Revision ba158029 hw/omap_sx1.c

b/hw/omap_sx1.c
59 59
 * - 1 RTC
60 60
 */
61 61

  
62
static uint32_t static_readb(void *opaque, target_phys_addr_t offset)
62
static uint64_t static_read(void *opaque, target_phys_addr_t offset,
63
                            unsigned size)
63 64
{
64 65
    uint32_t *val = (uint32_t *) opaque;
66
    uint32_t mask = (4 / size) - 1;
65 67

  
66
    return *val >> ((offset & 3) << 3);
67
}
68

  
69
static uint32_t static_readh(void *opaque, target_phys_addr_t offset)
70
{
71
    uint32_t *val = (uint32_t *) opaque;
72

  
73
    return *val >> ((offset & 1) << 3);
74
}
75

  
76
static uint32_t static_readw(void *opaque, target_phys_addr_t offset)
77
{
78
    uint32_t *val = (uint32_t *) opaque;
79

  
80
    return *val >> ((offset & 0) << 3);
68
    return *val >> ((offset & mask) << 3);
81 69
}
82 70

  
83 71
static void static_write(void *opaque, target_phys_addr_t offset,
84
                uint32_t value)
72
                         uint64_t value, unsigned size)
85 73
{
86 74
#ifdef SPY
87
    printf("%s: value %08lx written at " PA_FMT "\n",
88
                    __FUNCTION__, value, offset);
75
    printf("%s: value %" PRIx64 " %u bytes written at 0x%x\n",
76
                    __func__, value, size, (int)offset);
89 77
#endif
90 78
}
91 79

  
92
static CPUReadMemoryFunc * const static_readfn[] = {
93
    static_readb,
94
    static_readh,
95
    static_readw,
96
};
97

  
98
static CPUWriteMemoryFunc * const static_writefn[] = {
99
    static_write,
100
    static_write,
101
    static_write,
80
static const MemoryRegionOps static_ops = {
81
    .read = static_read,
82
    .write = static_write,
83
    .endianness = DEVICE_NATIVE_ENDIAN,
102 84
};
103 85

  
104 86
#define sdram_size	0x02000000
......
123 105
{
124 106
    struct omap_mpu_state_s *cpu;
125 107
    MemoryRegion *address_space = get_system_memory();
126
    int io;
108
    MemoryRegion *flash = g_new(MemoryRegion, 1);
109
    MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
110
    MemoryRegion *cs = g_new(MemoryRegion, 4);
127 111
    static uint32_t cs0val = 0x00213090;
128 112
    static uint32_t cs1val = 0x00215070;
129 113
    static uint32_t cs2val = 0x00001139;
......
140 124
    cpu = omap310_mpu_init(address_space, sx1_binfo.ram_size, cpu_model);
141 125

  
142 126
    /* External Flash (EMIFS) */
143
    cpu_register_physical_memory(OMAP_CS0_BASE, flash_size,
144
                                 qemu_ram_alloc(NULL, "omap_sx1.flash0-0",
145
                                                flash_size) | IO_MEM_ROM);
146

  
147
    io = cpu_register_io_memory(static_readfn, static_writefn, &cs0val,
148
                                DEVICE_NATIVE_ENDIAN);
149
    cpu_register_physical_memory(OMAP_CS0_BASE + flash_size,
150
                    OMAP_CS0_SIZE - flash_size, io);
151
    io = cpu_register_io_memory(static_readfn, static_writefn, &cs2val,
152
                                DEVICE_NATIVE_ENDIAN);
153
    cpu_register_physical_memory(OMAP_CS2_BASE, OMAP_CS2_SIZE, io);
154
    io = cpu_register_io_memory(static_readfn, static_writefn, &cs3val,
155
                                DEVICE_NATIVE_ENDIAN);
156
    cpu_register_physical_memory(OMAP_CS3_BASE, OMAP_CS3_SIZE, io);
127
    memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size);
128
    memory_region_set_readonly(flash, true);
129
    memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
130

  
131
    memory_region_init_io(&cs[0], &static_ops, &cs0val,
132
                          "sx1.cs0", OMAP_CS0_SIZE - flash_size);
133
    memory_region_add_subregion(address_space,
134
                                OMAP_CS0_BASE + flash_size, &cs[0]);
135

  
136

  
137
    memory_region_init_io(&cs[2], &static_ops, &cs2val,
138
                          "sx1.cs2", OMAP_CS2_SIZE);
139
    memory_region_add_subregion(address_space,
140
                                OMAP_CS2_BASE, &cs[2]);
141

  
142
    memory_region_init_io(&cs[3], &static_ops, &cs3val,
143
                          "sx1.cs3", OMAP_CS3_SIZE);
144
    memory_region_add_subregion(address_space,
145
                                OMAP_CS2_BASE, &cs[3]);
157 146

  
158 147
    fl_idx = 0;
159 148
#ifdef TARGET_WORDS_BIGENDIAN
......
176 165

  
177 166
    if ((version == 1) &&
178 167
            (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
179
        cpu_register_physical_memory(OMAP_CS1_BASE, flash1_size,
180
                                     qemu_ram_alloc(NULL, "omap_sx1.flash1-0",
181
                                                    flash1_size) | IO_MEM_ROM);
182
        io = cpu_register_io_memory(static_readfn, static_writefn, &cs1val,
183
                                    DEVICE_NATIVE_ENDIAN);
184
        cpu_register_physical_memory(OMAP_CS1_BASE + flash1_size,
185
                        OMAP_CS1_SIZE - flash1_size, io);
168
        memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0", flash1_size);
169
        memory_region_set_readonly(flash_1, true);
170
        memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
171

  
172
        memory_region_init_io(&cs[1], &static_ops, &cs1val,
173
                              "sx1.cs1", OMAP_CS1_SIZE - flash1_size);
174
        memory_region_add_subregion(address_space,
175
                                OMAP_CS1_BASE + flash1_size, &cs[1]);
186 176

  
187 177
        if (!pflash_cfi01_register(OMAP_CS1_BASE, NULL,
188 178
                                   "omap_sx1.flash1-1", flash1_size,
......
194 184
        }
195 185
        fl_idx++;
196 186
    } else {
197
        io = cpu_register_io_memory(static_readfn, static_writefn, &cs1val,
198
                                    DEVICE_NATIVE_ENDIAN);
199
        cpu_register_physical_memory(OMAP_CS1_BASE, OMAP_CS1_SIZE, io);
187
        memory_region_init_io(&cs[1], &static_ops, &cs1val,
188
                              "sx1.cs1", OMAP_CS1_SIZE);
189
        memory_region_add_subregion(address_space,
190
                                OMAP_CS1_BASE, &cs[1]);
200 191
    }
201 192

  
202 193
    if (!kernel_filename && !fl_idx) {

Also available in: Unified diff