flashrom 

flashrom Svn Source Tree

Root/trunk/amd_imc.c

  • Property svn:eol-style set to native
1/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2013 Rudolf Marek <r.marek@assembler.cz>
5 * Copyright (C) 2013 Stefan Tauner
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#if defined(__i386__) || defined(__x86_64__)
23
24#include "flash.h"
25#include "programmer.h"
26#include "hwaccess.h"
27#include "spi.h"
28
29/* same as serverengines */
30static void enter_conf_mode_ec(uint16_t port)
31{
32OUTB(0x5a, port);
33}
34
35static void exit_conf_mode_ec(uint16_t port)
36{
37OUTB(0xa5, port);
38}
39
40static uint16_t get_sio_port(struct pci_dev *dev)
41{
42uint16_t ec_port;
43
44if (!dev) {
45return 0;
46}
47
48ec_port = pci_read_word(dev, 0xa4);
49
50/* EcPortActive? */
51if (!(ec_port & 0x1))
52return 0;
53
54ec_port &= ~0x1;
55
56return ec_port;
57}
58
59/* Wait for up to 10 ms for a response. */
60static int mbox_wait_ack(uint16_t mbox_port)
61{
62int i = 10;
63while (sio_read(mbox_port, 0x82) != 0xfa) {
64if (--i == 0) {
65msg_pwarn("IMC MBOX: Timeout!\n");
66return 1;
67}
68programmer_delay(1000);
69}
70return 0;
71}
72
73static uint16_t mbox_get_port(uint16_t sio_port)
74{
75uint16_t mbox_port;
76
77enter_conf_mode_ec(sio_port);
78
79/* Go to LDN 9, mailbox */
80sio_write(sio_port, 7, 9);
81
82/* MBOX inactive? */
83if ((sio_read(sio_port, 0x30) & 1) == 0) {
84exit_conf_mode_ec(sio_port);
85return 0;
86}
87
88mbox_port = sio_read(sio_port, 0x60) << 8;
89mbox_port |= sio_read(sio_port, 0x61);
90
91exit_conf_mode_ec(sio_port);
92return mbox_port;
93}
94
95/* Returns negative values when IMC is inactive, positive values on errors */
96static int imc_send_cmd(struct pci_dev *dev, uint8_t cmd)
97{
98uint16_t sio_port;
99uint16_t mbox_port;
100
101/* IntegratedEcPresent? */
102if (!(pci_read_byte(dev, 0x40) & (1 << 7)))
103return -1;
104
105sio_port = get_sio_port(dev);
106if (!sio_port)
107return -1;
108
109msg_pdbg2("IMC SIO is at 0x%x.\n", sio_port);
110mbox_port = mbox_get_port(sio_port);
111if (!mbox_port)
112return -1;
113msg_pdbg2("IMC MBOX is at 0x%x.\n", mbox_port);
114
115sio_write(mbox_port, 0x82, 0x0);
116sio_write(mbox_port, 0x83, cmd);
117sio_write(mbox_port, 0x84, 0x0);
118/* trigger transfer 0x96 with subcommand cmd */
119sio_write(mbox_port, 0x80, 0x96);
120
121return mbox_wait_ack(mbox_port);
122}
123
124static int imc_resume(void *data)
125{
126struct pci_dev *dev = data;
127int ret = imc_send_cmd(dev, 0xb5);
128
129if (ret != 0)
130msg_pinfo("Resuming IMC failed)\n");
131else
132msg_pdbg2("IMC resumed.\n");
133return ret;
134}
135
136int amd_imc_shutdown(struct pci_dev *dev)
137{
138/* Try to put IMC to sleep */
139int ret = imc_send_cmd(dev, 0xb4);
140
141/* No IMC activity detectable, assume we are fine */
142if (ret < 0) {
143msg_pdbg2("No IMC found.\n");
144return 0;
145}
146
147if (ret != 0) {
148msg_perr("Shutting down IMC failed.\n");
149return ret;
150}
151msg_pdbg2("Shutting down IMC successful.\n");
152
153if (register_shutdown(imc_resume, dev))
154return 1;
155
156return ret;
157}
158
159#endif

Archive Download this file

Revision: HEAD