blob: ae16ce2649922137070943e48cbc0d43912ffa39 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass17f9d5c2016-03-11 22:07:28 -07002/*
3 * Copyright (c) 2016 Google, Inc
4 *
Simon Glass17f9d5c2016-03-11 22:07:28 -07005 * Based on code from coreboot src/soc/intel/broadwell/me_status.c
6 */
7
8#include <common.h>
9#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass17f9d5c2016-03-11 22:07:28 -070011#include <asm/arch/me.h>
Simon Glassdbd79542020-05-10 11:40:11 -060012#include <linux/delay.h>
Simon Glass17f9d5c2016-03-11 22:07:28 -070013
14static inline void me_read_dword_ptr(struct udevice *dev, void *ptr, int offset)
15{
16 u32 dword;
17
18 dm_pci_read_config32(dev, offset, &dword);
19 memcpy(ptr, &dword, sizeof(dword));
20}
21
22int intel_me_hsio_version(struct udevice *dev, uint16_t *versionp,
23 uint16_t *checksump)
24{
25 int count;
26 u32 hsiover;
27 struct me_hfs hfs;
28
29 /* Query for HSIO version, overloads H_GS and HFS */
30 dm_pci_write_config32(dev, PCI_ME_H_GS,
31 ME_HSIO_MESSAGE | ME_HSIO_CMD_GETHSIOVER);
32
33 /* Must wait for ME acknowledgement */
34 for (count = ME_RETRY; count > 0; --count) {
35 me_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
36 if (hfs.bios_msg_ack)
37 break;
38 udelay(ME_DELAY);
39 }
40 if (!count) {
41 debug("ERROR: ME failed to respond\n");
42 return -ETIMEDOUT;
43 }
44
45 /* HSIO version should be in HFS_5 */
46 dm_pci_read_config32(dev, PCI_ME_HFS5, &hsiover);
47 *versionp = hsiover >> 16;
48 *checksump = hsiover & 0xffff;
49
50 debug("ME: HSIO Version : %d (CRC 0x%04x)\n",
51 *versionp, *checksump);
52
53 /* Reset registers to normal behavior */
54 dm_pci_write_config32(dev, PCI_ME_H_GS,
55 ME_HSIO_MESSAGE | ME_HSIO_CMD_GETHSIOVER);
56
57 return 0;
58}