blob: 0c2418ad278f74e17d4cb1481bbf5a114a2561cf [file] [log] [blame]
Mario Scheithauer66038c82018-09-25 17:26:32 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2018 Siemens AG
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <bootstate.h>
17#include <console/console.h>
18#include <device/pci_def.h>
19#include <device/pci_ids.h>
20#include <device/pci_ops.h>
21#include <hwilib.h>
22#include <intelblocks/lpc_lib.h>
23#include <timer.h>
24#include <timestamp.h>
25#include <baseboard/variants.h>
26
27void variant_mainboard_final(void)
28{
29 struct device *dev;
30 uint16_t cmd = 0;
31
32 /* Set Master Enable for on-board PCI device. */
33 dev = dev_find_device(PCI_VENDOR_ID_SIEMENS, 0x403e, 0);
34 if (dev) {
35 cmd = pci_read_config16(dev, PCI_COMMAND);
36 cmd |= PCI_COMMAND_MASTER;
37 pci_write_config16(dev, PCI_COMMAND, cmd);
38 }
39}
40
41static void wait_for_legacy_dev(void *unused)
42{
43 uint32_t legacy_delay, us_since_boot;
44 struct stopwatch sw;
45
46 /* Open main hwinfo block. */
47 if (hwilib_find_blocks("hwinfo.hex") != CB_SUCCESS)
48 return;
49
50 /* Get legacy delay parameter from hwinfo. */
51 if (hwilib_get_field(LegacyDelay, (uint8_t *) &legacy_delay,
52 sizeof(legacy_delay)) != sizeof(legacy_delay))
53 return;
54
55 us_since_boot = get_us_since_boot();
56 /* No need to wait if the time since boot is already long enough.*/
57 if (us_since_boot > legacy_delay)
58 return;
59 stopwatch_init_msecs_expire(&sw, (legacy_delay - us_since_boot) / 1000);
60 printk(BIOS_NOTICE, "Wait remaining %d of %d us for legacy devices...",
61 legacy_delay - us_since_boot, legacy_delay);
62 stopwatch_wait_until_expired(&sw);
63 printk(BIOS_NOTICE, "done!\n");
64}
65
66BOOT_STATE_INIT_ENTRY(BS_DEV_ENUMERATE, BS_ON_ENTRY, wait_for_legacy_dev, NULL);