root / hw / acpi.c @ beb811bd
History | View | Annotate | Download (12.8 kB)
1 | 6515b203 | bellard | /*
|
---|---|---|---|
2 | 6515b203 | bellard | * ACPI implementation
|
3 | 6515b203 | bellard | *
|
4 | 6515b203 | bellard | * Copyright (c) 2006 Fabrice Bellard
|
5 | 6515b203 | bellard | *
|
6 | 6515b203 | bellard | * This library is free software; you can redistribute it and/or
|
7 | 6515b203 | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | 6515b203 | bellard | * License version 2 as published by the Free Software Foundation.
|
9 | 6515b203 | bellard | *
|
10 | 6515b203 | bellard | * This library is distributed in the hope that it will be useful,
|
11 | 6515b203 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | 6515b203 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | 6515b203 | bellard | * Lesser General Public License for more details.
|
14 | 6515b203 | bellard | *
|
15 | 6515b203 | bellard | * You should have received a copy of the GNU Lesser General Public
|
16 | 6515b203 | bellard | * License along with this library; if not, write to the Free Software
|
17 | 6515b203 | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 | 6515b203 | bellard | */
|
19 | 6515b203 | bellard | #include "vl.h" |
20 | 6515b203 | bellard | |
21 | 6515b203 | bellard | //#define DEBUG
|
22 | 6515b203 | bellard | |
23 | 6515b203 | bellard | /* i82731AB (PIIX4) compatible power management function */
|
24 | 6515b203 | bellard | #define PM_FREQ 3579545 |
25 | 6515b203 | bellard | |
26 | 6515b203 | bellard | #define ACPI_DBG_IO_ADDR 0xb044 |
27 | 3fffc223 | ths | #define SMB_IO_BASE 0xb100 |
28 | 6515b203 | bellard | |
29 | 6515b203 | bellard | typedef struct PIIX4PMState { |
30 | 6515b203 | bellard | PCIDevice dev; |
31 | 6515b203 | bellard | uint16_t pmsts; |
32 | 6515b203 | bellard | uint16_t pmen; |
33 | 6515b203 | bellard | uint16_t pmcntrl; |
34 | ab1e34ad | bellard | uint8_t apmc; |
35 | ab1e34ad | bellard | uint8_t apms; |
36 | 6515b203 | bellard | QEMUTimer *tmr_timer; |
37 | 6515b203 | bellard | int64_t tmr_overflow_time; |
38 | 3fffc223 | ths | SMBusDevice *smb_dev[128];
|
39 | 3fffc223 | ths | uint8_t smb_stat; |
40 | 3fffc223 | ths | uint8_t smb_ctl; |
41 | 3fffc223 | ths | uint8_t smb_cmd; |
42 | 3fffc223 | ths | uint8_t smb_addr; |
43 | 3fffc223 | ths | uint8_t smb_data0; |
44 | 3fffc223 | ths | uint8_t smb_data1; |
45 | 3fffc223 | ths | uint8_t smb_data[32];
|
46 | 3fffc223 | ths | uint8_t smb_index; |
47 | 6515b203 | bellard | } PIIX4PMState; |
48 | 6515b203 | bellard | |
49 | 6515b203 | bellard | #define RTC_EN (1 << 10) |
50 | 6515b203 | bellard | #define PWRBTN_EN (1 << 8) |
51 | 6515b203 | bellard | #define GBL_EN (1 << 5) |
52 | 6515b203 | bellard | #define TMROF_EN (1 << 0) |
53 | 6515b203 | bellard | |
54 | 6515b203 | bellard | #define SCI_EN (1 << 0) |
55 | 6515b203 | bellard | |
56 | 6515b203 | bellard | #define SUS_EN (1 << 13) |
57 | 6515b203 | bellard | |
58 | 3fffc223 | ths | #define SMBHSTSTS 0x00 |
59 | 3fffc223 | ths | #define SMBHSTCNT 0x02 |
60 | 3fffc223 | ths | #define SMBHSTCMD 0x03 |
61 | 3fffc223 | ths | #define SMBHSTADD 0x04 |
62 | 3fffc223 | ths | #define SMBHSTDAT0 0x05 |
63 | 3fffc223 | ths | #define SMBHSTDAT1 0x06 |
64 | 3fffc223 | ths | #define SMBBLKDAT 0x07 |
65 | 3fffc223 | ths | |
66 | 3fffc223 | ths | /* Note: only used for piix4_smbus_register_device */
|
67 | 3fffc223 | ths | static PIIX4PMState *piix4_pm_state;
|
68 | 3fffc223 | ths | |
69 | 6515b203 | bellard | static uint32_t get_pmtmr(PIIX4PMState *s)
|
70 | 6515b203 | bellard | { |
71 | 6515b203 | bellard | uint32_t d; |
72 | 6515b203 | bellard | d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, ticks_per_sec); |
73 | 6515b203 | bellard | return d & 0xffffff; |
74 | 6515b203 | bellard | } |
75 | 6515b203 | bellard | |
76 | 6515b203 | bellard | static int get_pmsts(PIIX4PMState *s) |
77 | 6515b203 | bellard | { |
78 | 6515b203 | bellard | int64_t d; |
79 | 6515b203 | bellard | int pmsts;
|
80 | 6515b203 | bellard | pmsts = s->pmsts; |
81 | 6515b203 | bellard | d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, ticks_per_sec); |
82 | 6515b203 | bellard | if (d >= s->tmr_overflow_time)
|
83 | 6515b203 | bellard | s->pmsts |= TMROF_EN; |
84 | 6515b203 | bellard | return pmsts;
|
85 | 6515b203 | bellard | } |
86 | 6515b203 | bellard | |
87 | 6515b203 | bellard | static void pm_update_sci(PIIX4PMState *s) |
88 | 6515b203 | bellard | { |
89 | 6515b203 | bellard | int sci_level, pmsts;
|
90 | 6515b203 | bellard | int64_t expire_time; |
91 | 6515b203 | bellard | |
92 | 6515b203 | bellard | pmsts = get_pmsts(s); |
93 | 6515b203 | bellard | sci_level = (((pmsts & s->pmen) & |
94 | 6515b203 | bellard | (RTC_EN | PWRBTN_EN | GBL_EN | TMROF_EN)) != 0);
|
95 | 6515b203 | bellard | pci_set_irq(&s->dev, 0, sci_level);
|
96 | 6515b203 | bellard | /* schedule a timer interruption if needed */
|
97 | 6515b203 | bellard | if ((s->pmen & TMROF_EN) && !(pmsts & TMROF_EN)) {
|
98 | 6515b203 | bellard | expire_time = muldiv64(s->tmr_overflow_time, ticks_per_sec, PM_FREQ); |
99 | 6515b203 | bellard | qemu_mod_timer(s->tmr_timer, expire_time); |
100 | 6515b203 | bellard | } else {
|
101 | 6515b203 | bellard | qemu_del_timer(s->tmr_timer); |
102 | 6515b203 | bellard | } |
103 | 6515b203 | bellard | } |
104 | 6515b203 | bellard | |
105 | 6515b203 | bellard | static void pm_tmr_timer(void *opaque) |
106 | 6515b203 | bellard | { |
107 | 6515b203 | bellard | PIIX4PMState *s = opaque; |
108 | 6515b203 | bellard | pm_update_sci(s); |
109 | 6515b203 | bellard | } |
110 | 6515b203 | bellard | |
111 | 6515b203 | bellard | static void pm_ioport_writew(void *opaque, uint32_t addr, uint32_t val) |
112 | 6515b203 | bellard | { |
113 | 6515b203 | bellard | PIIX4PMState *s = opaque; |
114 | 6515b203 | bellard | addr &= 0x3f;
|
115 | 6515b203 | bellard | switch(addr) {
|
116 | 6515b203 | bellard | case 0x00: |
117 | 6515b203 | bellard | { |
118 | 6515b203 | bellard | int64_t d; |
119 | 6515b203 | bellard | int pmsts;
|
120 | 6515b203 | bellard | pmsts = get_pmsts(s); |
121 | 6515b203 | bellard | if (pmsts & val & TMROF_EN) {
|
122 | 6515b203 | bellard | /* if TMRSTS is reset, then compute the new overflow time */
|
123 | 6515b203 | bellard | d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, ticks_per_sec); |
124 | 6515b203 | bellard | s->tmr_overflow_time = (d + 0x800000LL) & ~0x7fffffLL; |
125 | 6515b203 | bellard | } |
126 | 6515b203 | bellard | s->pmsts &= ~val; |
127 | 6515b203 | bellard | pm_update_sci(s); |
128 | 6515b203 | bellard | } |
129 | 6515b203 | bellard | break;
|
130 | 6515b203 | bellard | case 0x02: |
131 | 6515b203 | bellard | s->pmen = val; |
132 | 6515b203 | bellard | pm_update_sci(s); |
133 | 6515b203 | bellard | break;
|
134 | 6515b203 | bellard | case 0x04: |
135 | 6515b203 | bellard | { |
136 | 6515b203 | bellard | int sus_typ;
|
137 | 6515b203 | bellard | s->pmcntrl = val & ~(SUS_EN); |
138 | 6515b203 | bellard | if (val & SUS_EN) {
|
139 | 6515b203 | bellard | /* change suspend type */
|
140 | 6515b203 | bellard | sus_typ = (val >> 10) & 3; |
141 | 6515b203 | bellard | switch(sus_typ) {
|
142 | 6515b203 | bellard | case 0: /* soft power off */ |
143 | 6515b203 | bellard | qemu_system_shutdown_request(); |
144 | 6515b203 | bellard | break;
|
145 | 6515b203 | bellard | default:
|
146 | 6515b203 | bellard | break;
|
147 | 6515b203 | bellard | } |
148 | 6515b203 | bellard | } |
149 | 6515b203 | bellard | } |
150 | 6515b203 | bellard | break;
|
151 | 6515b203 | bellard | default:
|
152 | 6515b203 | bellard | break;
|
153 | 6515b203 | bellard | } |
154 | 6515b203 | bellard | #ifdef DEBUG
|
155 | 6515b203 | bellard | printf("PM writew port=0x%04x val=0x%04x\n", addr, val);
|
156 | 6515b203 | bellard | #endif
|
157 | 6515b203 | bellard | } |
158 | 6515b203 | bellard | |
159 | 6515b203 | bellard | static uint32_t pm_ioport_readw(void *opaque, uint32_t addr) |
160 | 6515b203 | bellard | { |
161 | 6515b203 | bellard | PIIX4PMState *s = opaque; |
162 | 6515b203 | bellard | uint32_t val; |
163 | 6515b203 | bellard | |
164 | 6515b203 | bellard | addr &= 0x3f;
|
165 | 6515b203 | bellard | switch(addr) {
|
166 | 6515b203 | bellard | case 0x00: |
167 | 6515b203 | bellard | val = get_pmsts(s); |
168 | 6515b203 | bellard | break;
|
169 | 6515b203 | bellard | case 0x02: |
170 | 6515b203 | bellard | val = s->pmen; |
171 | 6515b203 | bellard | break;
|
172 | 6515b203 | bellard | case 0x04: |
173 | 6515b203 | bellard | val = s->pmcntrl; |
174 | 6515b203 | bellard | break;
|
175 | 6515b203 | bellard | default:
|
176 | 6515b203 | bellard | val = 0;
|
177 | 6515b203 | bellard | break;
|
178 | 6515b203 | bellard | } |
179 | 6515b203 | bellard | #ifdef DEBUG
|
180 | 6515b203 | bellard | printf("PM readw port=0x%04x val=0x%04x\n", addr, val);
|
181 | 6515b203 | bellard | #endif
|
182 | 6515b203 | bellard | return val;
|
183 | 6515b203 | bellard | } |
184 | 6515b203 | bellard | |
185 | 6515b203 | bellard | static void pm_ioport_writel(void *opaque, uint32_t addr, uint32_t val) |
186 | 6515b203 | bellard | { |
187 | 6515b203 | bellard | // PIIX4PMState *s = opaque;
|
188 | 6515b203 | bellard | addr &= 0x3f;
|
189 | 6515b203 | bellard | #ifdef DEBUG
|
190 | 6515b203 | bellard | printf("PM writel port=0x%04x val=0x%08x\n", addr, val);
|
191 | 6515b203 | bellard | #endif
|
192 | 6515b203 | bellard | } |
193 | 6515b203 | bellard | |
194 | 6515b203 | bellard | static uint32_t pm_ioport_readl(void *opaque, uint32_t addr) |
195 | 6515b203 | bellard | { |
196 | 6515b203 | bellard | PIIX4PMState *s = opaque; |
197 | 6515b203 | bellard | uint32_t val; |
198 | 6515b203 | bellard | |
199 | 6515b203 | bellard | addr &= 0x3f;
|
200 | 6515b203 | bellard | switch(addr) {
|
201 | 6515b203 | bellard | case 0x08: |
202 | 6515b203 | bellard | val = get_pmtmr(s); |
203 | 6515b203 | bellard | break;
|
204 | 6515b203 | bellard | default:
|
205 | 6515b203 | bellard | val = 0;
|
206 | 6515b203 | bellard | break;
|
207 | 6515b203 | bellard | } |
208 | 6515b203 | bellard | #ifdef DEBUG
|
209 | 6515b203 | bellard | printf("PM readl port=0x%04x val=0x%08x\n", addr, val);
|
210 | 6515b203 | bellard | #endif
|
211 | 6515b203 | bellard | return val;
|
212 | 6515b203 | bellard | } |
213 | 6515b203 | bellard | |
214 | ab1e34ad | bellard | static void pm_smi_writeb(void *opaque, uint32_t addr, uint32_t val) |
215 | 6515b203 | bellard | { |
216 | 6515b203 | bellard | PIIX4PMState *s = opaque; |
217 | ab1e34ad | bellard | addr &= 1;
|
218 | 6515b203 | bellard | #ifdef DEBUG
|
219 | ab1e34ad | bellard | printf("pm_smi_writeb addr=0x%x val=0x%02x\n", addr, val);
|
220 | 6515b203 | bellard | #endif
|
221 | ab1e34ad | bellard | if (addr == 0) { |
222 | ab1e34ad | bellard | s->apmc = val; |
223 | 47d02f6d | bellard | if (s->dev.config[0x5b] & (1 << 1)) { |
224 | 47d02f6d | bellard | cpu_interrupt(first_cpu, CPU_INTERRUPT_SMI); |
225 | ab1e34ad | bellard | } |
226 | ab1e34ad | bellard | } else {
|
227 | ab1e34ad | bellard | s->apms = val; |
228 | 6515b203 | bellard | } |
229 | 6515b203 | bellard | } |
230 | 6515b203 | bellard | |
231 | ab1e34ad | bellard | static uint32_t pm_smi_readb(void *opaque, uint32_t addr) |
232 | ab1e34ad | bellard | { |
233 | ab1e34ad | bellard | PIIX4PMState *s = opaque; |
234 | ab1e34ad | bellard | uint32_t val; |
235 | ab1e34ad | bellard | |
236 | ab1e34ad | bellard | addr &= 1;
|
237 | ab1e34ad | bellard | if (addr == 0) { |
238 | ab1e34ad | bellard | val = s->apmc; |
239 | ab1e34ad | bellard | } else {
|
240 | ab1e34ad | bellard | val = s->apms; |
241 | ab1e34ad | bellard | } |
242 | ab1e34ad | bellard | #ifdef DEBUG
|
243 | ab1e34ad | bellard | printf("pm_smi_readb addr=0x%x val=0x%02x\n", addr, val);
|
244 | ab1e34ad | bellard | #endif
|
245 | ab1e34ad | bellard | return val;
|
246 | ab1e34ad | bellard | } |
247 | ab1e34ad | bellard | |
248 | 6515b203 | bellard | static void acpi_dbg_writel(void *opaque, uint32_t addr, uint32_t val) |
249 | 6515b203 | bellard | { |
250 | 6515b203 | bellard | #if defined(DEBUG)
|
251 | 6515b203 | bellard | printf("ACPI: DBG: 0x%08x\n", val);
|
252 | 6515b203 | bellard | #endif
|
253 | 6515b203 | bellard | } |
254 | 6515b203 | bellard | |
255 | 3fffc223 | ths | static void smb_transaction(PIIX4PMState *s) |
256 | 3fffc223 | ths | { |
257 | 3fffc223 | ths | uint8_t prot = (s->smb_ctl >> 2) & 0x07; |
258 | 3fffc223 | ths | uint8_t read = s->smb_addr & 0x01;
|
259 | 3fffc223 | ths | uint8_t cmd = s->smb_cmd; |
260 | 3fffc223 | ths | uint8_t addr = s->smb_addr >> 1;
|
261 | 3fffc223 | ths | SMBusDevice *dev = s->smb_dev[addr]; |
262 | 3fffc223 | ths | |
263 | 3fffc223 | ths | #ifdef DEBUG
|
264 | 3fffc223 | ths | printf("SMBus trans addr=0x%02x prot=0x%02x\n", addr, prot);
|
265 | 3fffc223 | ths | #endif
|
266 | 3fffc223 | ths | if (!dev) goto error; |
267 | 3fffc223 | ths | |
268 | 3fffc223 | ths | switch(prot) {
|
269 | 3fffc223 | ths | case 0x0: |
270 | 3fffc223 | ths | if (!dev->quick_cmd) goto error; |
271 | 3fffc223 | ths | (*dev->quick_cmd)(dev, read); |
272 | 3fffc223 | ths | break;
|
273 | 3fffc223 | ths | case 0x1: |
274 | 3fffc223 | ths | if (read) {
|
275 | 3fffc223 | ths | if (!dev->receive_byte) goto error; |
276 | 3fffc223 | ths | s->smb_data0 = (*dev->receive_byte)(dev); |
277 | 3fffc223 | ths | } |
278 | 3fffc223 | ths | else {
|
279 | 3fffc223 | ths | if (!dev->send_byte) goto error; |
280 | 3fffc223 | ths | (*dev->send_byte)(dev, cmd); |
281 | 3fffc223 | ths | } |
282 | 3fffc223 | ths | break;
|
283 | 3fffc223 | ths | case 0x2: |
284 | 3fffc223 | ths | if (read) {
|
285 | 3fffc223 | ths | if (!dev->read_byte) goto error; |
286 | 3fffc223 | ths | s->smb_data0 = (*dev->read_byte)(dev, cmd); |
287 | 3fffc223 | ths | } |
288 | 3fffc223 | ths | else {
|
289 | 3fffc223 | ths | if (!dev->write_byte) goto error; |
290 | 3fffc223 | ths | (*dev->write_byte)(dev, cmd, s->smb_data0); |
291 | 3fffc223 | ths | } |
292 | 3fffc223 | ths | break;
|
293 | 3fffc223 | ths | case 0x3: |
294 | 3fffc223 | ths | if (read) {
|
295 | 3fffc223 | ths | uint16_t val; |
296 | 3fffc223 | ths | if (!dev->read_word) goto error; |
297 | 3fffc223 | ths | val = (*dev->read_word)(dev, cmd); |
298 | 3fffc223 | ths | s->smb_data0 = val; |
299 | 3fffc223 | ths | s->smb_data1 = val >> 8;
|
300 | 3fffc223 | ths | } |
301 | 3fffc223 | ths | else {
|
302 | 3fffc223 | ths | if (!dev->write_word) goto error; |
303 | 3fffc223 | ths | (*dev->write_word)(dev, cmd, (s->smb_data1 << 8) | s->smb_data0);
|
304 | 3fffc223 | ths | } |
305 | 3fffc223 | ths | break;
|
306 | 3fffc223 | ths | case 0x5: |
307 | 3fffc223 | ths | if (read) {
|
308 | 3fffc223 | ths | if (!dev->read_block) goto error; |
309 | 3fffc223 | ths | s->smb_data0 = (*dev->read_block)(dev, cmd, s->smb_data); |
310 | 3fffc223 | ths | } |
311 | 3fffc223 | ths | else {
|
312 | 3fffc223 | ths | if (!dev->write_block) goto error; |
313 | 3fffc223 | ths | (*dev->write_block)(dev, cmd, s->smb_data0, s->smb_data); |
314 | 3fffc223 | ths | } |
315 | 3fffc223 | ths | break;
|
316 | 3fffc223 | ths | default:
|
317 | 3fffc223 | ths | goto error;
|
318 | 3fffc223 | ths | } |
319 | 3fffc223 | ths | return;
|
320 | 3fffc223 | ths | |
321 | 3fffc223 | ths | error:
|
322 | 3fffc223 | ths | s->smb_stat |= 0x04;
|
323 | 3fffc223 | ths | } |
324 | 3fffc223 | ths | |
325 | 3fffc223 | ths | static void smb_ioport_writeb(void *opaque, uint32_t addr, uint32_t val) |
326 | 3fffc223 | ths | { |
327 | 3fffc223 | ths | PIIX4PMState *s = opaque; |
328 | 3fffc223 | ths | addr &= 0x3f;
|
329 | 3fffc223 | ths | #ifdef DEBUG
|
330 | 3fffc223 | ths | printf("SMB writeb port=0x%04x val=0x%02x\n", addr, val);
|
331 | 3fffc223 | ths | #endif
|
332 | 3fffc223 | ths | switch(addr) {
|
333 | 3fffc223 | ths | case SMBHSTSTS:
|
334 | 3fffc223 | ths | s->smb_stat = 0;
|
335 | 3fffc223 | ths | s->smb_index = 0;
|
336 | 3fffc223 | ths | break;
|
337 | 3fffc223 | ths | case SMBHSTCNT:
|
338 | 3fffc223 | ths | s->smb_ctl = val; |
339 | 3fffc223 | ths | if (val & 0x40) |
340 | 3fffc223 | ths | smb_transaction(s); |
341 | 3fffc223 | ths | break;
|
342 | 3fffc223 | ths | case SMBHSTCMD:
|
343 | 3fffc223 | ths | s->smb_cmd = val; |
344 | 3fffc223 | ths | break;
|
345 | 3fffc223 | ths | case SMBHSTADD:
|
346 | 3fffc223 | ths | s->smb_addr = val; |
347 | 3fffc223 | ths | break;
|
348 | 3fffc223 | ths | case SMBHSTDAT0:
|
349 | 3fffc223 | ths | s->smb_data0 = val; |
350 | 3fffc223 | ths | break;
|
351 | 3fffc223 | ths | case SMBHSTDAT1:
|
352 | 3fffc223 | ths | s->smb_data1 = val; |
353 | 3fffc223 | ths | break;
|
354 | 3fffc223 | ths | case SMBBLKDAT:
|
355 | 3fffc223 | ths | s->smb_data[s->smb_index++] = val; |
356 | 3fffc223 | ths | if (s->smb_index > 31) |
357 | 3fffc223 | ths | s->smb_index = 0;
|
358 | 3fffc223 | ths | break;
|
359 | 3fffc223 | ths | default:
|
360 | 3fffc223 | ths | break;
|
361 | 3fffc223 | ths | } |
362 | 3fffc223 | ths | } |
363 | 3fffc223 | ths | |
364 | 3fffc223 | ths | static uint32_t smb_ioport_readb(void *opaque, uint32_t addr) |
365 | 3fffc223 | ths | { |
366 | 3fffc223 | ths | PIIX4PMState *s = opaque; |
367 | 3fffc223 | ths | uint32_t val; |
368 | 3fffc223 | ths | |
369 | 3fffc223 | ths | addr &= 0x3f;
|
370 | 3fffc223 | ths | switch(addr) {
|
371 | 3fffc223 | ths | case SMBHSTSTS:
|
372 | 3fffc223 | ths | val = s->smb_stat; |
373 | 3fffc223 | ths | break;
|
374 | 3fffc223 | ths | case SMBHSTCNT:
|
375 | 3fffc223 | ths | s->smb_index = 0;
|
376 | 3fffc223 | ths | val = s->smb_ctl & 0x1f;
|
377 | 3fffc223 | ths | break;
|
378 | 3fffc223 | ths | case SMBHSTCMD:
|
379 | 3fffc223 | ths | val = s->smb_cmd; |
380 | 3fffc223 | ths | break;
|
381 | 3fffc223 | ths | case SMBHSTADD:
|
382 | 3fffc223 | ths | val = s->smb_addr; |
383 | 3fffc223 | ths | break;
|
384 | 3fffc223 | ths | case SMBHSTDAT0:
|
385 | 3fffc223 | ths | val = s->smb_data0; |
386 | 3fffc223 | ths | break;
|
387 | 3fffc223 | ths | case SMBHSTDAT1:
|
388 | 3fffc223 | ths | val = s->smb_data1; |
389 | 3fffc223 | ths | break;
|
390 | 3fffc223 | ths | case SMBBLKDAT:
|
391 | 3fffc223 | ths | val = s->smb_data[s->smb_index++]; |
392 | 3fffc223 | ths | if (s->smb_index > 31) |
393 | 3fffc223 | ths | s->smb_index = 0;
|
394 | 3fffc223 | ths | break;
|
395 | 3fffc223 | ths | default:
|
396 | 3fffc223 | ths | val = 0;
|
397 | 3fffc223 | ths | break;
|
398 | 3fffc223 | ths | } |
399 | 3fffc223 | ths | #ifdef DEBUG
|
400 | 3fffc223 | ths | printf("SMB readb port=0x%04x val=0x%02x\n", addr, val);
|
401 | 3fffc223 | ths | #endif
|
402 | 3fffc223 | ths | return val;
|
403 | 3fffc223 | ths | } |
404 | 3fffc223 | ths | |
405 | ab1e34ad | bellard | static void pm_io_space_update(PIIX4PMState *s) |
406 | ab1e34ad | bellard | { |
407 | ab1e34ad | bellard | uint32_t pm_io_base; |
408 | ab1e34ad | bellard | |
409 | ab1e34ad | bellard | if (s->dev.config[0x80] & 1) { |
410 | ab1e34ad | bellard | pm_io_base = le32_to_cpu(*(uint32_t *)(s->dev.config + 0x40));
|
411 | ab1e34ad | bellard | pm_io_base &= 0xfffe;
|
412 | ab1e34ad | bellard | |
413 | ab1e34ad | bellard | /* XXX: need to improve memory and ioport allocation */
|
414 | ab1e34ad | bellard | #if defined(DEBUG)
|
415 | ab1e34ad | bellard | printf("PM: mapping to 0x%x\n", pm_io_base);
|
416 | ab1e34ad | bellard | #endif
|
417 | ab1e34ad | bellard | register_ioport_write(pm_io_base, 64, 2, pm_ioport_writew, s); |
418 | ab1e34ad | bellard | register_ioport_read(pm_io_base, 64, 2, pm_ioport_readw, s); |
419 | ab1e34ad | bellard | register_ioport_write(pm_io_base, 64, 4, pm_ioport_writel, s); |
420 | ab1e34ad | bellard | register_ioport_read(pm_io_base, 64, 4, pm_ioport_readl, s); |
421 | ab1e34ad | bellard | } |
422 | ab1e34ad | bellard | } |
423 | ab1e34ad | bellard | |
424 | ab1e34ad | bellard | static void pm_write_config(PCIDevice *d, |
425 | ab1e34ad | bellard | uint32_t address, uint32_t val, int len)
|
426 | ab1e34ad | bellard | { |
427 | ab1e34ad | bellard | pci_default_write_config(d, address, val, len); |
428 | ab1e34ad | bellard | if (address == 0x80) |
429 | ab1e34ad | bellard | pm_io_space_update((PIIX4PMState *)d); |
430 | ab1e34ad | bellard | } |
431 | ab1e34ad | bellard | |
432 | ab1e34ad | bellard | static void pm_save(QEMUFile* f,void *opaque) |
433 | ab1e34ad | bellard | { |
434 | ab1e34ad | bellard | PIIX4PMState *s = opaque; |
435 | ab1e34ad | bellard | |
436 | ab1e34ad | bellard | pci_device_save(&s->dev, f); |
437 | ab1e34ad | bellard | |
438 | ab1e34ad | bellard | qemu_put_be16s(f, &s->pmsts); |
439 | ab1e34ad | bellard | qemu_put_be16s(f, &s->pmen); |
440 | ab1e34ad | bellard | qemu_put_be16s(f, &s->pmcntrl); |
441 | ab1e34ad | bellard | qemu_put_8s(f, &s->apmc); |
442 | ab1e34ad | bellard | qemu_put_8s(f, &s->apms); |
443 | ab1e34ad | bellard | qemu_put_timer(f, s->tmr_timer); |
444 | ab1e34ad | bellard | qemu_put_be64s(f, &s->tmr_overflow_time); |
445 | ab1e34ad | bellard | } |
446 | ab1e34ad | bellard | |
447 | ab1e34ad | bellard | static int pm_load(QEMUFile* f,void* opaque,int version_id) |
448 | ab1e34ad | bellard | { |
449 | ab1e34ad | bellard | PIIX4PMState *s = opaque; |
450 | ab1e34ad | bellard | int ret;
|
451 | ab1e34ad | bellard | |
452 | ab1e34ad | bellard | if (version_id > 1) |
453 | ab1e34ad | bellard | return -EINVAL;
|
454 | ab1e34ad | bellard | |
455 | ab1e34ad | bellard | ret = pci_device_load(&s->dev, f); |
456 | ab1e34ad | bellard | if (ret < 0) |
457 | ab1e34ad | bellard | return ret;
|
458 | ab1e34ad | bellard | |
459 | ab1e34ad | bellard | qemu_get_be16s(f, &s->pmsts); |
460 | ab1e34ad | bellard | qemu_get_be16s(f, &s->pmen); |
461 | ab1e34ad | bellard | qemu_get_be16s(f, &s->pmcntrl); |
462 | ab1e34ad | bellard | qemu_get_8s(f, &s->apmc); |
463 | ab1e34ad | bellard | qemu_get_8s(f, &s->apms); |
464 | ab1e34ad | bellard | qemu_get_timer(f, s->tmr_timer); |
465 | ab1e34ad | bellard | qemu_get_be64s(f, &s->tmr_overflow_time); |
466 | ab1e34ad | bellard | |
467 | ab1e34ad | bellard | pm_io_space_update(s); |
468 | ab1e34ad | bellard | |
469 | ab1e34ad | bellard | return 0; |
470 | ab1e34ad | bellard | } |
471 | ab1e34ad | bellard | |
472 | 502a5395 | pbrook | void piix4_pm_init(PCIBus *bus, int devfn) |
473 | 6515b203 | bellard | { |
474 | 6515b203 | bellard | PIIX4PMState *s; |
475 | 6515b203 | bellard | uint8_t *pci_conf; |
476 | 3fffc223 | ths | uint32_t pm_io_base, smb_io_base; |
477 | 6515b203 | bellard | |
478 | 6515b203 | bellard | s = (PIIX4PMState *)pci_register_device(bus, |
479 | 6515b203 | bellard | "PM", sizeof(PIIX4PMState), |
480 | ab1e34ad | bellard | devfn, NULL, pm_write_config);
|
481 | 6515b203 | bellard | pci_conf = s->dev.config; |
482 | 6515b203 | bellard | pci_conf[0x00] = 0x86; |
483 | 6515b203 | bellard | pci_conf[0x01] = 0x80; |
484 | 6515b203 | bellard | pci_conf[0x02] = 0x13; |
485 | 7ef4da1c | bellard | pci_conf[0x03] = 0x71; |
486 | 6515b203 | bellard | pci_conf[0x08] = 0x00; // revision number |
487 | 6515b203 | bellard | pci_conf[0x09] = 0x00; |
488 | 6515b203 | bellard | pci_conf[0x0a] = 0x80; // other bridge device |
489 | 6515b203 | bellard | pci_conf[0x0b] = 0x06; // bridge device |
490 | 6515b203 | bellard | pci_conf[0x0e] = 0x00; // header_type |
491 | 6515b203 | bellard | pci_conf[0x3d] = 0x01; // interrupt pin 1 |
492 | 6515b203 | bellard | |
493 | ab1e34ad | bellard | pci_conf[0x40] = 0x01; /* PM io base read only bit */ |
494 | 6515b203 | bellard | |
495 | ab1e34ad | bellard | register_ioport_write(0xb2, 2, 1, pm_smi_writeb, s); |
496 | ab1e34ad | bellard | register_ioport_read(0xb2, 2, 1, pm_smi_readb, s); |
497 | ab1e34ad | bellard | |
498 | 6515b203 | bellard | register_ioport_write(ACPI_DBG_IO_ADDR, 4, 4, acpi_dbg_writel, s); |
499 | 6515b203 | bellard | |
500 | 1ce549ab | bellard | /* XXX: which specification is used ? The i82731AB has different
|
501 | 1ce549ab | bellard | mappings */
|
502 | 1ce549ab | bellard | pci_conf[0x5f] = (parallel_hds[0] != NULL ? 0x80 : 0) | 0x10; |
503 | 1ce549ab | bellard | pci_conf[0x63] = 0x60; |
504 | 1ce549ab | bellard | pci_conf[0x67] = (serial_hds[0] != NULL ? 0x08 : 0) | |
505 | 1ce549ab | bellard | (serial_hds[1] != NULL ? 0x90 : 0); |
506 | 1ce549ab | bellard | |
507 | 3fffc223 | ths | smb_io_base = SMB_IO_BASE; |
508 | 3fffc223 | ths | pci_conf[0x90] = smb_io_base | 1; |
509 | 3fffc223 | ths | pci_conf[0x91] = smb_io_base >> 8; |
510 | 3fffc223 | ths | pci_conf[0xd2] = 0x09; |
511 | 3fffc223 | ths | register_ioport_write(smb_io_base, 64, 1, smb_ioport_writeb, s); |
512 | 3fffc223 | ths | register_ioport_read(smb_io_base, 64, 1, smb_ioport_readb, s); |
513 | 3fffc223 | ths | |
514 | 6515b203 | bellard | s->tmr_timer = qemu_new_timer(vm_clock, pm_tmr_timer, s); |
515 | 6515b203 | bellard | |
516 | ab1e34ad | bellard | register_savevm("piix4_pm", 0, 1, pm_save, pm_load, s); |
517 | 3fffc223 | ths | piix4_pm_state = s; |
518 | 3fffc223 | ths | } |
519 | 3fffc223 | ths | |
520 | 3fffc223 | ths | void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr)
|
521 | 3fffc223 | ths | { |
522 | 3fffc223 | ths | piix4_pm_state->smb_dev[addr] = dev; |
523 | 6515b203 | bellard | } |