blob: 7da7e7c822cebf379e9f5ac630ab47890ad5eab6 [file] [log] [blame]
bellarda541f292004-04-12 20:39:29 +00001/*
bellard819385c2005-10-30 16:58:32 +00002 * QEMU M48T59 and M48T08 NVRAM emulation for PPC PREP and Sparc platforms
ths5fafdf22007-09-16 21:08:06 +00003 *
blueswir13ccacc42007-04-14 13:01:31 +00004 * Copyright (c) 2003-2005, 2007 Jocelyn Mayer
ths5fafdf22007-09-16 21:08:06 +00005 *
bellarda541f292004-04-12 20:39:29 +00006 * 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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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.
23 */
pbrook87ecb682007-11-17 17:14:51 +000024#include "hw.h"
25#include "nvram.h"
pbrook87ecb682007-11-17 17:14:51 +000026#include "qemu-timer.h"
27#include "sysemu.h"
Blue Swirld27cf0a2009-07-12 20:07:07 +000028#include "sysbus.h"
Blue Swirlf80237d2009-09-14 15:33:28 +000029#include "isa.h"
Alexander Graf087bd052012-10-08 13:19:48 +020030#include "exec-memory.h"
bellarda541f292004-04-12 20:39:29 +000031
bellard13ab5da2004-05-17 20:21:49 +000032//#define DEBUG_NVRAM
bellarda541f292004-04-12 20:39:29 +000033
bellard13ab5da2004-05-17 20:21:49 +000034#if defined(DEBUG_NVRAM)
Blue Swirl001faf32009-05-13 17:53:17 +000035#define NVRAM_PRINTF(fmt, ...) do { printf(fmt , ## __VA_ARGS__); } while (0)
bellarda541f292004-04-12 20:39:29 +000036#else
Blue Swirl001faf32009-05-13 17:53:17 +000037#define NVRAM_PRINTF(fmt, ...) do { } while (0)
bellarda541f292004-04-12 20:39:29 +000038#endif
39
bellard819385c2005-10-30 16:58:32 +000040/*
blueswir14aed2c32007-12-29 09:05:30 +000041 * The M48T02, M48T08 and M48T59 chips are very similar. The newer '59 has
bellard819385c2005-10-30 16:58:32 +000042 * alarm and a watchdog timer and related control registers. In the
43 * PPC platform there is also a nvram lock function.
44 */
Blue Swirl930f3fe2009-10-13 18:56:27 +000045
46/*
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
51 */
52
Blue Swirl43a34702010-02-07 08:05:03 +000053struct M48t59State {
bellarda541f292004-04-12 20:39:29 +000054 /* Hardware parameters */
pbrookd537cf62007-04-07 18:14:41 +000055 qemu_irq IRQ;
Avi Kivity5a31cd62011-11-13 12:16:07 +020056 MemoryRegion iomem;
bellarda541f292004-04-12 20:39:29 +000057 uint32_t io_base;
Gerd Hoffmannee6847d2009-07-15 13:43:31 +020058 uint32_t size;
bellarda541f292004-04-12 20:39:29 +000059 /* RTC management */
60 time_t time_offset;
61 time_t stop_time;
62 /* Alarm & watchdog */
balrogf6503052008-02-17 11:42:19 +000063 struct tm alarm;
bellarda541f292004-04-12 20:39:29 +000064 struct QEMUTimer *alrm_timer;
65 struct QEMUTimer *wd_timer;
66 /* NVRAM storage */
bellarda541f292004-04-12 20:39:29 +000067 uint8_t *buffer;
Blue Swirl42c812b2011-08-07 20:02:02 +000068 /* Model parameters */
Paolo Bonzini7bc30182012-05-23 19:25:34 +020069 uint32_t model; /* 2 = m48t02, 8 = m48t08, 59 = m48t59 */
Blue Swirl42c812b2011-08-07 20:02:02 +000070 /* NVRAM storage */
71 uint16_t addr;
72 uint8_t lock;
bellardc5df0182004-04-12 20:54:52 +000073};
bellarda541f292004-04-12 20:39:29 +000074
Blue Swirlf80237d2009-09-14 15:33:28 +000075typedef struct M48t59ISAState {
76 ISADevice busdev;
Blue Swirl43a34702010-02-07 08:05:03 +000077 M48t59State state;
Richard Henderson9936d6e2011-08-15 15:33:40 -070078 MemoryRegion io;
Blue Swirlf80237d2009-09-14 15:33:28 +000079} M48t59ISAState;
80
81typedef struct M48t59SysBusState {
82 SysBusDevice busdev;
Blue Swirl43a34702010-02-07 08:05:03 +000083 M48t59State state;
Alexander Graf087bd052012-10-08 13:19:48 +020084 MemoryRegion io;
Blue Swirlf80237d2009-09-14 15:33:28 +000085} M48t59SysBusState;
86
bellarda541f292004-04-12 20:39:29 +000087/* Fake timer functions */
bellarda541f292004-04-12 20:39:29 +000088
bellarda541f292004-04-12 20:39:29 +000089/* Alarm management */
90static void alarm_cb (void *opaque)
91{
balrogf6503052008-02-17 11:42:19 +000092 struct tm tm;
bellarda541f292004-04-12 20:39:29 +000093 uint64_t next_time;
Blue Swirl43a34702010-02-07 08:05:03 +000094 M48t59State *NVRAM = opaque;
bellarda541f292004-04-12 20:39:29 +000095
pbrookd537cf62007-04-07 18:14:41 +000096 qemu_set_irq(NVRAM->IRQ, 1);
ths5fafdf22007-09-16 21:08:06 +000097 if ((NVRAM->buffer[0x1FF5] & 0x80) == 0 &&
bellarda541f292004-04-12 20:39:29 +000098 (NVRAM->buffer[0x1FF4] & 0x80) == 0 &&
99 (NVRAM->buffer[0x1FF3] & 0x80) == 0 &&
100 (NVRAM->buffer[0x1FF2] & 0x80) == 0) {
balrogf6503052008-02-17 11:42:19 +0000101 /* 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++;
107 }
108 next_time = qemu_timedate_diff(&tm) - NVRAM->time_offset;
bellarda541f292004-04-12 20:39:29 +0000109 } 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) {
balrogf6503052008-02-17 11:42:19 +0000113 /* Repeat once a day */
114 next_time = 24 * 60 * 60;
bellarda541f292004-04-12 20:39:29 +0000115 } 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) {
balrogf6503052008-02-17 11:42:19 +0000119 /* Repeat once an hour */
120 next_time = 60 * 60;
bellarda541f292004-04-12 20:39:29 +0000121 } 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) {
balrogf6503052008-02-17 11:42:19 +0000125 /* Repeat once a minute */
126 next_time = 60;
bellarda541f292004-04-12 20:39:29 +0000127 } else {
balrogf6503052008-02-17 11:42:19 +0000128 /* Repeat once a second */
129 next_time = 1;
bellarda541f292004-04-12 20:39:29 +0000130 }
Paolo Bonzini1d849502012-01-20 13:05:00 +0100131 qemu_mod_timer(NVRAM->alrm_timer, qemu_get_clock_ns(rtc_clock) +
balrogf6503052008-02-17 11:42:19 +0000132 next_time * 1000);
pbrookd537cf62007-04-07 18:14:41 +0000133 qemu_set_irq(NVRAM->IRQ, 0);
bellarda541f292004-04-12 20:39:29 +0000134}
135
Blue Swirl43a34702010-02-07 08:05:03 +0000136static void set_alarm(M48t59State *NVRAM)
bellarda541f292004-04-12 20:39:29 +0000137{
balrogf6503052008-02-17 11:42:19 +0000138 int diff;
bellarda541f292004-04-12 20:39:29 +0000139 if (NVRAM->alrm_timer != NULL) {
140 qemu_del_timer(NVRAM->alrm_timer);
balrogf6503052008-02-17 11:42:19 +0000141 diff = qemu_timedate_diff(&NVRAM->alarm) - NVRAM->time_offset;
142 if (diff > 0)
143 qemu_mod_timer(NVRAM->alrm_timer, diff * 1000);
bellarda541f292004-04-12 20:39:29 +0000144 }
bellarda541f292004-04-12 20:39:29 +0000145}
146
balrogf6503052008-02-17 11:42:19 +0000147/* RTC management helpers */
Blue Swirl43a34702010-02-07 08:05:03 +0000148static inline void get_time(M48t59State *NVRAM, struct tm *tm)
balrogf6503052008-02-17 11:42:19 +0000149{
150 qemu_get_timedate(tm, NVRAM->time_offset);
151}
152
Blue Swirl43a34702010-02-07 08:05:03 +0000153static void set_time(M48t59State *NVRAM, struct tm *tm)
balrogf6503052008-02-17 11:42:19 +0000154{
155 NVRAM->time_offset = qemu_timedate_diff(tm);
156 set_alarm(NVRAM);
157}
158
bellarda541f292004-04-12 20:39:29 +0000159/* Watchdog management */
160static void watchdog_cb (void *opaque)
161{
Blue Swirl43a34702010-02-07 08:05:03 +0000162 M48t59State *NVRAM = opaque;
bellarda541f292004-04-12 20:39:29 +0000163
164 NVRAM->buffer[0x1FF0] |= 0x80;
165 if (NVRAM->buffer[0x1FF7] & 0x80) {
166 NVRAM->buffer[0x1FF7] = 0x00;
167 NVRAM->buffer[0x1FFC] &= ~0x40;
bellard13ab5da2004-05-17 20:21:49 +0000168 /* May it be a hw CPU Reset instead ? */
bellardd7d02e32004-06-20 12:58:36 +0000169 qemu_system_reset_request();
bellarda541f292004-04-12 20:39:29 +0000170 } else {
pbrookd537cf62007-04-07 18:14:41 +0000171 qemu_set_irq(NVRAM->IRQ, 1);
172 qemu_set_irq(NVRAM->IRQ, 0);
bellarda541f292004-04-12 20:39:29 +0000173 }
174}
175
Blue Swirl43a34702010-02-07 08:05:03 +0000176static void set_up_watchdog(M48t59State *NVRAM, uint8_t value)
bellarda541f292004-04-12 20:39:29 +0000177{
178 uint64_t interval; /* in 1/16 seconds */
179
j_mayer868d5852007-09-30 01:29:07 +0000180 NVRAM->buffer[0x1FF0] &= ~0x80;
bellarda541f292004-04-12 20:39:29 +0000181 if (NVRAM->wd_timer != NULL) {
182 qemu_del_timer(NVRAM->wd_timer);
j_mayer868d5852007-09-30 01:29:07 +0000183 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));
187 }
bellarda541f292004-04-12 20:39:29 +0000188 }
189}
190
191/* Direct access to NVRAM */
j_mayer897b4c62007-10-28 23:33:05 +0000192void m48t59_write (void *opaque, uint32_t addr, uint32_t val)
bellarda541f292004-04-12 20:39:29 +0000193{
Blue Swirl43a34702010-02-07 08:05:03 +0000194 M48t59State *NVRAM = opaque;
bellarda541f292004-04-12 20:39:29 +0000195 struct tm tm;
196 int tmp;
197
bellard819385c2005-10-30 16:58:32 +0000198 if (addr > 0x1FF8 && addr < 0x2000)
199 NVRAM_PRINTF("%s: 0x%08x => 0x%08x\n", __func__, addr, val);
blueswir14aed2c32007-12-29 09:05:30 +0000200
201 /* check for NVRAM access */
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200202 if ((NVRAM->model == 2 && addr < 0x7f8) ||
203 (NVRAM->model == 8 && addr < 0x1ff8) ||
204 (NVRAM->model == 59 && addr < 0x1ff0)) {
bellard819385c2005-10-30 16:58:32 +0000205 goto do_write;
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200206 }
blueswir14aed2c32007-12-29 09:05:30 +0000207
208 /* TOD access */
bellard819385c2005-10-30 16:58:32 +0000209 switch (addr) {
bellarda541f292004-04-12 20:39:29 +0000210 case 0x1FF0:
211 /* flags register : read-only */
212 break;
213 case 0x1FF1:
214 /* unused */
215 break;
216 case 0x1FF2:
217 /* alarm seconds */
Paul Brookabd0c6b2009-11-20 00:03:47 +0000218 tmp = from_bcd(val & 0x7F);
bellard819385c2005-10-30 16:58:32 +0000219 if (tmp >= 0 && tmp <= 59) {
balrogf6503052008-02-17 11:42:19 +0000220 NVRAM->alarm.tm_sec = tmp;
bellard819385c2005-10-30 16:58:32 +0000221 NVRAM->buffer[0x1FF2] = val;
balrogf6503052008-02-17 11:42:19 +0000222 set_alarm(NVRAM);
bellard819385c2005-10-30 16:58:32 +0000223 }
bellarda541f292004-04-12 20:39:29 +0000224 break;
225 case 0x1FF3:
226 /* alarm minutes */
Paul Brookabd0c6b2009-11-20 00:03:47 +0000227 tmp = from_bcd(val & 0x7F);
bellard819385c2005-10-30 16:58:32 +0000228 if (tmp >= 0 && tmp <= 59) {
balrogf6503052008-02-17 11:42:19 +0000229 NVRAM->alarm.tm_min = tmp;
bellard819385c2005-10-30 16:58:32 +0000230 NVRAM->buffer[0x1FF3] = val;
balrogf6503052008-02-17 11:42:19 +0000231 set_alarm(NVRAM);
bellard819385c2005-10-30 16:58:32 +0000232 }
bellarda541f292004-04-12 20:39:29 +0000233 break;
234 case 0x1FF4:
235 /* alarm hours */
Paul Brookabd0c6b2009-11-20 00:03:47 +0000236 tmp = from_bcd(val & 0x3F);
bellard819385c2005-10-30 16:58:32 +0000237 if (tmp >= 0 && tmp <= 23) {
balrogf6503052008-02-17 11:42:19 +0000238 NVRAM->alarm.tm_hour = tmp;
bellard819385c2005-10-30 16:58:32 +0000239 NVRAM->buffer[0x1FF4] = val;
balrogf6503052008-02-17 11:42:19 +0000240 set_alarm(NVRAM);
bellard819385c2005-10-30 16:58:32 +0000241 }
bellarda541f292004-04-12 20:39:29 +0000242 break;
243 case 0x1FF5:
244 /* alarm date */
Artyom Tarasenko02f5da12012-04-23 16:48:31 +0200245 tmp = from_bcd(val & 0x3F);
bellard819385c2005-10-30 16:58:32 +0000246 if (tmp != 0) {
balrogf6503052008-02-17 11:42:19 +0000247 NVRAM->alarm.tm_mday = tmp;
bellard819385c2005-10-30 16:58:32 +0000248 NVRAM->buffer[0x1FF5] = val;
balrogf6503052008-02-17 11:42:19 +0000249 set_alarm(NVRAM);
bellard819385c2005-10-30 16:58:32 +0000250 }
bellarda541f292004-04-12 20:39:29 +0000251 break;
252 case 0x1FF6:
253 /* interrupts */
bellard819385c2005-10-30 16:58:32 +0000254 NVRAM->buffer[0x1FF6] = val;
bellarda541f292004-04-12 20:39:29 +0000255 break;
256 case 0x1FF7:
257 /* watchdog */
bellard819385c2005-10-30 16:58:32 +0000258 NVRAM->buffer[0x1FF7] = val;
259 set_up_watchdog(NVRAM, val);
bellarda541f292004-04-12 20:39:29 +0000260 break;
261 case 0x1FF8:
blueswir14aed2c32007-12-29 09:05:30 +0000262 case 0x07F8:
bellarda541f292004-04-12 20:39:29 +0000263 /* control */
blueswir14aed2c32007-12-29 09:05:30 +0000264 NVRAM->buffer[addr] = (val & ~0xA0) | 0x90;
bellarda541f292004-04-12 20:39:29 +0000265 break;
266 case 0x1FF9:
blueswir14aed2c32007-12-29 09:05:30 +0000267 case 0x07F9:
bellarda541f292004-04-12 20:39:29 +0000268 /* seconds (BCD) */
Paul Brookabd0c6b2009-11-20 00:03:47 +0000269 tmp = from_bcd(val & 0x7F);
bellarda541f292004-04-12 20:39:29 +0000270 if (tmp >= 0 && tmp <= 59) {
271 get_time(NVRAM, &tm);
272 tm.tm_sec = tmp;
273 set_time(NVRAM, &tm);
274 }
balrogf6503052008-02-17 11:42:19 +0000275 if ((val & 0x80) ^ (NVRAM->buffer[addr] & 0x80)) {
bellarda541f292004-04-12 20:39:29 +0000276 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;
281 }
282 }
balrogf6503052008-02-17 11:42:19 +0000283 NVRAM->buffer[addr] = val & 0x80;
bellarda541f292004-04-12 20:39:29 +0000284 break;
285 case 0x1FFA:
blueswir14aed2c32007-12-29 09:05:30 +0000286 case 0x07FA:
bellarda541f292004-04-12 20:39:29 +0000287 /* minutes (BCD) */
Paul Brookabd0c6b2009-11-20 00:03:47 +0000288 tmp = from_bcd(val & 0x7F);
bellarda541f292004-04-12 20:39:29 +0000289 if (tmp >= 0 && tmp <= 59) {
290 get_time(NVRAM, &tm);
291 tm.tm_min = tmp;
292 set_time(NVRAM, &tm);
293 }
294 break;
295 case 0x1FFB:
blueswir14aed2c32007-12-29 09:05:30 +0000296 case 0x07FB:
bellarda541f292004-04-12 20:39:29 +0000297 /* hours (BCD) */
Paul Brookabd0c6b2009-11-20 00:03:47 +0000298 tmp = from_bcd(val & 0x3F);
bellarda541f292004-04-12 20:39:29 +0000299 if (tmp >= 0 && tmp <= 23) {
300 get_time(NVRAM, &tm);
301 tm.tm_hour = tmp;
302 set_time(NVRAM, &tm);
303 }
304 break;
305 case 0x1FFC:
blueswir14aed2c32007-12-29 09:05:30 +0000306 case 0x07FC:
bellarda541f292004-04-12 20:39:29 +0000307 /* day of the week / century */
Paul Brookabd0c6b2009-11-20 00:03:47 +0000308 tmp = from_bcd(val & 0x07);
bellarda541f292004-04-12 20:39:29 +0000309 get_time(NVRAM, &tm);
310 tm.tm_wday = tmp;
311 set_time(NVRAM, &tm);
blueswir14aed2c32007-12-29 09:05:30 +0000312 NVRAM->buffer[addr] = val & 0x40;
bellarda541f292004-04-12 20:39:29 +0000313 break;
314 case 0x1FFD:
blueswir14aed2c32007-12-29 09:05:30 +0000315 case 0x07FD:
Artyom Tarasenko02f5da12012-04-23 16:48:31 +0200316 /* date (BCD) */
317 tmp = from_bcd(val & 0x3F);
bellarda541f292004-04-12 20:39:29 +0000318 if (tmp != 0) {
319 get_time(NVRAM, &tm);
320 tm.tm_mday = tmp;
321 set_time(NVRAM, &tm);
322 }
323 break;
324 case 0x1FFE:
blueswir14aed2c32007-12-29 09:05:30 +0000325 case 0x07FE:
bellarda541f292004-04-12 20:39:29 +0000326 /* month */
Paul Brookabd0c6b2009-11-20 00:03:47 +0000327 tmp = from_bcd(val & 0x1F);
bellarda541f292004-04-12 20:39:29 +0000328 if (tmp >= 1 && tmp <= 12) {
329 get_time(NVRAM, &tm);
330 tm.tm_mon = tmp - 1;
331 set_time(NVRAM, &tm);
332 }
333 break;
334 case 0x1FFF:
blueswir14aed2c32007-12-29 09:05:30 +0000335 case 0x07FF:
bellarda541f292004-04-12 20:39:29 +0000336 /* year */
Paul Brookabd0c6b2009-11-20 00:03:47 +0000337 tmp = from_bcd(val);
bellarda541f292004-04-12 20:39:29 +0000338 if (tmp >= 0 && tmp <= 99) {
339 get_time(NVRAM, &tm);
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200340 if (NVRAM->model == 8) {
Paul Brookabd0c6b2009-11-20 00:03:47 +0000341 tm.tm_year = from_bcd(val) + 68; // Base year is 1968
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200342 } else {
Paul Brookabd0c6b2009-11-20 00:03:47 +0000343 tm.tm_year = from_bcd(val);
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200344 }
bellarda541f292004-04-12 20:39:29 +0000345 set_time(NVRAM, &tm);
346 }
347 break;
348 default:
bellard13ab5da2004-05-17 20:21:49 +0000349 /* Check lock registers state */
bellard819385c2005-10-30 16:58:32 +0000350 if (addr >= 0x20 && addr <= 0x2F && (NVRAM->lock & 1))
bellard13ab5da2004-05-17 20:21:49 +0000351 break;
bellard819385c2005-10-30 16:58:32 +0000352 if (addr >= 0x30 && addr <= 0x3F && (NVRAM->lock & 2))
bellard13ab5da2004-05-17 20:21:49 +0000353 break;
bellard819385c2005-10-30 16:58:32 +0000354 do_write:
355 if (addr < NVRAM->size) {
356 NVRAM->buffer[addr] = val & 0xFF;
bellarda541f292004-04-12 20:39:29 +0000357 }
358 break;
359 }
360}
361
j_mayer897b4c62007-10-28 23:33:05 +0000362uint32_t m48t59_read (void *opaque, uint32_t addr)
bellarda541f292004-04-12 20:39:29 +0000363{
Blue Swirl43a34702010-02-07 08:05:03 +0000364 M48t59State *NVRAM = opaque;
bellarda541f292004-04-12 20:39:29 +0000365 struct tm tm;
366 uint32_t retval = 0xFF;
367
blueswir14aed2c32007-12-29 09:05:30 +0000368 /* check for NVRAM access */
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200369 if ((NVRAM->model == 2 && addr < 0x078f) ||
370 (NVRAM->model == 8 && addr < 0x1ff8) ||
371 (NVRAM->model == 59 && addr < 0x1ff0)) {
bellard819385c2005-10-30 16:58:32 +0000372 goto do_read;
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200373 }
blueswir14aed2c32007-12-29 09:05:30 +0000374
375 /* TOD access */
bellard819385c2005-10-30 16:58:32 +0000376 switch (addr) {
bellarda541f292004-04-12 20:39:29 +0000377 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:
blueswir14aed2c32007-12-29 09:05:30 +0000404 case 0x07F8:
bellarda541f292004-04-12 20:39:29 +0000405 /* control */
406 goto do_read;
407 case 0x1FF9:
blueswir14aed2c32007-12-29 09:05:30 +0000408 case 0x07F9:
bellarda541f292004-04-12 20:39:29 +0000409 /* seconds (BCD) */
410 get_time(NVRAM, &tm);
Paul Brookabd0c6b2009-11-20 00:03:47 +0000411 retval = (NVRAM->buffer[addr] & 0x80) | to_bcd(tm.tm_sec);
bellarda541f292004-04-12 20:39:29 +0000412 break;
413 case 0x1FFA:
blueswir14aed2c32007-12-29 09:05:30 +0000414 case 0x07FA:
bellarda541f292004-04-12 20:39:29 +0000415 /* minutes (BCD) */
416 get_time(NVRAM, &tm);
Paul Brookabd0c6b2009-11-20 00:03:47 +0000417 retval = to_bcd(tm.tm_min);
bellarda541f292004-04-12 20:39:29 +0000418 break;
419 case 0x1FFB:
blueswir14aed2c32007-12-29 09:05:30 +0000420 case 0x07FB:
bellarda541f292004-04-12 20:39:29 +0000421 /* hours (BCD) */
422 get_time(NVRAM, &tm);
Paul Brookabd0c6b2009-11-20 00:03:47 +0000423 retval = to_bcd(tm.tm_hour);
bellarda541f292004-04-12 20:39:29 +0000424 break;
425 case 0x1FFC:
blueswir14aed2c32007-12-29 09:05:30 +0000426 case 0x07FC:
bellarda541f292004-04-12 20:39:29 +0000427 /* day of the week / century */
428 get_time(NVRAM, &tm);
blueswir14aed2c32007-12-29 09:05:30 +0000429 retval = NVRAM->buffer[addr] | tm.tm_wday;
bellarda541f292004-04-12 20:39:29 +0000430 break;
431 case 0x1FFD:
blueswir14aed2c32007-12-29 09:05:30 +0000432 case 0x07FD:
bellarda541f292004-04-12 20:39:29 +0000433 /* date */
434 get_time(NVRAM, &tm);
Paul Brookabd0c6b2009-11-20 00:03:47 +0000435 retval = to_bcd(tm.tm_mday);
bellarda541f292004-04-12 20:39:29 +0000436 break;
437 case 0x1FFE:
blueswir14aed2c32007-12-29 09:05:30 +0000438 case 0x07FE:
bellarda541f292004-04-12 20:39:29 +0000439 /* month */
440 get_time(NVRAM, &tm);
Paul Brookabd0c6b2009-11-20 00:03:47 +0000441 retval = to_bcd(tm.tm_mon + 1);
bellarda541f292004-04-12 20:39:29 +0000442 break;
443 case 0x1FFF:
blueswir14aed2c32007-12-29 09:05:30 +0000444 case 0x07FF:
bellarda541f292004-04-12 20:39:29 +0000445 /* year */
446 get_time(NVRAM, &tm);
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200447 if (NVRAM->model == 8) {
Paul Brookabd0c6b2009-11-20 00:03:47 +0000448 retval = to_bcd(tm.tm_year - 68); // Base year is 1968
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200449 } else {
Paul Brookabd0c6b2009-11-20 00:03:47 +0000450 retval = to_bcd(tm.tm_year);
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200451 }
bellarda541f292004-04-12 20:39:29 +0000452 break;
453 default:
bellard13ab5da2004-05-17 20:21:49 +0000454 /* Check lock registers state */
bellard819385c2005-10-30 16:58:32 +0000455 if (addr >= 0x20 && addr <= 0x2F && (NVRAM->lock & 1))
bellard13ab5da2004-05-17 20:21:49 +0000456 break;
bellard819385c2005-10-30 16:58:32 +0000457 if (addr >= 0x30 && addr <= 0x3F && (NVRAM->lock & 2))
bellard13ab5da2004-05-17 20:21:49 +0000458 break;
bellard819385c2005-10-30 16:58:32 +0000459 do_read:
460 if (addr < NVRAM->size) {
461 retval = NVRAM->buffer[addr];
bellarda541f292004-04-12 20:39:29 +0000462 }
463 break;
464 }
bellard819385c2005-10-30 16:58:32 +0000465 if (addr > 0x1FF9 && addr < 0x2000)
blueswir19ed1e662007-12-29 09:03:43 +0000466 NVRAM_PRINTF("%s: 0x%08x <= 0x%08x\n", __func__, addr, retval);
bellarda541f292004-04-12 20:39:29 +0000467
468 return retval;
469}
470
j_mayer897b4c62007-10-28 23:33:05 +0000471void m48t59_toggle_lock (void *opaque, int lock)
bellard13ab5da2004-05-17 20:21:49 +0000472{
Blue Swirl43a34702010-02-07 08:05:03 +0000473 M48t59State *NVRAM = opaque;
j_mayer897b4c62007-10-28 23:33:05 +0000474
bellard13ab5da2004-05-17 20:21:49 +0000475 NVRAM->lock ^= 1 << lock;
476}
477
bellarda541f292004-04-12 20:39:29 +0000478/* IO access to NVRAM */
Alexander Graf087bd052012-10-08 13:19:48 +0200479static void NVRAM_writeb(void *opaque, hwaddr addr, uint64_t val,
480 unsigned size)
bellarda541f292004-04-12 20:39:29 +0000481{
Blue Swirl43a34702010-02-07 08:05:03 +0000482 M48t59State *NVRAM = opaque;
bellarda541f292004-04-12 20:39:29 +0000483
blueswir19ed1e662007-12-29 09:03:43 +0000484 NVRAM_PRINTF("%s: 0x%08x => 0x%08x\n", __func__, addr, val);
bellarda541f292004-04-12 20:39:29 +0000485 switch (addr) {
486 case 0:
487 NVRAM->addr &= ~0x00FF;
488 NVRAM->addr |= val;
489 break;
490 case 1:
491 NVRAM->addr &= ~0xFF00;
492 NVRAM->addr |= val << 8;
493 break;
494 case 3:
Blue Swirlb1f88302011-10-15 08:05:18 +0000495 m48t59_write(NVRAM, NVRAM->addr, val);
bellarda541f292004-04-12 20:39:29 +0000496 NVRAM->addr = 0x0000;
497 break;
498 default:
499 break;
500 }
501}
502
Alexander Graf087bd052012-10-08 13:19:48 +0200503static uint64_t NVRAM_readb(void *opaque, hwaddr addr, unsigned size)
bellarda541f292004-04-12 20:39:29 +0000504{
Blue Swirl43a34702010-02-07 08:05:03 +0000505 M48t59State *NVRAM = opaque;
bellard13ab5da2004-05-17 20:21:49 +0000506 uint32_t retval;
bellarda541f292004-04-12 20:39:29 +0000507
bellard13ab5da2004-05-17 20:21:49 +0000508 switch (addr) {
509 case 3:
bellard819385c2005-10-30 16:58:32 +0000510 retval = m48t59_read(NVRAM, NVRAM->addr);
bellard13ab5da2004-05-17 20:21:49 +0000511 break;
512 default:
513 retval = -1;
514 break;
515 }
blueswir19ed1e662007-12-29 09:03:43 +0000516 NVRAM_PRINTF("%s: 0x%08x <= 0x%08x\n", __func__, addr, retval);
bellarda541f292004-04-12 20:39:29 +0000517
bellard13ab5da2004-05-17 20:21:49 +0000518 return retval;
bellarda541f292004-04-12 20:39:29 +0000519}
520
Avi Kivitya8170e52012-10-23 12:30:10 +0200521static void nvram_writeb (void *opaque, hwaddr addr, uint32_t value)
bellarde1bb04f2004-06-21 16:49:53 +0000522{
Blue Swirl43a34702010-02-07 08:05:03 +0000523 M48t59State *NVRAM = opaque;
ths3b46e622007-09-17 08:09:54 +0000524
bellard819385c2005-10-30 16:58:32 +0000525 m48t59_write(NVRAM, addr, value & 0xff);
bellarde1bb04f2004-06-21 16:49:53 +0000526}
527
Avi Kivitya8170e52012-10-23 12:30:10 +0200528static void nvram_writew (void *opaque, hwaddr addr, uint32_t value)
bellarde1bb04f2004-06-21 16:49:53 +0000529{
Blue Swirl43a34702010-02-07 08:05:03 +0000530 M48t59State *NVRAM = opaque;
ths3b46e622007-09-17 08:09:54 +0000531
bellard819385c2005-10-30 16:58:32 +0000532 m48t59_write(NVRAM, addr, (value >> 8) & 0xff);
533 m48t59_write(NVRAM, addr + 1, value & 0xff);
bellarde1bb04f2004-06-21 16:49:53 +0000534}
535
Avi Kivitya8170e52012-10-23 12:30:10 +0200536static void nvram_writel (void *opaque, hwaddr addr, uint32_t value)
bellarde1bb04f2004-06-21 16:49:53 +0000537{
Blue Swirl43a34702010-02-07 08:05:03 +0000538 M48t59State *NVRAM = opaque;
ths3b46e622007-09-17 08:09:54 +0000539
bellard819385c2005-10-30 16:58:32 +0000540 m48t59_write(NVRAM, addr, (value >> 24) & 0xff);
541 m48t59_write(NVRAM, addr + 1, (value >> 16) & 0xff);
542 m48t59_write(NVRAM, addr + 2, (value >> 8) & 0xff);
543 m48t59_write(NVRAM, addr + 3, value & 0xff);
bellarde1bb04f2004-06-21 16:49:53 +0000544}
545
Avi Kivitya8170e52012-10-23 12:30:10 +0200546static uint32_t nvram_readb (void *opaque, hwaddr addr)
bellarde1bb04f2004-06-21 16:49:53 +0000547{
Blue Swirl43a34702010-02-07 08:05:03 +0000548 M48t59State *NVRAM = opaque;
bellard819385c2005-10-30 16:58:32 +0000549 uint32_t retval;
ths3b46e622007-09-17 08:09:54 +0000550
bellard819385c2005-10-30 16:58:32 +0000551 retval = m48t59_read(NVRAM, addr);
bellarde1bb04f2004-06-21 16:49:53 +0000552 return retval;
553}
554
Avi Kivitya8170e52012-10-23 12:30:10 +0200555static uint32_t nvram_readw (void *opaque, hwaddr addr)
bellarde1bb04f2004-06-21 16:49:53 +0000556{
Blue Swirl43a34702010-02-07 08:05:03 +0000557 M48t59State *NVRAM = opaque;
bellard819385c2005-10-30 16:58:32 +0000558 uint32_t retval;
ths3b46e622007-09-17 08:09:54 +0000559
bellard819385c2005-10-30 16:58:32 +0000560 retval = m48t59_read(NVRAM, addr) << 8;
561 retval |= m48t59_read(NVRAM, addr + 1);
bellarde1bb04f2004-06-21 16:49:53 +0000562 return retval;
563}
564
Avi Kivitya8170e52012-10-23 12:30:10 +0200565static uint32_t nvram_readl (void *opaque, hwaddr addr)
bellarde1bb04f2004-06-21 16:49:53 +0000566{
Blue Swirl43a34702010-02-07 08:05:03 +0000567 M48t59State *NVRAM = opaque;
bellard819385c2005-10-30 16:58:32 +0000568 uint32_t retval;
bellarde1bb04f2004-06-21 16:49:53 +0000569
bellard819385c2005-10-30 16:58:32 +0000570 retval = m48t59_read(NVRAM, addr) << 24;
571 retval |= m48t59_read(NVRAM, addr + 1) << 16;
572 retval |= m48t59_read(NVRAM, addr + 2) << 8;
573 retval |= m48t59_read(NVRAM, addr + 3);
bellarde1bb04f2004-06-21 16:49:53 +0000574 return retval;
575}
576
Avi Kivity5a31cd62011-11-13 12:16:07 +0200577static const MemoryRegionOps nvram_ops = {
578 .old_mmio = {
579 .read = { nvram_readb, nvram_readw, nvram_readl, },
580 .write = { nvram_writeb, nvram_writew, nvram_writel, },
581 },
582 .endianness = DEVICE_NATIVE_ENDIAN,
bellarde1bb04f2004-06-21 16:49:53 +0000583};
bellard819385c2005-10-30 16:58:32 +0000584
Juan Quintelafd484ae2010-12-02 00:16:33 +0100585static const VMStateDescription vmstate_m48t59 = {
586 .name = "m48t59",
587 .version_id = 1,
588 .minimum_version_id = 1,
589 .minimum_version_id_old = 1,
590 .fields = (VMStateField[]) {
591 VMSTATE_UINT8(lock, M48t59State),
592 VMSTATE_UINT16(addr, M48t59State),
593 VMSTATE_VBUFFER_UINT32(buffer, M48t59State, 0, NULL, 0, size),
594 VMSTATE_END_OF_LIST()
595 }
596};
blueswir13ccacc42007-04-14 13:01:31 +0000597
Blue Swirl43a34702010-02-07 08:05:03 +0000598static void m48t59_reset_common(M48t59State *NVRAM)
blueswir13ccacc42007-04-14 13:01:31 +0000599{
blueswir16e6b7362008-12-28 18:27:10 +0000600 NVRAM->addr = 0;
601 NVRAM->lock = 0;
blueswir13ccacc42007-04-14 13:01:31 +0000602 if (NVRAM->alrm_timer != NULL)
603 qemu_del_timer(NVRAM->alrm_timer);
604
605 if (NVRAM->wd_timer != NULL)
606 qemu_del_timer(NVRAM->wd_timer);
607}
608
Blue Swirl285e4682009-10-24 19:22:56 +0000609static void m48t59_reset_isa(DeviceState *d)
610{
611 M48t59ISAState *isa = container_of(d, M48t59ISAState, busdev.qdev);
Blue Swirl43a34702010-02-07 08:05:03 +0000612 M48t59State *NVRAM = &isa->state;
Blue Swirl285e4682009-10-24 19:22:56 +0000613
614 m48t59_reset_common(NVRAM);
615}
616
617static void m48t59_reset_sysbus(DeviceState *d)
618{
619 M48t59SysBusState *sys = container_of(d, M48t59SysBusState, busdev.qdev);
Blue Swirl43a34702010-02-07 08:05:03 +0000620 M48t59State *NVRAM = &sys->state;
Blue Swirl285e4682009-10-24 19:22:56 +0000621
622 m48t59_reset_common(NVRAM);
623}
624
Richard Henderson9936d6e2011-08-15 15:33:40 -0700625static const MemoryRegionOps m48t59_io_ops = {
Alexander Graf087bd052012-10-08 13:19:48 +0200626 .read = NVRAM_readb,
627 .write = NVRAM_writeb,
628 .impl = {
629 .min_access_size = 1,
630 .max_access_size = 1,
631 },
632 .endianness = DEVICE_LITTLE_ENDIAN,
Richard Henderson9936d6e2011-08-15 15:33:40 -0700633};
634
bellarda541f292004-04-12 20:39:29 +0000635/* Initialisation routine */
Avi Kivitya8170e52012-10-23 12:30:10 +0200636M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200637 uint32_t io_base, uint16_t size, int model)
bellarda541f292004-04-12 20:39:29 +0000638{
Blue Swirld27cf0a2009-07-12 20:07:07 +0000639 DeviceState *dev;
640 SysBusDevice *s;
Blue Swirlf80237d2009-09-14 15:33:28 +0000641 M48t59SysBusState *d;
Hervé Poussineau51f9b842011-01-02 19:44:49 +0100642 M48t59State *state;
bellarda541f292004-04-12 20:39:29 +0000643
Blue Swirld27cf0a2009-07-12 20:07:07 +0000644 dev = qdev_create(NULL, "m48t59");
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200645 qdev_prop_set_uint32(dev, "model", model);
Gerd Hoffmannee6847d2009-07-15 13:43:31 +0200646 qdev_prop_set_uint32(dev, "size", size);
647 qdev_prop_set_uint32(dev, "io_base", io_base);
Markus Armbrustere23a1b32009-10-07 01:15:58 +0200648 qdev_init_nofail(dev);
Blue Swirld27cf0a2009-07-12 20:07:07 +0000649 s = sysbus_from_qdev(dev);
Hervé Poussineau51f9b842011-01-02 19:44:49 +0100650 d = FROM_SYSBUS(M48t59SysBusState, s);
651 state = &d->state;
Blue Swirld27cf0a2009-07-12 20:07:07 +0000652 sysbus_connect_irq(s, 0, IRQ);
Alexander Graf087bd052012-10-08 13:19:48 +0200653 memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
bellard819385c2005-10-30 16:58:32 +0000654 if (io_base != 0) {
Alexander Graf087bd052012-10-08 13:19:48 +0200655 memory_region_add_subregion(get_system_io(), io_base, &d->io);
bellard819385c2005-10-30 16:58:32 +0000656 }
bellarde1bb04f2004-06-21 16:49:53 +0000657 if (mem_base != 0) {
Blue Swirld27cf0a2009-07-12 20:07:07 +0000658 sysbus_mmio_map(s, 0, mem_base);
bellarde1bb04f2004-06-21 16:49:53 +0000659 }
Blue Swirld27cf0a2009-07-12 20:07:07 +0000660
Hervé Poussineau51f9b842011-01-02 19:44:49 +0100661 return state;
Blue Swirld27cf0a2009-07-12 20:07:07 +0000662}
663
Hervé Poussineau48a18b32011-12-15 22:09:51 +0100664M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200665 int model)
Blue Swirld27cf0a2009-07-12 20:07:07 +0000666{
Blue Swirlf80237d2009-09-14 15:33:28 +0000667 M48t59ISAState *d;
668 ISADevice *dev;
Blue Swirl43a34702010-02-07 08:05:03 +0000669 M48t59State *s;
Blue Swirld27cf0a2009-07-12 20:07:07 +0000670
Hervé Poussineau48a18b32011-12-15 22:09:51 +0100671 dev = isa_create(bus, "m48t59_isa");
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200672 qdev_prop_set_uint32(&dev->qdev, "model", model);
Blue Swirlf80237d2009-09-14 15:33:28 +0000673 qdev_prop_set_uint32(&dev->qdev, "size", size);
674 qdev_prop_set_uint32(&dev->qdev, "io_base", io_base);
Markus Armbrustere23a1b32009-10-07 01:15:58 +0200675 qdev_init_nofail(&dev->qdev);
Blue Swirlf80237d2009-09-14 15:33:28 +0000676 d = DO_UPCAST(M48t59ISAState, busdev, dev);
677 s = &d->state;
678
Richard Henderson9936d6e2011-08-15 15:33:40 -0700679 memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
Blue Swirlf80237d2009-09-14 15:33:28 +0000680 if (io_base != 0) {
Richard Henderson9936d6e2011-08-15 15:33:40 -0700681 isa_register_ioport(dev, &d->io, io_base);
Blue Swirlf80237d2009-09-14 15:33:28 +0000682 }
683
684 return s;
685}
686
Blue Swirl43a34702010-02-07 08:05:03 +0000687static void m48t59_init_common(M48t59State *s)
Blue Swirlf80237d2009-09-14 15:33:28 +0000688{
Anthony Liguori7267c092011-08-20 22:09:37 -0500689 s->buffer = g_malloc0(s->size);
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200690 if (s->model == 59) {
Paolo Bonzini1d849502012-01-20 13:05:00 +0100691 s->alrm_timer = qemu_new_timer_ns(rtc_clock, &alarm_cb, s);
Paolo Bonzini74475452011-03-11 16:47:48 +0100692 s->wd_timer = qemu_new_timer_ns(vm_clock, &watchdog_cb, s);
bellard819385c2005-10-30 16:58:32 +0000693 }
balrogf6503052008-02-17 11:42:19 +0000694 qemu_get_timedate(&s->alarm, 0);
bellard13ab5da2004-05-17 20:21:49 +0000695
Juan Quintelafd484ae2010-12-02 00:16:33 +0100696 vmstate_register(NULL, -1, &vmstate_m48t59, s);
Blue Swirlf80237d2009-09-14 15:33:28 +0000697}
698
699static int m48t59_init_isa1(ISADevice *dev)
700{
701 M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
Blue Swirl43a34702010-02-07 08:05:03 +0000702 M48t59State *s = &d->state;
Blue Swirlf80237d2009-09-14 15:33:28 +0000703
704 isa_init_irq(dev, &s->IRQ, 8);
705 m48t59_init_common(s);
706
Gerd Hoffmann81a322d2009-08-14 10:36:05 +0200707 return 0;
bellarda541f292004-04-12 20:39:29 +0000708}
Blue Swirld27cf0a2009-07-12 20:07:07 +0000709
Blue Swirlf80237d2009-09-14 15:33:28 +0000710static int m48t59_init1(SysBusDevice *dev)
711{
712 M48t59SysBusState *d = FROM_SYSBUS(M48t59SysBusState, dev);
Blue Swirl43a34702010-02-07 08:05:03 +0000713 M48t59State *s = &d->state;
Blue Swirlf80237d2009-09-14 15:33:28 +0000714
715 sysbus_init_irq(dev, &s->IRQ);
716
Avi Kivity5a31cd62011-11-13 12:16:07 +0200717 memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size);
Avi Kivity750ecd42011-11-27 11:38:10 +0200718 sysbus_init_mmio(dev, &s->iomem);
Blue Swirlf80237d2009-09-14 15:33:28 +0000719 m48t59_init_common(s);
720
721 return 0;
722}
723
Anthony Liguori39bffca2011-12-07 21:34:16 -0600724static Property m48t59_isa_properties[] = {
725 DEFINE_PROP_UINT32("size", M48t59ISAState, state.size, -1),
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200726 DEFINE_PROP_UINT32("model", M48t59ISAState, state.model, -1),
Anthony Liguori39bffca2011-12-07 21:34:16 -0600727 DEFINE_PROP_HEX32( "io_base", M48t59ISAState, state.io_base, 0),
728 DEFINE_PROP_END_OF_LIST(),
729};
730
Anthony Liguori8f04ee02011-12-04 11:52:49 -0600731static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
732{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600733 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori8f04ee02011-12-04 11:52:49 -0600734 ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
735 ic->init = m48t59_init_isa1;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600736 dc->no_user = 1;
737 dc->reset = m48t59_reset_isa;
738 dc->props = m48t59_isa_properties;
Anthony Liguori8f04ee02011-12-04 11:52:49 -0600739}
740
Anthony Liguori39bffca2011-12-07 21:34:16 -0600741static TypeInfo m48t59_isa_info = {
742 .name = "m48t59_isa",
743 .parent = TYPE_ISA_DEVICE,
744 .instance_size = sizeof(M48t59ISAState),
745 .class_init = m48t59_init_class_isa1,
Blue Swirlf80237d2009-09-14 15:33:28 +0000746};
747
Anthony Liguori999e12b2012-01-24 13:12:29 -0600748static Property m48t59_properties[] = {
749 DEFINE_PROP_UINT32("size", M48t59SysBusState, state.size, -1),
Paolo Bonzini7bc30182012-05-23 19:25:34 +0200750 DEFINE_PROP_UINT32("model", M48t59SysBusState, state.model, -1),
Anthony Liguori999e12b2012-01-24 13:12:29 -0600751 DEFINE_PROP_HEX32( "io_base", M48t59SysBusState, state.io_base, 0),
752 DEFINE_PROP_END_OF_LIST(),
753};
754
755static void m48t59_class_init(ObjectClass *klass, void *data)
756{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600757 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori999e12b2012-01-24 13:12:29 -0600758 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
759
760 k->init = m48t59_init1;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600761 dc->reset = m48t59_reset_sysbus;
762 dc->props = m48t59_properties;
Anthony Liguori999e12b2012-01-24 13:12:29 -0600763}
764
Anthony Liguori39bffca2011-12-07 21:34:16 -0600765static TypeInfo m48t59_info = {
766 .name = "m48t59",
767 .parent = TYPE_SYS_BUS_DEVICE,
768 .instance_size = sizeof(M48t59SysBusState),
769 .class_init = m48t59_class_init,
Gerd Hoffmannee6847d2009-07-15 13:43:31 +0200770};
771
Andreas Färber83f7d432012-02-09 15:20:55 +0100772static void m48t59_register_types(void)
Blue Swirld27cf0a2009-07-12 20:07:07 +0000773{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600774 type_register_static(&m48t59_info);
775 type_register_static(&m48t59_isa_info);
Blue Swirld27cf0a2009-07-12 20:07:07 +0000776}
777
Andreas Färber83f7d432012-02-09 15:20:55 +0100778type_init(m48t59_register_types)