xref: /qemu/include/hw/nvram/nrf51_nvm.h (revision e3a6e0da)
1 /*
2  * Nordic Semiconductor nRF51 non-volatile memory
3  *
4  * It provides an interface to erase regions in flash memory.
5  * Furthermore it provides the user and factory information registers.
6  *
7  * QEMU interface:
8  * + sysbus MMIO regions 0: NVMC peripheral registers
9  * + sysbus MMIO regions 1: FICR peripheral registers
10  * + sysbus MMIO regions 2: UICR peripheral registers
11  * + flash-size property: flash size in bytes.
12  *
13  * Accuracy of the peripheral model:
14  * + Code regions (MPU configuration) are disregarded.
15  *
16  * Copyright 2018 Steffen Görtz <contrib@steffen-goertz.de>
17  *
18  * This code is licensed under the GPL version 2 or later.  See
19  * the COPYING file in the top-level directory.
20  *
21  */
22 #ifndef NRF51_NVM_H
23 #define NRF51_NVM_H
24 
25 #include "hw/sysbus.h"
26 #include "qom/object.h"
27 #define TYPE_NRF51_NVM "nrf51_soc.nvm"
28 typedef struct NRF51NVMState NRF51NVMState;
29 DECLARE_INSTANCE_CHECKER(NRF51NVMState, NRF51_NVM,
30                          TYPE_NRF51_NVM)
31 
32 #define NRF51_UICR_FIXTURE_SIZE 64
33 
34 #define NRF51_NVMC_SIZE         0x1000
35 
36 #define NRF51_NVMC_READY        0x400
37 #define NRF51_NVMC_READY_READY  0x01
38 #define NRF51_NVMC_CONFIG       0x504
39 #define NRF51_NVMC_CONFIG_MASK  0x03
40 #define NRF51_NVMC_CONFIG_WEN   0x01
41 #define NRF51_NVMC_CONFIG_EEN   0x02
42 #define NRF51_NVMC_ERASEPCR1    0x508
43 #define NRF51_NVMC_ERASEPCR0    0x510
44 #define NRF51_NVMC_ERASEALL     0x50C
45 #define NRF51_NVMC_ERASEUICR    0x514
46 #define NRF51_NVMC_ERASE        0x01
47 
48 #define NRF51_UICR_SIZE         0x100
49 
50 struct NRF51NVMState {
51     SysBusDevice parent_obj;
52 
53     MemoryRegion mmio;
54     MemoryRegion ficr;
55     MemoryRegion uicr;
56     MemoryRegion flash;
57 
58     uint32_t uicr_content[NRF51_UICR_FIXTURE_SIZE];
59     uint32_t flash_size;
60     uint8_t *storage;
61 
62     uint32_t config;
63 
64 };
65 
66 
67 #endif
68