xenfb: fix build breakage caused by console cleanup series
[qemu/opensuse.git] / hw / m48t59.c
blob9e8e692669f72c31b79222b36a1ff4b311ff19b4
1 /*
2 * QEMU M48T59 and M48T08 NVRAM emulation for PPC PREP and Sparc platforms
4 * Copyright (c) 2003-2005, 2007 Jocelyn Mayer
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
24 #include "hw.h"
25 #include "nvram.h"
26 #include "qemu-timer.h"
27 #include "sysemu.h"
28 #include "sysbus.h"
29 #include "isa.h"
30 #include "exec-memory.h"
32 //#define DEBUG_NVRAM
34 #if defined(DEBUG_NVRAM)
35 #define NVRAM_PRINTF(fmt, ...) do { printf(fmt , ## __VA_ARGS__); } while (0)
36 #else
37 #define NVRAM_PRINTF(fmt, ...) do { } while (0)
38 #endif
41 * The M48T02, M48T08 and M48T59 chips are very similar. The newer '59 has
42 * alarm and a watchdog timer and related control registers. In the
43 * PPC platform there is also a nvram lock function.
47 * Chipset docs:
48 * http://www.st.com/stonline/products/literature/ds/2410/m48t02.pdf
49 * http://www.st.com/stonline/products/literature/ds/2411/m48t08.pdf
50 * http://www.st.com/stonline/products/literature/od/7001/m48t59y.pdf
53 struct M48t59State {
54 /* Hardware parameters */
55 qemu_irq IRQ;
56 MemoryRegion iomem;
57 uint32_t io_base;
58 uint32_t size;
59 /* RTC management */
60 time_t time_offset;
61 time_t stop_time;
62 /* Alarm & watchdog */
63 struct tm alarm;
64 struct QEMUTimer *alrm_timer;
65 struct QEMUTimer *wd_timer;
66 /* NVRAM storage */
67 uint8_t *buffer;
68 /* Model parameters */
69 uint32_t model; /* 2 = m48t02, 8 = m48t08, 59 = m48t59 */
70 /* NVRAM storage */
71 uint16_t addr;
72 uint8_t lock;
75 typedef struct M48t59ISAState {
76 ISADevice busdev;
77 M48t59State state;
78 MemoryRegion io;
79 } M48t59ISAState;
81 typedef struct M48t59SysBusState {
82 SysBusDevice busdev;
83 M48t59State state;
84 MemoryRegion io;
85 } M48t59SysBusState;
87 /* Fake timer functions */
89 /* Alarm management */
90 static void alarm_cb (void *opaque)
92 struct tm tm;
93 uint64_t next_time;
94 M48t59State *NVRAM = opaque;
96 qemu_set_irq(NVRAM->IRQ, 1);
97 if ((NVRAM->buffer[0x1FF5] & 0x80) == 0 &&
98 (NVRAM->buffer[0x1FF4] & 0x80) == 0 &&
99 (NVRAM->buffer[0x1FF3] & 0x80) == 0 &&
100 (NVRAM->buffer[0x1FF2] & 0x80) == 0) {
101 /* Repeat once a month */
102 qemu_get_timedate(&tm, NVRAM->time_offset);
103 tm.tm_mon++;
104 if (tm.tm_mon == 13) {
105 tm.tm_mon = 1;
106 tm.tm_year++;
108 next_time = qemu_timedate_diff(&tm) - NVRAM->time_offset;
109 } else if ((NVRAM->buffer[0x1FF5] & 0x80) != 0 &&
110 (NVRAM->buffer[0x1FF4] & 0x80) == 0 &&
111 (NVRAM->buffer[0x1FF3] & 0x80) == 0 &&
112 (NVRAM->buffer[0x1FF2] & 0x80) == 0) {
113 /* Repeat once a day */
114 next_time = 24 * 60 * 60;
115 } else if ((NVRAM->buffer[0x1FF5] & 0x80) != 0 &&
116 (NVRAM->buffer[0x1FF4] & 0x80) != 0 &&
117 (NVRAM->buffer[0x1FF3] & 0x80) == 0 &&
118 (NVRAM->buffer[0x1FF2] & 0x80) == 0) {
119 /* Repeat once an hour */
120 next_time = 60 * 60;
121 } else if ((NVRAM->buffer[0x1FF5] & 0x80) != 0 &&
122 (NVRAM->buffer[0x1FF4] & 0x80) != 0 &&
123 (NVRAM->buffer[0x1FF3] & 0x80) != 0 &&
124 (NVRAM->buffer[0x1FF2] & 0x80) == 0) {
125 /* Repeat once a minute */
126 next_time = 60;
127 } else {
128 /* Repeat once a second */
129 next_time = 1;
131 qemu_mod_timer(NVRAM->alrm_timer, qemu_get_clock_ns(rtc_clock) +
132 next_time * 1000);
133 qemu_set_irq(NVRAM->IRQ, 0);
136 static void set_alarm(M48t59State *NVRAM)
138 int diff;
139 if (NVRAM->alrm_timer != NULL) {
140 qemu_del_timer(NVRAM->alrm_timer);
141 diff = qemu_timedate_diff(&NVRAM->alarm) - NVRAM->time_offset;
142 if (diff > 0)
143 qemu_mod_timer(NVRAM->alrm_timer, diff * 1000);
147 /* RTC management helpers */
148 static inline void get_time(M48t59State *NVRAM, struct tm *tm)
150 qemu_get_timedate(tm, NVRAM->time_offset);
153 static void set_time(M48t59State *NVRAM, struct tm *tm)
155 NVRAM->time_offset = qemu_timedate_diff(tm);
156 set_alarm(NVRAM);
159 /* Watchdog management */
160 static void watchdog_cb (void *opaque)
162 M48t59State *NVRAM = opaque;
164 NVRAM->buffer[0x1FF0] |= 0x80;
165 if (NVRAM->buffer[0x1FF7] & 0x80) {
166 NVRAM->buffer[0x1FF7] = 0x00;
167 NVRAM->buffer[0x1FFC] &= ~0x40;
168 /* May it be a hw CPU Reset instead ? */
169 qemu_system_reset_request();
170 } else {
171 qemu_set_irq(NVRAM->IRQ, 1);
172 qemu_set_irq(NVRAM->IRQ, 0);
176 static void set_up_watchdog(M48t59State *NVRAM, uint8_t value)
178 uint64_t interval; /* in 1/16 seconds */
180 NVRAM->buffer[0x1FF0] &= ~0x80;
181 if (NVRAM->wd_timer != NULL) {
182 qemu_del_timer(NVRAM->wd_timer);
183 if (value != 0) {
184 interval = (1 << (2 * (value & 0x03))) * ((value >> 2) & 0x1F);
185 qemu_mod_timer(NVRAM->wd_timer, ((uint64_t)time(NULL) * 1000) +
186 ((interval * 1000) >> 4));
191 /* Direct access to NVRAM */
192 void m48t59_write (void *opaque, uint32_t addr, uint32_t val)
194 M48t59State *NVRAM = opaque;
195 struct tm tm;
196 int tmp;
198 if (addr > 0x1FF8 && addr < 0x2000)
199 NVRAM_PRINTF("%s: 0x%08x => 0x%08x\n", __func__, addr, val);
201 /* check for NVRAM access */
202 if ((NVRAM->model == 2 && addr < 0x7f8) ||
203 (NVRAM->model == 8 && addr < 0x1ff8) ||
204 (NVRAM->model == 59 && addr < 0x1ff0)) {
205 goto do_write;
208 /* TOD access */
209 switch (addr) {
210 case 0x1FF0:
211 /* flags register : read-only */
212 break;
213 case 0x1FF1:
214 /* unused */
215 break;
216 case 0x1FF2:
217 /* alarm seconds */
218 tmp = from_bcd(val & 0x7F);
219 if (tmp >= 0 && tmp <= 59) {
220 NVRAM->alarm.tm_sec = tmp;
221 NVRAM->buffer[0x1FF2] = val;
222 set_alarm(NVRAM);
224 break;
225 case 0x1FF3:
226 /* alarm minutes */
227 tmp = from_bcd(val & 0x7F);
228 if (tmp >= 0 && tmp <= 59) {
229 NVRAM->alarm.tm_min = tmp;
230 NVRAM->buffer[0x1FF3] = val;
231 set_alarm(NVRAM);
233 break;
234 case 0x1FF4:
235 /* alarm hours */
236 tmp = from_bcd(val & 0x3F);
237 if (tmp >= 0 && tmp <= 23) {
238 NVRAM->alarm.tm_hour = tmp;
239 NVRAM->buffer[0x1FF4] = val;
240 set_alarm(NVRAM);
242 break;
243 case 0x1FF5:
244 /* alarm date */
245 tmp = from_bcd(val & 0x3F);
246 if (tmp != 0) {
247 NVRAM->alarm.tm_mday = tmp;
248 NVRAM->buffer[0x1FF5] = val;
249 set_alarm(NVRAM);
251 break;
252 case 0x1FF6:
253 /* interrupts */
254 NVRAM->buffer[0x1FF6] = val;
255 break;
256 case 0x1FF7:
257 /* watchdog */
258 NVRAM->buffer[0x1FF7] = val;
259 set_up_watchdog(NVRAM, val);
260 break;
261 case 0x1FF8:
262 case 0x07F8:
263 /* control */
264 NVRAM->buffer[addr] = (val & ~0xA0) | 0x90;
265 break;
266 case 0x1FF9:
267 case 0x07F9:
268 /* seconds (BCD) */
269 tmp = from_bcd(val & 0x7F);
270 if (tmp >= 0 && tmp <= 59) {
271 get_time(NVRAM, &tm);
272 tm.tm_sec = tmp;
273 set_time(NVRAM, &tm);
275 if ((val & 0x80) ^ (NVRAM->buffer[addr] & 0x80)) {
276 if (val & 0x80) {
277 NVRAM->stop_time = time(NULL);
278 } else {
279 NVRAM->time_offset += NVRAM->stop_time - time(NULL);
280 NVRAM->stop_time = 0;
283 NVRAM->buffer[addr] = val & 0x80;
284 break;
285 case 0x1FFA:
286 case 0x07FA:
287 /* minutes (BCD) */
288 tmp = from_bcd(val & 0x7F);
289 if (tmp >= 0 && tmp <= 59) {
290 get_time(NVRAM, &tm);
291 tm.tm_min = tmp;
292 set_time(NVRAM, &tm);
294 break;
295 case 0x1FFB:
296 case 0x07FB:
297 /* hours (BCD) */
298 tmp = from_bcd(val & 0x3F);
299 if (tmp >= 0 && tmp <= 23) {
300 get_time(NVRAM, &tm);
301 tm.tm_hour = tmp;
302 set_time(NVRAM, &tm);
304 break;
305 case 0x1FFC:
306 case 0x07FC:
307 /* day of the week / century */
308 tmp = from_bcd(val & 0x07);
309 get_time(NVRAM, &tm);
310 tm.tm_wday = tmp;
311 set_time(NVRAM, &tm);
312 NVRAM->buffer[addr] = val & 0x40;
313 break;
314 case 0x1FFD:
315 case 0x07FD:
316 /* date (BCD) */
317 tmp = from_bcd(val & 0x3F);
318 if (tmp != 0) {
319 get_time(NVRAM, &tm);
320 tm.tm_mday = tmp;
321 set_time(NVRAM, &tm);
323 break;
324 case 0x1FFE:
325 case 0x07FE:
326 /* month */
327 tmp = from_bcd(val & 0x1F);
328 if (tmp >= 1 && tmp <= 12) {
329 get_time(NVRAM, &tm);
330 tm.tm_mon = tmp - 1;
331 set_time(NVRAM, &tm);
333 break;
334 case 0x1FFF:
335 case 0x07FF:
336 /* year */
337 tmp = from_bcd(val);
338 if (tmp >= 0 && tmp <= 99) {
339 get_time(NVRAM, &tm);
340 if (NVRAM->model == 8) {
341 tm.tm_year = from_bcd(val) + 68; // Base year is 1968
342 } else {
343 tm.tm_year = from_bcd(val);
345 set_time(NVRAM, &tm);
347 break;
348 default:
349 /* Check lock registers state */
350 if (addr >= 0x20 && addr <= 0x2F && (NVRAM->lock & 1))
351 break;
352 if (addr >= 0x30 && addr <= 0x3F && (NVRAM->lock & 2))
353 break;
354 do_write:
355 if (addr < NVRAM->size) {
356 NVRAM->buffer[addr] = val & 0xFF;
358 break;
362 uint32_t m48t59_read (void *opaque, uint32_t addr)
364 M48t59State *NVRAM = opaque;
365 struct tm tm;
366 uint32_t retval = 0xFF;
368 /* check for NVRAM access */
369 if ((NVRAM->model == 2 && addr < 0x078f) ||
370 (NVRAM->model == 8 && addr < 0x1ff8) ||
371 (NVRAM->model == 59 && addr < 0x1ff0)) {
372 goto do_read;
375 /* TOD access */
376 switch (addr) {
377 case 0x1FF0:
378 /* flags register */
379 goto do_read;
380 case 0x1FF1:
381 /* unused */
382 retval = 0;
383 break;
384 case 0x1FF2:
385 /* alarm seconds */
386 goto do_read;
387 case 0x1FF3:
388 /* alarm minutes */
389 goto do_read;
390 case 0x1FF4:
391 /* alarm hours */
392 goto do_read;
393 case 0x1FF5:
394 /* alarm date */
395 goto do_read;
396 case 0x1FF6:
397 /* interrupts */
398 goto do_read;
399 case 0x1FF7:
400 /* A read resets the watchdog */
401 set_up_watchdog(NVRAM, NVRAM->buffer[0x1FF7]);
402 goto do_read;
403 case 0x1FF8:
404 case 0x07F8:
405 /* control */
406 goto do_read;
407 case 0x1FF9:
408 case 0x07F9:
409 /* seconds (BCD) */
410 get_time(NVRAM, &tm);
411 retval = (NVRAM->buffer[addr] & 0x80) | to_bcd(tm.tm_sec);
412 break;
413 case 0x1FFA:
414 case 0x07FA:
415 /* minutes (BCD) */
416 get_time(NVRAM, &tm);
417 retval = to_bcd(tm.tm_min);
418 break;
419 case 0x1FFB:
420 case 0x07FB:
421 /* hours (BCD) */
422 get_time(NVRAM, &tm);
423 retval = to_bcd(tm.tm_hour);
424 break;
425 case 0x1FFC:
426 case 0x07FC:
427 /* day of the week / century */
428 get_time(NVRAM, &tm);
429 retval = NVRAM->buffer[addr] | tm.tm_wday;
430 break;
431 case 0x1FFD:
432 case 0x07FD:
433 /* date */
434 get_time(NVRAM, &tm);
435 retval = to_bcd(tm.tm_mday);
436 break;
437 case 0x1FFE:
438 case 0x07FE:
439 /* month */
440 get_time(NVRAM, &tm);
441 retval = to_bcd(tm.tm_mon + 1);
442 break;
443 case 0x1FFF:
444 case 0x07FF:
445 /* year */
446 get_time(NVRAM, &tm);
447 if (NVRAM->model == 8) {
448 retval = to_bcd(tm.tm_year - 68); // Base year is 1968
449 } else {
450 retval = to_bcd(tm.tm_year);
452 break;
453 default:
454 /* Check lock registers state */
455 if (addr >= 0x20 && addr <= 0x2F && (NVRAM->lock & 1))
456 break;
457 if (addr >= 0x30 && addr <= 0x3F && (NVRAM->lock & 2))
458 break;
459 do_read:
460 if (addr < NVRAM->size) {
461 retval = NVRAM->buffer[addr];
463 break;
465 if (addr > 0x1FF9 && addr < 0x2000)
466 NVRAM_PRINTF("%s: 0x%08x <= 0x%08x\n", __func__, addr, retval);
468 return retval;
471 void m48t59_set_addr (void *opaque, uint32_t addr)
473 M48t59State *NVRAM = opaque;
475 NVRAM->addr = addr;
478 void m48t59_toggle_lock (void *opaque, int lock)
480 M48t59State *NVRAM = opaque;
482 NVRAM->lock ^= 1 << lock;
485 /* IO access to NVRAM */
486 static void NVRAM_writeb(void *opaque, hwaddr addr, uint64_t val,
487 unsigned size)
489 M48t59State *NVRAM = opaque;
491 NVRAM_PRINTF("%s: 0x%08x => 0x%08x\n", __func__, addr, val);
492 switch (addr) {
493 case 0:
494 NVRAM->addr &= ~0x00FF;
495 NVRAM->addr |= val;
496 break;
497 case 1:
498 NVRAM->addr &= ~0xFF00;
499 NVRAM->addr |= val << 8;
500 break;
501 case 3:
502 m48t59_write(NVRAM, NVRAM->addr, val);
503 NVRAM->addr = 0x0000;
504 break;
505 default:
506 break;
510 static uint64_t NVRAM_readb(void *opaque, hwaddr addr, unsigned size)
512 M48t59State *NVRAM = opaque;
513 uint32_t retval;
515 switch (addr) {
516 case 3:
517 retval = m48t59_read(NVRAM, NVRAM->addr);
518 break;
519 default:
520 retval = -1;
521 break;
523 NVRAM_PRINTF("%s: 0x%08x <= 0x%08x\n", __func__, addr, retval);
525 return retval;
528 static void nvram_writeb (void *opaque, hwaddr addr, uint32_t value)
530 M48t59State *NVRAM = opaque;
532 m48t59_write(NVRAM, addr, value & 0xff);
535 static void nvram_writew (void *opaque, hwaddr addr, uint32_t value)
537 M48t59State *NVRAM = opaque;
539 m48t59_write(NVRAM, addr, (value >> 8) & 0xff);
540 m48t59_write(NVRAM, addr + 1, value & 0xff);
543 static void nvram_writel (void *opaque, hwaddr addr, uint32_t value)
545 M48t59State *NVRAM = opaque;
547 m48t59_write(NVRAM, addr, (value >> 24) & 0xff);
548 m48t59_write(NVRAM, addr + 1, (value >> 16) & 0xff);
549 m48t59_write(NVRAM, addr + 2, (value >> 8) & 0xff);
550 m48t59_write(NVRAM, addr + 3, value & 0xff);
553 static uint32_t nvram_readb (void *opaque, hwaddr addr)
555 M48t59State *NVRAM = opaque;
556 uint32_t retval;
558 retval = m48t59_read(NVRAM, addr);
559 return retval;
562 static uint32_t nvram_readw (void *opaque, hwaddr addr)
564 M48t59State *NVRAM = opaque;
565 uint32_t retval;
567 retval = m48t59_read(NVRAM, addr) << 8;
568 retval |= m48t59_read(NVRAM, addr + 1);
569 return retval;
572 static uint32_t nvram_readl (void *opaque, hwaddr addr)
574 M48t59State *NVRAM = opaque;
575 uint32_t retval;
577 retval = m48t59_read(NVRAM, addr) << 24;
578 retval |= m48t59_read(NVRAM, addr + 1) << 16;
579 retval |= m48t59_read(NVRAM, addr + 2) << 8;
580 retval |= m48t59_read(NVRAM, addr + 3);
581 return retval;
584 static const MemoryRegionOps nvram_ops = {
585 .old_mmio = {
586 .read = { nvram_readb, nvram_readw, nvram_readl, },
587 .write = { nvram_writeb, nvram_writew, nvram_writel, },
589 .endianness = DEVICE_NATIVE_ENDIAN,
592 static const VMStateDescription vmstate_m48t59 = {
593 .name = "m48t59",
594 .version_id = 1,
595 .minimum_version_id = 1,
596 .minimum_version_id_old = 1,
597 .fields = (VMStateField[]) {
598 VMSTATE_UINT8(lock, M48t59State),
599 VMSTATE_UINT16(addr, M48t59State),
600 VMSTATE_VBUFFER_UINT32(buffer, M48t59State, 0, NULL, 0, size),
601 VMSTATE_END_OF_LIST()
605 static void m48t59_reset_common(M48t59State *NVRAM)
607 NVRAM->addr = 0;
608 NVRAM->lock = 0;
609 if (NVRAM->alrm_timer != NULL)
610 qemu_del_timer(NVRAM->alrm_timer);
612 if (NVRAM->wd_timer != NULL)
613 qemu_del_timer(NVRAM->wd_timer);
616 static void m48t59_reset_isa(DeviceState *d)
618 M48t59ISAState *isa = container_of(d, M48t59ISAState, busdev.qdev);
619 M48t59State *NVRAM = &isa->state;
621 m48t59_reset_common(NVRAM);
624 static void m48t59_reset_sysbus(DeviceState *d)
626 M48t59SysBusState *sys = container_of(d, M48t59SysBusState, busdev.qdev);
627 M48t59State *NVRAM = &sys->state;
629 m48t59_reset_common(NVRAM);
632 static const MemoryRegionOps m48t59_io_ops = {
633 .read = NVRAM_readb,
634 .write = NVRAM_writeb,
635 .impl = {
636 .min_access_size = 1,
637 .max_access_size = 1,
639 .endianness = DEVICE_LITTLE_ENDIAN,
642 /* Initialisation routine */
643 M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
644 uint32_t io_base, uint16_t size, int model)
646 DeviceState *dev;
647 SysBusDevice *s;
648 M48t59SysBusState *d;
649 M48t59State *state;
651 dev = qdev_create(NULL, "m48t59");
652 qdev_prop_set_uint32(dev, "model", model);
653 qdev_prop_set_uint32(dev, "size", size);
654 qdev_prop_set_uint32(dev, "io_base", io_base);
655 qdev_init_nofail(dev);
656 s = sysbus_from_qdev(dev);
657 d = FROM_SYSBUS(M48t59SysBusState, s);
658 state = &d->state;
659 sysbus_connect_irq(s, 0, IRQ);
660 memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
661 if (io_base != 0) {
662 memory_region_add_subregion(get_system_io(), io_base, &d->io);
664 if (mem_base != 0) {
665 sysbus_mmio_map(s, 0, mem_base);
668 return state;
671 M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
672 int model)
674 M48t59ISAState *d;
675 ISADevice *dev;
676 M48t59State *s;
678 dev = isa_create(bus, "m48t59_isa");
679 qdev_prop_set_uint32(&dev->qdev, "model", model);
680 qdev_prop_set_uint32(&dev->qdev, "size", size);
681 qdev_prop_set_uint32(&dev->qdev, "io_base", io_base);
682 qdev_init_nofail(&dev->qdev);
683 d = DO_UPCAST(M48t59ISAState, busdev, dev);
684 s = &d->state;
686 memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
687 if (io_base != 0) {
688 isa_register_ioport(dev, &d->io, io_base);
691 return s;
694 static void m48t59_init_common(M48t59State *s)
696 s->buffer = g_malloc0(s->size);
697 if (s->model == 59) {
698 s->alrm_timer = qemu_new_timer_ns(rtc_clock, &alarm_cb, s);
699 s->wd_timer = qemu_new_timer_ns(vm_clock, &watchdog_cb, s);
701 qemu_get_timedate(&s->alarm, 0);
703 vmstate_register(NULL, -1, &vmstate_m48t59, s);
706 static int m48t59_init_isa1(ISADevice *dev)
708 M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
709 M48t59State *s = &d->state;
711 isa_init_irq(dev, &s->IRQ, 8);
712 m48t59_init_common(s);
714 return 0;
717 static int m48t59_init1(SysBusDevice *dev)
719 M48t59SysBusState *d = FROM_SYSBUS(M48t59SysBusState, dev);
720 M48t59State *s = &d->state;
722 sysbus_init_irq(dev, &s->IRQ);
724 memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size);
725 sysbus_init_mmio(dev, &s->iomem);
726 m48t59_init_common(s);
728 return 0;
731 static Property m48t59_isa_properties[] = {
732 DEFINE_PROP_UINT32("size", M48t59ISAState, state.size, -1),
733 DEFINE_PROP_UINT32("model", M48t59ISAState, state.model, -1),
734 DEFINE_PROP_HEX32( "io_base", M48t59ISAState, state.io_base, 0),
735 DEFINE_PROP_END_OF_LIST(),
738 static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
740 DeviceClass *dc = DEVICE_CLASS(klass);
741 ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
742 ic->init = m48t59_init_isa1;
743 dc->no_user = 1;
744 dc->reset = m48t59_reset_isa;
745 dc->props = m48t59_isa_properties;
748 static TypeInfo m48t59_isa_info = {
749 .name = "m48t59_isa",
750 .parent = TYPE_ISA_DEVICE,
751 .instance_size = sizeof(M48t59ISAState),
752 .class_init = m48t59_init_class_isa1,
755 static Property m48t59_properties[] = {
756 DEFINE_PROP_UINT32("size", M48t59SysBusState, state.size, -1),
757 DEFINE_PROP_UINT32("model", M48t59SysBusState, state.model, -1),
758 DEFINE_PROP_HEX32( "io_base", M48t59SysBusState, state.io_base, 0),
759 DEFINE_PROP_END_OF_LIST(),
762 static void m48t59_class_init(ObjectClass *klass, void *data)
764 DeviceClass *dc = DEVICE_CLASS(klass);
765 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
767 k->init = m48t59_init1;
768 dc->reset = m48t59_reset_sysbus;
769 dc->props = m48t59_properties;
772 static TypeInfo m48t59_info = {
773 .name = "m48t59",
774 .parent = TYPE_SYS_BUS_DEVICE,
775 .instance_size = sizeof(M48t59SysBusState),
776 .class_init = m48t59_class_init,
779 static void m48t59_register_types(void)
781 type_register_static(&m48t59_info);
782 type_register_static(&m48t59_isa_info);
785 type_init(m48t59_register_types)