blob: 99c5842bb3dc3c0b99b5011b34a69e9cdc422e85 [file] [log] [blame]
Sergii Dmytrukef7dd5d2021-10-22 01:02:32 +03001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <arch/io.h>
4#include <console/console.h>
5#include <device/pnp.h>
6#include <delay.h>
7#include <timer.h>
8
9#include "ipmi_if.h"
10#include "chip.h"
11
12enum cb_err ipmi_premem_init(const u16 port, const u16 device)
13{
14 const struct drivers_ipmi_config *conf = NULL;
15 const struct device *dev;
16
17 /* Find IPMI PNP device from devicetree in romstage */
18 dev = dev_find_slot_pnp(port, device);
19
20 if (!dev) {
21 printk(BIOS_ERR, "IPMI: Cannot find PNP device port: %x, device %x\n",
22 port, device);
23 return CB_ERR;
24 }
25 if (!dev->enabled) {
26 printk(BIOS_ERR, "IPMI: device is not enabled\n");
27 return CB_ERR;
28 }
29 printk(BIOS_DEBUG, "IPMI: romstage PNP KCS 0x%x\n", dev->path.pnp.port);
30 if (dev->chip_info)
31 conf = dev->chip_info;
32
33 if (conf && conf->wait_for_bmc && conf->bmc_boot_timeout) {
34 struct stopwatch sw;
35 stopwatch_init_msecs_expire(&sw, conf->bmc_boot_timeout * 1000);
36 printk(BIOS_DEBUG, "IPMI: Waiting for BMC...\n");
37
38 while (!stopwatch_expired(&sw)) {
39 if (inb(dev->path.pnp.port) != 0xff)
40 break;
41 mdelay(100);
42 }
43 if (stopwatch_expired(&sw)) {
44 printk(BIOS_INFO, "IPMI: Waiting for BMC timed out\n");
45 return CB_ERR;
46 }
47 }
48
49 if (ipmi_process_self_test_result(dev))
50 return CB_ERR;
51
52 return CB_SUCCESS;
53}