blob: 3399d822e5b65bbd4822f7a25d83c610f8cd4e4e [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
Simon Glass17f9d5c2016-03-11 22:07:28 -07008#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass17f9d5c2016-03-11 22:07:28 -070010#include <asm/arch/me.h>
Simon Glassdbd79542020-05-10 11:40:11 -060011#include <linux/delay.h>
Simon Glass17f9d5c2016-03-11 22:07:28 -070012
13static inline void me_read_dword_ptr(struct udevice *dev, void *ptr, int offset)
14{
15 u32 dword;
16
17 dm_pci_read_config32(dev, offset, &dword);
18 memcpy(ptr, &dword, sizeof(dword));
19}
20
21int intel_me_hsio_version(struct udevice *dev, uint16_t *versionp,
22 uint16_t *checksump)
23{
24 int count;
25 u32 hsiover;
26 struct me_hfs hfs;
27
28 /* Query for HSIO version, overloads H_GS and HFS */
29 dm_pci_write_config32(dev, PCI_ME_H_GS,
30 ME_HSIO_MESSAGE | ME_HSIO_CMD_GETHSIOVER);
31
32 /* Must wait for ME acknowledgement */
33 for (count = ME_RETRY; count > 0; --count) {
34 me_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
35 if (hfs.bios_msg_ack)
36 break;
37 udelay(ME_DELAY);
38 }
39 if (!count) {
40 debug("ERROR: ME failed to respond\n");
41 return -ETIMEDOUT;
42 }
43
44 /* HSIO version should be in HFS_5 */
45 dm_pci_read_config32(dev, PCI_ME_HFS5, &hsiover);
46 *versionp = hsiover >> 16;
47 *checksump = hsiover & 0xffff;
48
49 debug("ME: HSIO Version : %d (CRC 0x%04x)\n",
50 *versionp, *checksump);
51
52 /* Reset registers to normal behavior */
53 dm_pci_write_config32(dev, PCI_ME_H_GS,
54 ME_HSIO_MESSAGE | ME_HSIO_CMD_GETHSIOVER);
55
56 return 0;
57}