qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

hw/rx: Register R5F562N7 and R5F562N8 MCUs

Make the current TYPE_RX62N_MCU an abstract class, and
generate TYPE_R5F562N7_MCU and TYPE_R5F562N8_MCU models.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

+85 -26
+77 -15
hw/rx/rx62n.c
··· 5 5 * (Rev.1.40 R01UH0033EJ0140) 6 6 * 7 7 * Copyright (c) 2019 Yoshinori Sato 8 + * Copyright (c) 2020 Philippe Mathieu-Daudé 8 9 * 9 10 * This program is free software; you can redistribute it and/or modify it 10 11 * under the terms and conditions of the GNU General Public License, ··· 54 55 #define RX62N_TMR_IRQ 174 55 56 #define RX62N_CMT_IRQ 28 56 57 #define RX62N_SCI_IRQ 214 58 + 59 + #define RX62N_XTAL_MIN_HZ (8 * 1000 * 1000) 60 + #define RX62N_XTAL_MAX_HZ (14 * 1000 * 1000) 61 + #define RX62N_PCLK_MAX_HZ (50 * 1000 * 1000) 62 + 63 + typedef struct RX62NClass { 64 + /*< private >*/ 65 + DeviceClass parent_class; 66 + /*< public >*/ 67 + const char *name; 68 + uint64_t ram_size; 69 + uint64_t rom_flash_size; 70 + uint64_t data_flash_size; 71 + } RX62NClass; 72 + 73 + #define RX62N_MCU_CLASS(klass) \ 74 + OBJECT_CLASS_CHECK(RX62NClass, (klass), TYPE_RX62N_MCU) 75 + #define RX62N_MCU_GET_CLASS(obj) \ 76 + OBJECT_GET_CLASS(RX62NClass, (obj), TYPE_RX62N_MCU) 57 77 58 78 /* 59 79 * IRQ -> IPR mapping table ··· 148 168 object_initialize_child(OBJECT(s), "tmr[*]", 149 169 &s->tmr[unit], TYPE_RENESAS_TMR); 150 170 tmr = SYS_BUS_DEVICE(&s->tmr[unit]); 151 - qdev_prop_set_uint64(DEVICE(tmr), "input-freq", RX62N_PCLK); 171 + qdev_prop_set_uint64(DEVICE(tmr), "input-freq", s->pclk_freq_hz); 152 172 sysbus_realize(tmr, &error_abort); 153 173 154 174 irqbase = RX62N_TMR_IRQ + TMR_NR_IRQ * unit; ··· 166 186 object_initialize_child(OBJECT(s), "cmt[*]", 167 187 &s->cmt[unit], TYPE_RENESAS_CMT); 168 188 cmt = SYS_BUS_DEVICE(&s->cmt[unit]); 169 - qdev_prop_set_uint64(DEVICE(cmt), "input-freq", RX62N_PCLK); 189 + qdev_prop_set_uint64(DEVICE(cmt), "input-freq", s->pclk_freq_hz); 170 190 sysbus_realize(cmt, &error_abort); 171 191 172 192 irqbase = RX62N_CMT_IRQ + CMT_NR_IRQ * unit; ··· 185 205 &s->sci[unit], TYPE_RENESAS_SCI); 186 206 sci = SYS_BUS_DEVICE(&s->sci[unit]); 187 207 qdev_prop_set_chr(DEVICE(sci), "chardev", serial_hd(unit)); 188 - qdev_prop_set_uint64(DEVICE(sci), "input-freq", RX62N_PCLK); 208 + qdev_prop_set_uint64(DEVICE(sci), "input-freq", s->pclk_freq_hz); 189 209 sysbus_realize(sci, &error_abort); 190 210 191 211 irqbase = RX62N_SCI_IRQ + SCI_NR_IRQ * unit; ··· 198 218 static void rx62n_realize(DeviceState *dev, Error **errp) 199 219 { 200 220 RX62NState *s = RX62N_MCU(dev); 221 + RX62NClass *rxc = RX62N_MCU_GET_CLASS(dev); 222 + 223 + if (s->xtal_freq_hz == 0) { 224 + error_setg(errp, "\"xtal-frequency-hz\" property must be provided."); 225 + return; 226 + } 227 + /* XTAL range: 8-14 MHz */ 228 + if (s->xtal_freq_hz < RX62N_XTAL_MIN_HZ 229 + || s->xtal_freq_hz > RX62N_XTAL_MAX_HZ) { 230 + error_setg(errp, "\"xtal-frequency-hz\" property in incorrect range."); 231 + return; 232 + } 233 + /* Use a 4x fixed multiplier */ 234 + s->pclk_freq_hz = 4 * s->xtal_freq_hz; 235 + /* PCLK range: 8-50 MHz */ 236 + assert(s->pclk_freq_hz <= RX62N_PCLK_MAX_HZ); 201 237 202 238 memory_region_init_ram(&s->iram, OBJECT(dev), "iram", 203 - RX62N_IRAM_SIZE, &error_abort); 239 + rxc->ram_size, &error_abort); 204 240 memory_region_add_subregion(s->sysmem, RX62N_IRAM_BASE, &s->iram); 205 241 memory_region_init_rom(&s->d_flash, OBJECT(dev), "flash-data", 206 - RX62N_DFLASH_SIZE, &error_abort); 242 + rxc->data_flash_size, &error_abort); 207 243 memory_region_add_subregion(s->sysmem, RX62N_DFLASH_BASE, &s->d_flash); 208 244 memory_region_init_rom(&s->c_flash, OBJECT(dev), "flash-code", 209 - RX62N_CFLASH_SIZE, &error_abort); 245 + rxc->rom_flash_size, &error_abort); 210 246 memory_region_add_subregion(s->sysmem, RX62N_CFLASH_BASE, &s->c_flash); 211 247 212 248 if (!s->kernel) { ··· 235 271 DEFINE_PROP_LINK("main-bus", RX62NState, sysmem, TYPE_MEMORY_REGION, 236 272 MemoryRegion *), 237 273 DEFINE_PROP_BOOL("load-kernel", RX62NState, kernel, false), 274 + DEFINE_PROP_UINT32("xtal-frequency-hz", RX62NState, xtal_freq_hz, 0), 238 275 DEFINE_PROP_END_OF_LIST(), 239 276 }; 240 277 ··· 246 283 device_class_set_props(dc, rx62n_properties); 247 284 } 248 285 249 - static const TypeInfo rx62n_info = { 250 - .name = TYPE_RX62N_MCU, 251 - .parent = TYPE_DEVICE, 252 - .instance_size = sizeof(RX62NState), 253 - .class_init = rx62n_class_init, 286 + static void r5f562n7_class_init(ObjectClass *oc, void *data) 287 + { 288 + RX62NClass *rxc = RX62N_MCU_CLASS(oc); 289 + 290 + rxc->ram_size = 64 * KiB; 291 + rxc->rom_flash_size = 384 * KiB; 292 + rxc->data_flash_size = 32 * KiB; 254 293 }; 255 294 256 - static void rx62n_register_types(void) 295 + static void r5f562n8_class_init(ObjectClass *oc, void *data) 257 296 { 258 - type_register_static(&rx62n_info); 259 - } 297 + RX62NClass *rxc = RX62N_MCU_CLASS(oc); 260 298 261 - type_init(rx62n_register_types) 299 + rxc->ram_size = 96 * KiB; 300 + rxc->rom_flash_size = 512 * KiB; 301 + rxc->data_flash_size = 32 * KiB; 302 + }; 303 + 304 + static const TypeInfo rx62n_types[] = { 305 + { 306 + .name = TYPE_R5F562N7_MCU, 307 + .parent = TYPE_RX62N_MCU, 308 + .class_init = r5f562n7_class_init, 309 + }, { 310 + .name = TYPE_R5F562N8_MCU, 311 + .parent = TYPE_RX62N_MCU, 312 + .class_init = r5f562n8_class_init, 313 + }, { 314 + .name = TYPE_RX62N_MCU, 315 + .parent = TYPE_DEVICE, 316 + .instance_size = sizeof(RX62NState), 317 + .class_size = sizeof(RX62NClass), 318 + .class_init = rx62n_class_init, 319 + .abstract = true, 320 + } 321 + }; 322 + 323 + DEFINE_TYPES(rx62n_types)
+8 -11
include/hw/rx/rx62n.h
··· 34 34 #define TYPE_RX62N_MCU "rx62n-mcu" 35 35 #define RX62N_MCU(obj) OBJECT_CHECK(RX62NState, (obj), TYPE_RX62N_MCU) 36 36 37 + #define TYPE_R5F562N7_MCU "r5f562n7-mcu" 38 + #define TYPE_R5F562N8_MCU "r5f562n8-mcu" 39 + 37 40 #define RX62N_NR_TMR 2 38 41 #define RX62N_NR_CMT 2 39 42 #define RX62N_NR_SCI 6 ··· 59 62 MemoryRegion iomem3; 60 63 MemoryRegion c_flash; 61 64 qemu_irq irq[NR_IRQS]; 62 - } RX62NState; 63 65 64 - /* 65 - * RX62N Internal Memory 66 - * It is the value of R5F562N8. 67 - * Please change the size for R5F562N7. 68 - */ 69 - #define RX62N_IRAM_SIZE (96 * KiB) 70 - #define RX62N_DFLASH_SIZE (32 * KiB) 71 - #define RX62N_CFLASH_SIZE (512 * KiB) 72 - 73 - #define RX62N_PCLK (48 * 1000 * 1000) 66 + /* Input Clock (XTAL) frequency */ 67 + uint32_t xtal_freq_hz; 68 + /* Peripheral Module Clock frequency */ 69 + uint32_t pclk_freq_hz; 70 + } RX62NState; 74 71 75 72 #endif