2 * OneNAND flash memories emulation.
4 * Copyright (C) 2008 Nokia Corporation
5 * Written by Andrzej Zaborowski <andrew@openedhand.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 or
10 * (at your option) version 3 of the License.
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.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
22 #include "qemu-common.h"
24 #include "hw/block/flash.h"
26 #include "sysemu/block-backend.h"
27 #include "sysemu/blockdev.h"
28 #include "exec/memory.h"
29 #include "exec/address-spaces.h"
30 #include "hw/sysbus.h"
31 #include "qemu/error-report.h"
33 /* 11 for 2kB-page OneNAND ("2nd generation") and 10 for 1kB-page chips */
37 #define BLOCK_SHIFT (PAGE_SHIFT + 6)
39 #define TYPE_ONE_NAND "onenand"
40 #define ONE_NAND(obj) OBJECT_CHECK(OneNANDState, (obj), TYPE_ONE_NAND)
42 typedef struct OneNANDState
{
43 SysBusDevice parent_obj
;
55 BlockBackend
*blk_cur
;
60 MemoryRegion mapped_ram
;
61 uint8_t current_direction
;
65 MemoryRegion container
;
91 ONEN_BUF_DEST_BLOCK
= 2,
92 ONEN_BUF_DEST_PAGE
= 3,
97 ONEN_ERR_CMD
= 1 << 10,
98 ONEN_ERR_ERASE
= 1 << 11,
99 ONEN_ERR_PROG
= 1 << 12,
100 ONEN_ERR_LOAD
= 1 << 13,
104 ONEN_INT_RESET
= 1 << 4,
105 ONEN_INT_ERASE
= 1 << 5,
106 ONEN_INT_PROG
= 1 << 6,
107 ONEN_INT_LOAD
= 1 << 7,
112 ONEN_LOCK_LOCKTIGHTEN
= 1 << 0,
113 ONEN_LOCK_LOCKED
= 1 << 1,
114 ONEN_LOCK_UNLOCKED
= 1 << 2,
117 static void onenand_mem_setup(OneNANDState
*s
)
119 /* XXX: We should use IO_MEM_ROMD but we broke it earlier...
120 * Both 0x0000 ... 0x01ff and 0x8000 ... 0x800f can be used to
121 * write boot commands. Also take note of the BWPS bit. */
122 memory_region_init(&s
->container
, OBJECT(s
), "onenand",
123 0x10000 << s
->shift
);
124 memory_region_add_subregion(&s
->container
, 0, &s
->iomem
);
125 memory_region_init_alias(&s
->mapped_ram
, OBJECT(s
), "onenand-mapped-ram",
126 &s
->ram
, 0x0200 << s
->shift
,
128 memory_region_add_subregion_overlap(&s
->container
,
134 static void onenand_intr_update(OneNANDState
*s
)
136 qemu_set_irq(s
->intr
, ((s
->intstatus
>> 15) ^ (~s
->config
[0] >> 6)) & 1);
139 static void onenand_pre_save(void *opaque
)
141 OneNANDState
*s
= opaque
;
142 if (s
->current
== s
->otp
) {
143 s
->current_direction
= 1;
144 } else if (s
->current
== s
->image
) {
145 s
->current_direction
= 2;
147 s
->current_direction
= 0;
151 static int onenand_post_load(void *opaque
, int version_id
)
153 OneNANDState
*s
= opaque
;
154 switch (s
->current_direction
) {
161 s
->current
= s
->image
;
166 onenand_intr_update(s
);
170 static const VMStateDescription vmstate_onenand
= {
173 .minimum_version_id
= 1,
174 .pre_save
= onenand_pre_save
,
175 .post_load
= onenand_post_load
,
176 .fields
= (VMStateField
[]) {
177 VMSTATE_UINT8(current_direction
, OneNANDState
),
178 VMSTATE_INT32(cycle
, OneNANDState
),
179 VMSTATE_INT32(otpmode
, OneNANDState
),
180 VMSTATE_UINT16_ARRAY(addr
, OneNANDState
, 8),
181 VMSTATE_UINT16_ARRAY(unladdr
, OneNANDState
, 8),
182 VMSTATE_INT32(bufaddr
, OneNANDState
),
183 VMSTATE_INT32(count
, OneNANDState
),
184 VMSTATE_UINT16(command
, OneNANDState
),
185 VMSTATE_UINT16_ARRAY(config
, OneNANDState
, 2),
186 VMSTATE_UINT16(status
, OneNANDState
),
187 VMSTATE_UINT16(intstatus
, OneNANDState
),
188 VMSTATE_UINT16(wpstatus
, OneNANDState
),
189 VMSTATE_INT32(secs_cur
, OneNANDState
),
190 VMSTATE_PARTIAL_VBUFFER(blockwp
, OneNANDState
, blocks
),
191 VMSTATE_UINT8(ecc
.cp
, OneNANDState
),
192 VMSTATE_UINT16_ARRAY(ecc
.lp
, OneNANDState
, 2),
193 VMSTATE_UINT16(ecc
.count
, OneNANDState
),
194 VMSTATE_BUFFER_POINTER_UNSAFE(otp
, OneNANDState
, 0,
195 ((64 + 2) << PAGE_SHIFT
)),
196 VMSTATE_END_OF_LIST()
200 /* Hot reset (Reset OneNAND command) or warm reset (RP pin low) */
201 static void onenand_reset(OneNANDState
*s
, int cold
)
203 memset(&s
->addr
, 0, sizeof(s
->addr
));
207 s
->config
[0] = 0x40c0;
208 s
->config
[1] = 0x0000;
209 onenand_intr_update(s
);
210 qemu_irq_raise(s
->rdy
);
212 s
->intstatus
= cold
? 0x8080 : 0x8010;
215 s
->wpstatus
= 0x0002;
219 s
->current
= s
->image
;
220 s
->secs_cur
= s
->secs
;
223 /* Lock the whole flash */
224 memset(s
->blockwp
, ONEN_LOCK_LOCKED
, s
->blocks
);
226 if (s
->blk_cur
&& blk_read(s
->blk_cur
, 0, s
->boot
[0], 8) < 0) {
227 hw_error("%s: Loading the BootRAM failed.\n", __func__
);
232 static void onenand_system_reset(DeviceState
*dev
)
234 OneNANDState
*s
= ONE_NAND(dev
);
239 static inline int onenand_load_main(OneNANDState
*s
, int sec
, int secn
,
243 return blk_read(s
->blk_cur
, sec
, dest
, secn
) < 0;
244 } else if (sec
+ secn
> s
->secs_cur
) {
248 memcpy(dest
, s
->current
+ (sec
<< 9), secn
<< 9);
253 static inline int onenand_prog_main(OneNANDState
*s
, int sec
, int secn
,
259 uint32_t size
= (uint32_t)secn
* 512;
260 const uint8_t *sp
= (const uint8_t *)src
;
264 if (!dp
|| blk_read(s
->blk_cur
, sec
, dp
, secn
) < 0) {
268 if (sec
+ secn
> s
->secs_cur
) {
271 dp
= (uint8_t *)s
->current
+ (sec
<< 9);
276 for (i
= 0; i
< size
; i
++) {
280 result
= blk_write(s
->blk_cur
, sec
, dp
, secn
) < 0;
283 if (dp
&& s
->blk_cur
) {
291 static inline int onenand_load_spare(OneNANDState
*s
, int sec
, int secn
,
297 if (blk_read(s
->blk_cur
, s
->secs_cur
+ (sec
>> 5), buf
, 1) < 0) {
300 memcpy(dest
, buf
+ ((sec
& 31) << 4), secn
<< 4);
301 } else if (sec
+ secn
> s
->secs_cur
) {
304 memcpy(dest
, s
->current
+ (s
->secs_cur
<< 9) + (sec
<< 4), secn
<< 4);
310 static inline int onenand_prog_spare(OneNANDState
*s
, int sec
, int secn
,
315 const uint8_t *sp
= (const uint8_t *)src
;
316 uint8_t *dp
= 0, *dpp
= 0;
320 || blk_read(s
->blk_cur
, s
->secs_cur
+ (sec
>> 5), dp
, 1) < 0) {
323 dpp
= dp
+ ((sec
& 31) << 4);
326 if (sec
+ secn
> s
->secs_cur
) {
329 dpp
= s
->current
+ (s
->secs_cur
<< 9) + (sec
<< 4);
334 for (i
= 0; i
< (secn
<< 4); i
++) {
338 result
= blk_write(s
->blk_cur
, s
->secs_cur
+ (sec
>> 5),
347 static inline int onenand_erase(OneNANDState
*s
, int sec
, int num
)
349 uint8_t *blankbuf
, *tmpbuf
;
351 blankbuf
= g_malloc(512);
352 tmpbuf
= g_malloc(512);
353 memset(blankbuf
, 0xff, 512);
354 for (; num
> 0; num
--, sec
++) {
356 int erasesec
= s
->secs_cur
+ (sec
>> 5);
357 if (blk_write(s
->blk_cur
, sec
, blankbuf
, 1) < 0) {
360 if (blk_read(s
->blk_cur
, erasesec
, tmpbuf
, 1) < 0) {
363 memcpy(tmpbuf
+ ((sec
& 31) << 4), blankbuf
, 1 << 4);
364 if (blk_write(s
->blk_cur
, erasesec
, tmpbuf
, 1) < 0) {
368 if (sec
+ 1 > s
->secs_cur
) {
371 memcpy(s
->current
+ (sec
<< 9), blankbuf
, 512);
372 memcpy(s
->current
+ (s
->secs_cur
<< 9) + (sec
<< 4),
387 static void onenand_command(OneNANDState
*s
)
392 #define SETADDR(block, page) \
393 sec = (s->addr[page] & 3) + \
394 ((((s->addr[page] >> 2) & 0x3f) + \
395 (((s->addr[block] & 0xfff) | \
396 (s->addr[block] >> 15 ? \
397 s->density_mask : 0)) << 6)) << (PAGE_SHIFT - 9));
399 buf = (s->bufaddr & 8) ? \
400 s->data[(s->bufaddr >> 2) & 1][0] : s->boot[0]; \
401 buf += (s->bufaddr & 3) << 9;
403 buf = (s->bufaddr & 8) ? \
404 s->data[(s->bufaddr >> 2) & 1][1] : s->boot[1]; \
405 buf += (s->bufaddr & 3) << 4;
407 switch (s
->command
) {
408 case 0x00: /* Load single/multiple sector data unit into buffer */
409 SETADDR(ONEN_BUF_BLOCK
, ONEN_BUF_PAGE
)
412 if (onenand_load_main(s
, sec
, s
->count
, buf
))
413 s
->status
|= ONEN_ERR_CMD
| ONEN_ERR_LOAD
;
417 if (onenand_load_spare(s
, sec
, s
->count
, buf
))
418 s
->status
|= ONEN_ERR_CMD
| ONEN_ERR_LOAD
;
421 /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
422 * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
423 * then we need two split the read/write into two chunks.
425 s
->intstatus
|= ONEN_INT
| ONEN_INT_LOAD
;
427 case 0x13: /* Load single/multiple spare sector into buffer */
428 SETADDR(ONEN_BUF_BLOCK
, ONEN_BUF_PAGE
)
431 if (onenand_load_spare(s
, sec
, s
->count
, buf
))
432 s
->status
|= ONEN_ERR_CMD
| ONEN_ERR_LOAD
;
434 /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
435 * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
436 * then we need two split the read/write into two chunks.
438 s
->intstatus
|= ONEN_INT
| ONEN_INT_LOAD
;
440 case 0x80: /* Program single/multiple sector data unit from buffer */
441 SETADDR(ONEN_BUF_BLOCK
, ONEN_BUF_PAGE
)
444 if (onenand_prog_main(s
, sec
, s
->count
, buf
))
445 s
->status
|= ONEN_ERR_CMD
| ONEN_ERR_PROG
;
449 if (onenand_prog_spare(s
, sec
, s
->count
, buf
))
450 s
->status
|= ONEN_ERR_CMD
| ONEN_ERR_PROG
;
453 /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
454 * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
455 * then we need two split the read/write into two chunks.
457 s
->intstatus
|= ONEN_INT
| ONEN_INT_PROG
;
459 case 0x1a: /* Program single/multiple spare area sector from buffer */
460 SETADDR(ONEN_BUF_BLOCK
, ONEN_BUF_PAGE
)
463 if (onenand_prog_spare(s
, sec
, s
->count
, buf
))
464 s
->status
|= ONEN_ERR_CMD
| ONEN_ERR_PROG
;
466 /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
467 * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
468 * then we need two split the read/write into two chunks.
470 s
->intstatus
|= ONEN_INT
| ONEN_INT_PROG
;
472 case 0x1b: /* Copy-back program */
475 SETADDR(ONEN_BUF_BLOCK
, ONEN_BUF_PAGE
)
476 if (onenand_load_main(s
, sec
, s
->count
, buf
))
477 s
->status
|= ONEN_ERR_CMD
| ONEN_ERR_PROG
;
479 SETADDR(ONEN_BUF_DEST_BLOCK
, ONEN_BUF_DEST_PAGE
)
480 if (onenand_prog_main(s
, sec
, s
->count
, buf
))
481 s
->status
|= ONEN_ERR_CMD
| ONEN_ERR_PROG
;
483 /* TODO: spare areas */
485 s
->intstatus
|= ONEN_INT
| ONEN_INT_PROG
;
488 case 0x23: /* Unlock NAND array block(s) */
489 s
->intstatus
|= ONEN_INT
;
491 /* XXX the previous (?) area should be locked automatically */
492 for (b
= s
->unladdr
[0]; b
<= s
->unladdr
[1]; b
++) {
493 if (b
>= s
->blocks
) {
494 s
->status
|= ONEN_ERR_CMD
;
497 if (s
->blockwp
[b
] == ONEN_LOCK_LOCKTIGHTEN
)
500 s
->wpstatus
= s
->blockwp
[b
] = ONEN_LOCK_UNLOCKED
;
503 case 0x27: /* Unlock All NAND array blocks */
504 s
->intstatus
|= ONEN_INT
;
506 for (b
= 0; b
< s
->blocks
; b
++) {
507 if (b
>= s
->blocks
) {
508 s
->status
|= ONEN_ERR_CMD
;
511 if (s
->blockwp
[b
] == ONEN_LOCK_LOCKTIGHTEN
)
514 s
->wpstatus
= s
->blockwp
[b
] = ONEN_LOCK_UNLOCKED
;
518 case 0x2a: /* Lock NAND array block(s) */
519 s
->intstatus
|= ONEN_INT
;
521 for (b
= s
->unladdr
[0]; b
<= s
->unladdr
[1]; b
++) {
522 if (b
>= s
->blocks
) {
523 s
->status
|= ONEN_ERR_CMD
;
526 if (s
->blockwp
[b
] == ONEN_LOCK_LOCKTIGHTEN
)
529 s
->wpstatus
= s
->blockwp
[b
] = ONEN_LOCK_LOCKED
;
532 case 0x2c: /* Lock-tight NAND array block(s) */
533 s
->intstatus
|= ONEN_INT
;
535 for (b
= s
->unladdr
[0]; b
<= s
->unladdr
[1]; b
++) {
536 if (b
>= s
->blocks
) {
537 s
->status
|= ONEN_ERR_CMD
;
540 if (s
->blockwp
[b
] == ONEN_LOCK_UNLOCKED
)
543 s
->wpstatus
= s
->blockwp
[b
] = ONEN_LOCK_LOCKTIGHTEN
;
547 case 0x71: /* Erase-Verify-Read */
548 s
->intstatus
|= ONEN_INT
;
550 case 0x95: /* Multi-block erase */
551 qemu_irq_pulse(s
->intr
);
553 case 0x94: /* Block erase */
554 sec
= ((s
->addr
[ONEN_BUF_BLOCK
] & 0xfff) |
555 (s
->addr
[ONEN_BUF_BLOCK
] >> 15 ? s
->density_mask
: 0))
556 << (BLOCK_SHIFT
- 9);
557 if (onenand_erase(s
, sec
, 1 << (BLOCK_SHIFT
- 9)))
558 s
->status
|= ONEN_ERR_CMD
| ONEN_ERR_ERASE
;
560 s
->intstatus
|= ONEN_INT
| ONEN_INT_ERASE
;
562 case 0xb0: /* Erase suspend */
564 case 0x30: /* Erase resume */
565 s
->intstatus
|= ONEN_INT
| ONEN_INT_ERASE
;
568 case 0xf0: /* Reset NAND Flash core */
571 case 0xf3: /* Reset OneNAND */
575 case 0x65: /* OTP Access */
576 s
->intstatus
|= ONEN_INT
;
579 s
->secs_cur
= 1 << (BLOCK_SHIFT
- 9);
580 s
->addr
[ONEN_BUF_BLOCK
] = 0;
585 s
->status
|= ONEN_ERR_CMD
;
586 s
->intstatus
|= ONEN_INT
;
587 fprintf(stderr
, "%s: unknown OneNAND command %x\n",
588 __func__
, s
->command
);
591 onenand_intr_update(s
);
594 static uint64_t onenand_read(void *opaque
, hwaddr addr
,
597 OneNANDState
*s
= (OneNANDState
*) opaque
;
598 int offset
= addr
>> s
->shift
;
601 case 0x0000 ... 0xc000:
602 return lduw_le_p(s
->boot
[0] + addr
);
604 case 0xf000: /* Manufacturer ID */
606 case 0xf001: /* Device ID */
608 case 0xf002: /* Version ID */
610 /* TODO: get the following values from a real chip! */
611 case 0xf003: /* Data Buffer size */
612 return 1 << PAGE_SHIFT
;
613 case 0xf004: /* Boot Buffer size */
615 case 0xf005: /* Amount of buffers */
617 case 0xf006: /* Technology */
620 case 0xf100 ... 0xf107: /* Start addresses */
621 return s
->addr
[offset
- 0xf100];
623 case 0xf200: /* Start buffer */
624 return (s
->bufaddr
<< 8) | ((s
->count
- 1) & (1 << (PAGE_SHIFT
- 10)));
626 case 0xf220: /* Command */
628 case 0xf221: /* System Configuration 1 */
629 return s
->config
[0] & 0xffe0;
630 case 0xf222: /* System Configuration 2 */
633 case 0xf240: /* Controller Status */
635 case 0xf241: /* Interrupt */
637 case 0xf24c: /* Unlock Start Block Address */
638 return s
->unladdr
[0];
639 case 0xf24d: /* Unlock End Block Address */
640 return s
->unladdr
[1];
641 case 0xf24e: /* Write Protection Status */
644 case 0xff00: /* ECC Status */
646 case 0xff01: /* ECC Result of main area data */
647 case 0xff02: /* ECC Result of spare area data */
648 case 0xff03: /* ECC Result of main area data */
649 case 0xff04: /* ECC Result of spare area data */
650 hw_error("%s: imeplement ECC\n", __FUNCTION__
);
654 fprintf(stderr
, "%s: unknown OneNAND register %x\n",
655 __FUNCTION__
, offset
);
659 static void onenand_write(void *opaque
, hwaddr addr
,
660 uint64_t value
, unsigned size
)
662 OneNANDState
*s
= (OneNANDState
*) opaque
;
663 int offset
= addr
>> s
->shift
;
667 case 0x0000 ... 0x01ff:
668 case 0x8000 ... 0x800f:
672 if (value
== 0x0000) {
673 SETADDR(ONEN_BUF_BLOCK
, ONEN_BUF_PAGE
)
674 onenand_load_main(s
, sec
,
675 1 << (PAGE_SHIFT
- 9), s
->data
[0][0]);
676 s
->addr
[ONEN_BUF_PAGE
] += 4;
677 s
->addr
[ONEN_BUF_PAGE
] &= 0xff;
683 case 0x00f0: /* Reset OneNAND */
687 case 0x00e0: /* Load Data into Buffer */
691 case 0x0090: /* Read Identification Data */
692 memset(s
->boot
[0], 0, 3 << s
->shift
);
693 s
->boot
[0][0 << s
->shift
] = s
->id
.man
& 0xff;
694 s
->boot
[0][1 << s
->shift
] = s
->id
.dev
& 0xff;
695 s
->boot
[0][2 << s
->shift
] = s
->wpstatus
& 0xff;
699 fprintf(stderr
, "%s: unknown OneNAND boot command %"PRIx64
"\n",
700 __FUNCTION__
, value
);
704 case 0xf100 ... 0xf107: /* Start addresses */
705 s
->addr
[offset
- 0xf100] = value
;
708 case 0xf200: /* Start buffer */
709 s
->bufaddr
= (value
>> 8) & 0xf;
710 if (PAGE_SHIFT
== 11)
711 s
->count
= (value
& 3) ?: 4;
712 else if (PAGE_SHIFT
== 10)
713 s
->count
= (value
& 1) ?: 2;
716 case 0xf220: /* Command */
717 if (s
->intstatus
& (1 << 15))
722 case 0xf221: /* System Configuration 1 */
723 s
->config
[0] = value
;
724 onenand_intr_update(s
);
725 qemu_set_irq(s
->rdy
, (s
->config
[0] >> 7) & 1);
727 case 0xf222: /* System Configuration 2 */
728 s
->config
[1] = value
;
731 case 0xf241: /* Interrupt */
732 s
->intstatus
&= value
;
733 if ((1 << 15) & ~s
->intstatus
)
734 s
->status
&= ~(ONEN_ERR_CMD
| ONEN_ERR_ERASE
|
735 ONEN_ERR_PROG
| ONEN_ERR_LOAD
);
736 onenand_intr_update(s
);
738 case 0xf24c: /* Unlock Start Block Address */
739 s
->unladdr
[0] = value
& (s
->blocks
- 1);
740 /* For some reason we have to set the end address to by default
741 * be same as start because the software forgets to write anything
743 s
->unladdr
[1] = value
& (s
->blocks
- 1);
745 case 0xf24d: /* Unlock End Block Address */
746 s
->unladdr
[1] = value
& (s
->blocks
- 1);
750 fprintf(stderr
, "%s: unknown OneNAND register %x\n",
751 __FUNCTION__
, offset
);
755 static const MemoryRegionOps onenand_ops
= {
756 .read
= onenand_read
,
757 .write
= onenand_write
,
758 .endianness
= DEVICE_NATIVE_ENDIAN
,
761 static int onenand_initfn(SysBusDevice
*sbd
)
763 DeviceState
*dev
= DEVICE(sbd
);
764 OneNANDState
*s
= ONE_NAND(dev
);
765 uint32_t size
= 1 << (24 + ((s
->id
.dev
>> 4) & 7));
768 s
->base
= (hwaddr
)-1;
770 s
->blocks
= size
>> BLOCK_SHIFT
;
772 s
->blockwp
= g_malloc(s
->blocks
);
773 s
->density_mask
= (s
->id
.dev
& 0x08)
774 ? (1 << (6 + ((s
->id
.dev
>> 4) & 7))) : 0;
775 memory_region_init_io(&s
->iomem
, OBJECT(s
), &onenand_ops
, s
, "onenand",
776 0x10000 << s
->shift
);
778 s
->image
= memset(g_malloc(size
+ (size
>> 5)),
779 0xff, size
+ (size
>> 5));
781 if (blk_is_read_only(s
->blk
)) {
782 error_report("Can't use a read-only drive");
787 s
->otp
= memset(g_malloc((64 + 2) << PAGE_SHIFT
),
788 0xff, (64 + 2) << PAGE_SHIFT
);
789 memory_region_init_ram(&s
->ram
, OBJECT(s
), "onenand.ram",
790 0xc000 << s
->shift
, &error_fatal
);
791 vmstate_register_ram_global(&s
->ram
);
792 ram
= memory_region_get_ram_ptr(&s
->ram
);
793 s
->boot
[0] = ram
+ (0x0000 << s
->shift
);
794 s
->boot
[1] = ram
+ (0x8000 << s
->shift
);
795 s
->data
[0][0] = ram
+ ((0x0200 + (0 << (PAGE_SHIFT
- 1))) << s
->shift
);
796 s
->data
[0][1] = ram
+ ((0x8010 + (0 << (PAGE_SHIFT
- 6))) << s
->shift
);
797 s
->data
[1][0] = ram
+ ((0x0200 + (1 << (PAGE_SHIFT
- 1))) << s
->shift
);
798 s
->data
[1][1] = ram
+ ((0x8010 + (1 << (PAGE_SHIFT
- 6))) << s
->shift
);
799 onenand_mem_setup(s
);
800 sysbus_init_irq(sbd
, &s
->intr
);
801 sysbus_init_mmio(sbd
, &s
->container
);
802 vmstate_register(dev
,
803 ((s
->shift
& 0x7f) << 24)
804 | ((s
->id
.man
& 0xff) << 16)
805 | ((s
->id
.dev
& 0xff) << 8)
806 | (s
->id
.ver
& 0xff),
807 &vmstate_onenand
, s
);
811 static Property onenand_properties
[] = {
812 DEFINE_PROP_UINT16("manufacturer_id", OneNANDState
, id
.man
, 0),
813 DEFINE_PROP_UINT16("device_id", OneNANDState
, id
.dev
, 0),
814 DEFINE_PROP_UINT16("version_id", OneNANDState
, id
.ver
, 0),
815 DEFINE_PROP_INT32("shift", OneNANDState
, shift
, 0),
816 DEFINE_PROP_DRIVE("drive", OneNANDState
, blk
),
817 DEFINE_PROP_END_OF_LIST(),
820 static void onenand_class_init(ObjectClass
*klass
, void *data
)
822 DeviceClass
*dc
= DEVICE_CLASS(klass
);
823 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
825 k
->init
= onenand_initfn
;
826 dc
->reset
= onenand_system_reset
;
827 dc
->props
= onenand_properties
;
830 static const TypeInfo onenand_info
= {
831 .name
= TYPE_ONE_NAND
,
832 .parent
= TYPE_SYS_BUS_DEVICE
,
833 .instance_size
= sizeof(OneNANDState
),
834 .class_init
= onenand_class_init
,
837 static void onenand_register_types(void)
839 type_register_static(&onenand_info
);
842 void *onenand_raw_otp(DeviceState
*onenand_device
)
844 OneNANDState
*s
= ONE_NAND(onenand_device
);
849 type_init(onenand_register_types
)