2 * CFI parallel flash with AMD command set emulation
4 * Copyright (c) 2005 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 * For now, this code can emulate flashes of 1, 2 or 4 bytes width.
22 * Supported commands/modes are:
28 * - unlock bypass command
31 * It does not support flash interleaving.
32 * It does not implement software data protection as found in many real chips
33 * It does not implement erase suspend/resume commands
34 * It does not implement multiple sectors erase
37 #include "qemu/osdep.h"
39 #include "hw/block/block.h"
40 #include "hw/block/flash.h"
41 #include "qapi/error.h"
42 #include "qemu/timer.h"
43 #include "sysemu/block-backend.h"
44 #include "qemu/host-utils.h"
45 #include "qemu/module.h"
46 #include "hw/sysbus.h"
49 #define PFLASH_DEBUG false
50 #define DPRINTF(fmt, ...) \
53 fprintf(stderr, "PFLASH: " fmt, ## __VA_ARGS__); \
57 #define PFLASH_LAZY_ROMD_THRESHOLD 42
60 * The size of the cfi_table indirectly depends on this and the start of the
61 * PRI table directly depends on it. 4 is the maximum size (and also what
62 * seems common) without changing the PRT table address.
64 #define PFLASH_MAX_ERASE_REGIONS 4
66 /* Special write cycles for CFI queries. */
73 SysBusDevice parent_obj
;
77 uint32_t uniform_nb_blocs
;
78 uint32_t uniform_sector_len
;
79 uint32_t nb_blocs
[PFLASH_MAX_ERASE_REGIONS
];
80 uint32_t sector_len
[PFLASH_MAX_ERASE_REGIONS
];
85 int wcycle
; /* if 0, the flash is read normally */
90 /* FIXME: implement array device properties */
95 uint16_t unlock_addr0
;
96 uint16_t unlock_addr1
;
97 uint8_t cfi_table
[0x4d];
99 /* The device replicates the flash memory across its memory space. Emulate
100 * that by having a container (.mem) filled with an array of aliases
101 * (.mem_mappings) pointing to the flash memory (.orig_mem).
104 MemoryRegion
*mem_mappings
; /* array; one per mapping */
105 MemoryRegion orig_mem
;
107 int read_counter
; /* used for lazy switch-back to rom mode */
113 * Toggle status bit DQ7.
115 static inline void toggle_dq7(PFlashCFI02
*pfl
)
121 * Set status bit DQ7 to bit 7 of value.
123 static inline void set_dq7(PFlashCFI02
*pfl
, uint8_t value
)
126 pfl
->status
|= value
& 0x80;
130 * Toggle status bit DQ6.
132 static inline void toggle_dq6(PFlashCFI02
*pfl
)
138 * Set up replicated mappings of the same region.
140 static void pflash_setup_mappings(PFlashCFI02
*pfl
)
143 hwaddr size
= memory_region_size(&pfl
->orig_mem
);
145 memory_region_init(&pfl
->mem
, OBJECT(pfl
), "pflash", pfl
->mappings
* size
);
146 pfl
->mem_mappings
= g_new(MemoryRegion
, pfl
->mappings
);
147 for (i
= 0; i
< pfl
->mappings
; ++i
) {
148 memory_region_init_alias(&pfl
->mem_mappings
[i
], OBJECT(pfl
),
149 "pflash-alias", &pfl
->orig_mem
, 0, size
);
150 memory_region_add_subregion(&pfl
->mem
, i
* size
, &pfl
->mem_mappings
[i
]);
154 static void pflash_register_memory(PFlashCFI02
*pfl
, int rom_mode
)
156 memory_region_rom_device_set_romd(&pfl
->orig_mem
, rom_mode
);
157 pfl
->rom_mode
= rom_mode
;
160 static void pflash_timer (void *opaque
)
162 PFlashCFI02
*pfl
= opaque
;
164 trace_pflash_timer_expired(pfl
->cmd
);
170 pflash_register_memory(pfl
, 1);
177 * Read data from flash.
179 static uint64_t pflash_data_read(PFlashCFI02
*pfl
, hwaddr offset
,
182 uint8_t *p
= (uint8_t *)pfl
->storage
+ offset
;
183 uint64_t ret
= pfl
->be
? ldn_be_p(p
, width
) : ldn_le_p(p
, width
);
184 trace_pflash_data_read(offset
, width
<< 1, ret
);
189 * offset should be a byte offset of the QEMU device and _not_ a device
192 static uint32_t pflash_sector_len(PFlashCFI02
*pfl
, hwaddr offset
)
194 assert(offset
< pfl
->chip_len
);
195 int nb_regions
= pfl
->cfi_table
[0x2C];
197 for (int i
= 0; i
< nb_regions
; ++i
) {
198 uint64_t region_size
= (uint64_t)pfl
->nb_blocs
[i
] * pfl
->sector_len
[i
];
199 if (addr
<= offset
&& offset
< addr
+ region_size
) {
200 return pfl
->sector_len
[i
];
207 static uint64_t pflash_read(void *opaque
, hwaddr offset
, unsigned int width
)
209 PFlashCFI02
*pfl
= opaque
;
214 /* Lazy reset to ROMD mode after a certain amount of read accesses */
215 if (!pfl
->rom_mode
&& pfl
->wcycle
== 0 &&
216 ++pfl
->read_counter
> PFLASH_LAZY_ROMD_THRESHOLD
) {
217 pflash_register_memory(pfl
, 1);
219 offset
&= pfl
->chip_len
- 1;
220 boff
= offset
& 0xFF;
221 if (pfl
->width
== 2) {
223 } else if (pfl
->width
== 4) {
228 /* This should never happen : reset state & treat it as a read*/
229 DPRINTF("%s: unknown command state: %x\n", __func__
, pfl
->cmd
);
232 /* fall through to the read code */
234 /* We accept reads during second unlock sequence... */
236 /* Flash area read */
237 ret
= pflash_data_read(pfl
, offset
, width
);
244 ret
= boff
& 0x01 ? pfl
->ident1
: pfl
->ident0
;
247 ret
= 0x00; /* Pretend all sectors are unprotected */
251 ret
= boff
& 0x01 ? pfl
->ident3
: pfl
->ident2
;
252 if (ret
!= (uint8_t)-1) {
255 /* Fall through to data read. */
257 ret
= pflash_data_read(pfl
, offset
, width
);
259 DPRINTF("%s: ID " TARGET_FMT_plx
" %" PRIx64
"\n", __func__
, boff
, ret
);
264 /* Status register read */
266 DPRINTF("%s: status %" PRIx64
"\n", __func__
, ret
);
271 if (boff
< sizeof(pfl
->cfi_table
)) {
272 ret
= pfl
->cfi_table
[boff
];
278 trace_pflash_io_read(offset
, width
, width
<< 1, ret
, pfl
->cmd
, pfl
->wcycle
);
283 /* update flash content on disk */
284 static void pflash_update(PFlashCFI02
*pfl
, int offset
, int size
)
288 offset_end
= offset
+ size
;
289 /* widen to sector boundaries */
290 offset
= QEMU_ALIGN_DOWN(offset
, BDRV_SECTOR_SIZE
);
291 offset_end
= QEMU_ALIGN_UP(offset_end
, BDRV_SECTOR_SIZE
);
292 blk_pwrite(pfl
->blk
, offset
, pfl
->storage
+ offset
,
293 offset_end
- offset
, 0);
297 static void pflash_write(void *opaque
, hwaddr offset
, uint64_t value
,
300 PFlashCFI02
*pfl
= opaque
;
306 trace_pflash_io_write(offset
, width
, width
<< 1, value
, pfl
->wcycle
);
308 if (pfl
->cmd
!= 0xA0 && cmd
== 0xF0) {
311 offset
&= pfl
->chip_len
- 1;
314 if (pfl
->width
== 2) {
316 } else if (pfl
->width
== 4) {
319 /* Only the least-significant 11 bits are used in most cases. */
321 switch (pfl
->wcycle
) {
323 /* Set the device in I/O access mode if required */
325 pflash_register_memory(pfl
, 0);
326 pfl
->read_counter
= 0;
327 /* We're in read mode */
329 if (boff
== 0x55 && cmd
== 0x98) {
331 /* Enter CFI query mode */
332 pfl
->wcycle
= WCYCLE_CFI
;
336 if (boff
!= pfl
->unlock_addr0
|| cmd
!= 0xAA) {
337 DPRINTF("%s: unlock0 failed " TARGET_FMT_plx
" %02x %04x\n",
338 __func__
, boff
, cmd
, pfl
->unlock_addr0
);
341 DPRINTF("%s: unlock sequence started\n", __func__
);
344 /* We started an unlock sequence */
346 if (boff
!= pfl
->unlock_addr1
|| cmd
!= 0x55) {
347 DPRINTF("%s: unlock1 failed " TARGET_FMT_plx
" %02x\n", __func__
,
351 DPRINTF("%s: unlock sequence done\n", __func__
);
354 /* We finished an unlock sequence */
355 if (!pfl
->bypass
&& boff
!= pfl
->unlock_addr0
) {
356 DPRINTF("%s: command failed " TARGET_FMT_plx
" %02x\n", __func__
,
368 DPRINTF("%s: starting command %02x\n", __func__
, cmd
);
371 DPRINTF("%s: unknown command %02x\n", __func__
, cmd
);
378 /* We need another unlock sequence */
381 trace_pflash_data_write(offset
, width
<< 1, value
, 0);
383 p
= (uint8_t *)pfl
->storage
+ offset
;
385 uint64_t current
= ldn_be_p(p
, width
);
386 stn_be_p(p
, width
, current
& value
);
388 uint64_t current
= ldn_le_p(p
, width
);
389 stn_le_p(p
, width
, current
& value
);
391 pflash_update(pfl
, offset
, width
);
394 * While programming, status bit DQ7 should hold the opposite
395 * value from how it was programmed.
397 set_dq7(pfl
, ~value
);
398 /* Let's pretend write is immediate */
403 if (pfl
->bypass
&& cmd
== 0x00) {
404 /* Unlock bypass reset */
407 /* We can enter CFI query mode from autoselect mode */
408 if (boff
== 0x55 && cmd
== 0x98)
412 DPRINTF("%s: invalid write for command %02x\n",
419 /* Ignore writes while flash data write is occurring */
420 /* As we suppose write is immediate, this should never happen */
425 /* Should never happen */
426 DPRINTF("%s: invalid command state %02x (wc 4)\n",
434 if (boff
!= pfl
->unlock_addr0
) {
435 DPRINTF("%s: chip erase: invalid address " TARGET_FMT_plx
"\n",
440 DPRINTF("%s: start chip erase\n", __func__
);
442 memset(pfl
->storage
, 0xff, pfl
->chip_len
);
443 pflash_update(pfl
, 0, pfl
->chip_len
);
446 /* Let's wait 5 seconds before chip erase is done */
447 timer_mod(&pfl
->timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
448 (NANOSECONDS_PER_SECOND
* 5));
453 sector_len
= pflash_sector_len(pfl
, offset
);
454 offset
&= ~(sector_len
- 1);
455 DPRINTF("%s: start sector erase at %0*" PRIx64
"-%0*" PRIx64
"\n",
456 __func__
, pfl
->width
* 2, offset
,
457 pfl
->width
* 2, offset
+ sector_len
- 1);
459 memset(p
+ offset
, 0xff, sector_len
);
460 pflash_update(pfl
, offset
, sector_len
);
463 /* Let's wait 1/2 second before sector erase is done */
464 timer_mod(&pfl
->timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
465 (NANOSECONDS_PER_SECOND
/ 2));
468 DPRINTF("%s: invalid command %02x (wc 5)\n", __func__
, cmd
);
476 /* Ignore writes during chip erase */
479 /* Ignore writes during sector erase */
482 /* Should never happen */
483 DPRINTF("%s: invalid command state %02x (wc 6)\n",
488 /* Special values for CFI queries */
490 DPRINTF("%s: invalid write in CFI query mode\n", __func__
);
493 /* Should never happen */
494 DPRINTF("%s: invalid write state (wc 7)\n", __func__
);
503 trace_pflash_reset();
514 static const MemoryRegionOps pflash_cfi02_ops
= {
516 .write
= pflash_write
,
517 .valid
.min_access_size
= 1,
518 .valid
.max_access_size
= 4,
519 .endianness
= DEVICE_NATIVE_ENDIAN
,
522 static void pflash_cfi02_realize(DeviceState
*dev
, Error
**errp
)
524 PFlashCFI02
*pfl
= PFLASH_CFI02(dev
);
526 Error
*local_err
= NULL
;
528 if (pfl
->uniform_sector_len
== 0 && pfl
->sector_len
[0] == 0) {
529 error_setg(errp
, "attribute \"sector-length\" not specified or zero.");
532 if (pfl
->uniform_nb_blocs
== 0 && pfl
->nb_blocs
[0] == 0) {
533 error_setg(errp
, "attribute \"num-blocks\" not specified or zero.");
536 if (pfl
->name
== NULL
) {
537 error_setg(errp
, "attribute \"name\" not specified.");
543 for (nb_regions
= 0; nb_regions
< PFLASH_MAX_ERASE_REGIONS
; ++nb_regions
) {
544 if (pfl
->nb_blocs
[nb_regions
] == 0) {
547 uint64_t sector_len_per_device
= pfl
->sector_len
[nb_regions
];
550 * The size of each flash sector must be a power of 2 and it must be
551 * aligned at the same power of 2.
553 if (sector_len_per_device
& 0xff ||
554 sector_len_per_device
>= (1 << 24) ||
555 !is_power_of_2(sector_len_per_device
))
557 error_setg(errp
, "unsupported configuration: "
558 "sector length[%d] per device = %" PRIx64
".",
559 nb_regions
, sector_len_per_device
);
562 if (pfl
->chip_len
& (sector_len_per_device
- 1)) {
563 error_setg(errp
, "unsupported configuration: "
564 "flash region %d not correctly aligned.",
569 pfl
->chip_len
+= (uint64_t)pfl
->sector_len
[nb_regions
] *
570 pfl
->nb_blocs
[nb_regions
];
573 uint64_t uniform_len
= (uint64_t)pfl
->uniform_nb_blocs
*
574 pfl
->uniform_sector_len
;
575 if (nb_regions
== 0) {
577 pfl
->nb_blocs
[0] = pfl
->uniform_nb_blocs
;
578 pfl
->sector_len
[0] = pfl
->uniform_sector_len
;
579 pfl
->chip_len
= uniform_len
;
580 } else if (uniform_len
!= 0 && uniform_len
!= pfl
->chip_len
) {
581 error_setg(errp
, "\"num-blocks\"*\"sector-length\" "
582 "different from \"num-blocks0\"*\'sector-length0\" + ... + "
583 "\"num-blocks3\"*\"sector-length3\"");
587 memory_region_init_rom_device(&pfl
->orig_mem
, OBJECT(pfl
),
588 &pflash_cfi02_ops
, pfl
, pfl
->name
,
589 pfl
->chip_len
, &local_err
);
591 error_propagate(errp
, local_err
);
595 pfl
->storage
= memory_region_get_ram_ptr(&pfl
->orig_mem
);
599 pfl
->ro
= blk_is_read_only(pfl
->blk
);
600 perm
= BLK_PERM_CONSISTENT_READ
| (pfl
->ro
? 0 : BLK_PERM_WRITE
);
601 ret
= blk_set_perm(pfl
->blk
, perm
, BLK_PERM_ALL
, errp
);
610 if (!blk_check_size_and_read_all(pfl
->blk
, pfl
->storage
,
611 pfl
->chip_len
, errp
)) {
612 vmstate_unregister_ram(&pfl
->orig_mem
, DEVICE(pfl
));
617 /* Only 11 bits are used in the comparison. */
618 pfl
->unlock_addr0
&= 0x7FF;
619 pfl
->unlock_addr1
&= 0x7FF;
621 pflash_setup_mappings(pfl
);
623 sysbus_init_mmio(SYS_BUS_DEVICE(dev
), &pfl
->mem
);
625 timer_init_ns(&pfl
->timer
, QEMU_CLOCK_VIRTUAL
, pflash_timer
, pfl
);
630 /* Hardcoded CFI table (mostly from SG29 Spansion flash) */
631 const uint16_t pri_ofs
= 0x40;
632 /* Standard "QRY" string */
633 pfl
->cfi_table
[0x10] = 'Q';
634 pfl
->cfi_table
[0x11] = 'R';
635 pfl
->cfi_table
[0x12] = 'Y';
636 /* Command set (AMD/Fujitsu) */
637 pfl
->cfi_table
[0x13] = 0x02;
638 pfl
->cfi_table
[0x14] = 0x00;
639 /* Primary extended table address */
640 pfl
->cfi_table
[0x15] = pri_ofs
;
641 pfl
->cfi_table
[0x16] = pri_ofs
>> 8;
642 /* Alternate command set (none) */
643 pfl
->cfi_table
[0x17] = 0x00;
644 pfl
->cfi_table
[0x18] = 0x00;
645 /* Alternate extended table (none) */
646 pfl
->cfi_table
[0x19] = 0x00;
647 pfl
->cfi_table
[0x1A] = 0x00;
649 pfl
->cfi_table
[0x1B] = 0x27;
651 pfl
->cfi_table
[0x1C] = 0x36;
652 /* Vpp min (no Vpp pin) */
653 pfl
->cfi_table
[0x1D] = 0x00;
654 /* Vpp max (no Vpp pin) */
655 pfl
->cfi_table
[0x1E] = 0x00;
656 /* Timeout per single byte/word write (128 ms) */
657 pfl
->cfi_table
[0x1F] = 0x07;
658 /* Timeout for min size buffer write (NA) */
659 pfl
->cfi_table
[0x20] = 0x00;
660 /* Typical timeout for block erase (512 ms) */
661 pfl
->cfi_table
[0x21] = 0x09;
662 /* Typical timeout for full chip erase (4096 ms) */
663 pfl
->cfi_table
[0x22] = 0x0C;
665 pfl
->cfi_table
[0x23] = 0x01;
666 /* Max timeout for buffer write (NA) */
667 pfl
->cfi_table
[0x24] = 0x00;
668 /* Max timeout for block erase */
669 pfl
->cfi_table
[0x25] = 0x0A;
670 /* Max timeout for chip erase */
671 pfl
->cfi_table
[0x26] = 0x0D;
673 pfl
->cfi_table
[0x27] = ctz32(pfl
->chip_len
);
674 /* Flash device interface (8 & 16 bits) */
675 pfl
->cfi_table
[0x28] = 0x02;
676 pfl
->cfi_table
[0x29] = 0x00;
677 /* Max number of bytes in multi-bytes write */
678 /* XXX: disable buffered write as it's not supported */
679 // pfl->cfi_table[0x2A] = 0x05;
680 pfl
->cfi_table
[0x2A] = 0x00;
681 pfl
->cfi_table
[0x2B] = 0x00;
682 /* Number of erase block regions */
683 pfl
->cfi_table
[0x2c] = nb_regions
;
684 /* Erase block regions */
685 for (int i
= 0; i
< nb_regions
; ++i
) {
686 uint32_t sector_len_per_device
= pfl
->sector_len
[i
];
687 pfl
->cfi_table
[0x2d + 4 * i
] = pfl
->nb_blocs
[i
] - 1;
688 pfl
->cfi_table
[0x2e + 4 * i
] = (pfl
->nb_blocs
[i
] - 1) >> 8;
689 pfl
->cfi_table
[0x2f + 4 * i
] = sector_len_per_device
>> 8;
690 pfl
->cfi_table
[0x30 + 4 * i
] = sector_len_per_device
>> 16;
692 assert(0x2c + 4 * nb_regions
< pri_ofs
);
695 pfl
->cfi_table
[0x00 + pri_ofs
] = 'P';
696 pfl
->cfi_table
[0x01 + pri_ofs
] = 'R';
697 pfl
->cfi_table
[0x02 + pri_ofs
] = 'I';
699 /* Extended version 1.0 */
700 pfl
->cfi_table
[0x03 + pri_ofs
] = '1';
701 pfl
->cfi_table
[0x04 + pri_ofs
] = '0';
703 /* Address sensitive unlock required. */
704 pfl
->cfi_table
[0x05 + pri_ofs
] = 0x00;
705 /* Erase suspend not supported. */
706 pfl
->cfi_table
[0x06 + pri_ofs
] = 0x00;
707 /* Sector protect not supported. */
708 pfl
->cfi_table
[0x07 + pri_ofs
] = 0x00;
709 /* Temporary sector unprotect not supported. */
710 pfl
->cfi_table
[0x08 + pri_ofs
] = 0x00;
712 /* Sector protect/unprotect scheme. */
713 pfl
->cfi_table
[0x09 + pri_ofs
] = 0x00;
715 /* Simultaneous operation not supported. */
716 pfl
->cfi_table
[0x0a + pri_ofs
] = 0x00;
717 /* Burst mode not supported. */
718 pfl
->cfi_table
[0x0b + pri_ofs
] = 0x00;
719 /* Page mode not supported. */
720 pfl
->cfi_table
[0x0c + pri_ofs
] = 0x00;
721 assert(0x0c + pri_ofs
< ARRAY_SIZE(pfl
->cfi_table
));
724 static Property pflash_cfi02_properties
[] = {
725 DEFINE_PROP_DRIVE("drive", PFlashCFI02
, blk
),
726 DEFINE_PROP_UINT32("num-blocks", PFlashCFI02
, uniform_nb_blocs
, 0),
727 DEFINE_PROP_UINT32("sector-length", PFlashCFI02
, uniform_sector_len
, 0),
728 DEFINE_PROP_UINT32("num-blocks0", PFlashCFI02
, nb_blocs
[0], 0),
729 DEFINE_PROP_UINT32("sector-length0", PFlashCFI02
, sector_len
[0], 0),
730 DEFINE_PROP_UINT32("num-blocks1", PFlashCFI02
, nb_blocs
[1], 0),
731 DEFINE_PROP_UINT32("sector-length1", PFlashCFI02
, sector_len
[1], 0),
732 DEFINE_PROP_UINT32("num-blocks2", PFlashCFI02
, nb_blocs
[2], 0),
733 DEFINE_PROP_UINT32("sector-length2", PFlashCFI02
, sector_len
[2], 0),
734 DEFINE_PROP_UINT32("num-blocks3", PFlashCFI02
, nb_blocs
[3], 0),
735 DEFINE_PROP_UINT32("sector-length3", PFlashCFI02
, sector_len
[3], 0),
736 DEFINE_PROP_UINT8("width", PFlashCFI02
, width
, 0),
737 DEFINE_PROP_UINT8("mappings", PFlashCFI02
, mappings
, 0),
738 DEFINE_PROP_UINT8("big-endian", PFlashCFI02
, be
, 0),
739 DEFINE_PROP_UINT16("id0", PFlashCFI02
, ident0
, 0),
740 DEFINE_PROP_UINT16("id1", PFlashCFI02
, ident1
, 0),
741 DEFINE_PROP_UINT16("id2", PFlashCFI02
, ident2
, 0),
742 DEFINE_PROP_UINT16("id3", PFlashCFI02
, ident3
, 0),
743 DEFINE_PROP_UINT16("unlock-addr0", PFlashCFI02
, unlock_addr0
, 0),
744 DEFINE_PROP_UINT16("unlock-addr1", PFlashCFI02
, unlock_addr1
, 0),
745 DEFINE_PROP_STRING("name", PFlashCFI02
, name
),
746 DEFINE_PROP_END_OF_LIST(),
749 static void pflash_cfi02_unrealize(DeviceState
*dev
, Error
**errp
)
751 PFlashCFI02
*pfl
= PFLASH_CFI02(dev
);
752 timer_del(&pfl
->timer
);
755 static void pflash_cfi02_class_init(ObjectClass
*klass
, void *data
)
757 DeviceClass
*dc
= DEVICE_CLASS(klass
);
759 dc
->realize
= pflash_cfi02_realize
;
760 dc
->unrealize
= pflash_cfi02_unrealize
;
761 dc
->props
= pflash_cfi02_properties
;
762 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
765 static const TypeInfo pflash_cfi02_info
= {
766 .name
= TYPE_PFLASH_CFI02
,
767 .parent
= TYPE_SYS_BUS_DEVICE
,
768 .instance_size
= sizeof(PFlashCFI02
),
769 .class_init
= pflash_cfi02_class_init
,
772 static void pflash_cfi02_register_types(void)
774 type_register_static(&pflash_cfi02_info
);
777 type_init(pflash_cfi02_register_types
)
779 PFlashCFI02
*pflash_cfi02_register(hwaddr base
,
784 int nb_mappings
, int width
,
785 uint16_t id0
, uint16_t id1
,
786 uint16_t id2
, uint16_t id3
,
787 uint16_t unlock_addr0
,
788 uint16_t unlock_addr1
,
791 DeviceState
*dev
= qdev_create(NULL
, TYPE_PFLASH_CFI02
);
794 qdev_prop_set_drive(dev
, "drive", blk
, &error_abort
);
796 assert(size
% sector_len
== 0);
797 qdev_prop_set_uint32(dev
, "num-blocks", size
/ sector_len
);
798 qdev_prop_set_uint32(dev
, "sector-length", sector_len
);
799 qdev_prop_set_uint8(dev
, "width", width
);
800 qdev_prop_set_uint8(dev
, "mappings", nb_mappings
);
801 qdev_prop_set_uint8(dev
, "big-endian", !!be
);
802 qdev_prop_set_uint16(dev
, "id0", id0
);
803 qdev_prop_set_uint16(dev
, "id1", id1
);
804 qdev_prop_set_uint16(dev
, "id2", id2
);
805 qdev_prop_set_uint16(dev
, "id3", id3
);
806 qdev_prop_set_uint16(dev
, "unlock-addr0", unlock_addr0
);
807 qdev_prop_set_uint16(dev
, "unlock-addr1", unlock_addr1
);
808 qdev_prop_set_string(dev
, "name", name
);
809 qdev_init_nofail(dev
);
811 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, base
);
812 return PFLASH_CFI02(dev
);