More SH4 clean ups (including code style series)
v6 cover More SH4 clean ups (including code style series)
This now includes the previous code style clean up series so everything is in the series now. This got big enough for now so I'll wait until these are merged (hopefully before the freeze) before going on so I don't have to carry them in my tree. Only plan to submit another version if needed from review otherwise that's it for now, hopefully this is the last version.
v6: Found some lines with wrong indentation missed in code style clean up and one line missed removing sh_intc_source from header so I'm posting the whole series with these two small fixes, otherwise same as v5 but rebased on fixed code style series which is now also included.
v5: Do not use hw_error, back to qemu_log_mask; split up QOM-ify patch mode and drop one memory alias for sh_serial
v4: Drop changes from fprintf before abort() as Philippe said, only change sh_serial now which can use hw_error instead; missed two more debug printfs in sh_timer that I've also added now; some more clean ups
v3: Correct mistakes found in review, drop size change of sh_intc iomem as that was wrong so only rename it, more clean ups
v2: separate sh_serial trace events, split QOM-ify patch for easier review and some more patches to clean up sh_intc a bit
Regards,
BALATON Zoltan (30):
hw/sh4: Coding style: Remove tabs
hw/sh4: Coding style: Fix multi-line comments
hw/sh4: Coding style: White space fixes
hw/sh4: Coding style: Add missing braces
hw/sh4: Coding style: Remove unnecessary casts
hw/sh4: Fix typos in a comment
hw/sh4: Change debug printfs to traces
hw/sh4/r2d: Use error_report instead of fprintf to stderr hw/char/sh_serial: Do not abort on invalid access hw/char/sh_serial: Rename type sh_serial_state to SHSerialState hw/char/sh_serial: Embed QEMUTimer in state struct hw/char/sh_serial: Split off sh_serial_reset() from sh_serial_init() hw/char/sh_serial: QOM-ify
hw/char/sh_serial: Add device id to trace output hw/intc/sh_intc: Use existing macro instead of local one hw/intc/sh_intc: Turn some defines into an enum hw/intc/sh_intc: Rename iomem region
hw/intc/sh_intc: Drop another useless macro hw/intc/sh_intc: Move sh_intc_register() closer to its only user hw/intc/sh_intc: Remove excessive parenthesis hw/intc/sh_intc: Use array index instead of pointer arithmetics hw/intc/sh_intc: Inline and drop sh_intc_source() function hw/intc/sh_intc: Replace abort() with g_assert_not_reached() hw/intc/sh_intc: Avoid using continue in loops hw/intc/sh_intc: Simplify allocating sources array hw/intc/sh_intc: Remove unneeded local variable initialisers hw/timer/sh_timer: Rename sh_timer_state to SHTimerState hw/timer/sh_timer: Do not wrap lines that are not too long hw/timer/sh_timer: Fix timer memory region size hw/timer/sh_timer: Remove use of hw_error
hw/char/sh_serial.c | 236 +++--- hw/char/trace-events | 4 + hw/intc/sh_intc.c | 546 ++++++------- hw/intc/trace-events | 8 + hw/pci-host/sh_pci.c | 10 +- hw/sh4/r2d.c | 69 +- hw/sh4/sh7750.c | 637 ++++++++------- hw/sh4/sh7750_regnames.c | 148 ++-- hw/sh4/sh7750_regs.h | 1600 +++++++++++++++++++------------------- hw/sh4/shix.c | 12 +- hw/sh4/trace-events | 3 + hw/sh4/trace.h | 1 + hw/timer/sh_timer.c | 147 ++-- hw/timer/trace-events | 5 + include/hw/sh4/sh.h | 19 +- include/hw/sh4/sh_intc.h | 2 +- meson.build | 1 + 17 files changed, 1739 insertions(+), 1709 deletions(-) create mode 100644 hw/sh4/trace-events create mode 100644 hw/sh4/trace.h
Signature · 1 line
2.21.4
PATCH v6 1/30 hw/sh4: Coding style: Remove tabs
--- hw/intc/sh_intc.c | 220 +++--- hw/sh4/r2d.c | 34 +- hw/sh4/sh7750.c | 515 ++++++------ hw/sh4/sh7750_regnames.c | 144 ++-- hw/sh4/sh7750_regs.h | 1592 +++++++++++++++++++------------------- include/hw/sh4/sh.h | 20 +- 6 files changed, 1262 insertions(+), 1263 deletions(-)
hw/intc/sh_intc.c +110 -110
@@ -20,7 +20,7 @@#define INTC_A7 (x) ((x) & 0x1fffffff)void sh_intc_toggle_source (struct intc_source *source, -int enable_adj,int assert_adj) +int enable_adj,int assert_adj) {int enable_changed =0 ;int pending_changed =0 ;
@@ -54,22 +54,22 @@ void sh_intc_toggle_source(struct intc_source *source,if (source->parent->pending ==0 ) {cpu_reset_interrupt (first_cpu,CPU_INTERRUPT_HARD ); } - } + } }if (enable_changed || assert_adj || pending_changed) {#ifdef DEBUG_INTC_SOURCES printf ("sh_intc: (%d/%d/%d/%d) interrupt source 0x%x %s%s%s\n" , - source->parent->pending, - source->asserted, - source->enable_count, - source->enable_max, - source->vect, - source->asserted ?"asserted " : - assert_adj ?"deasserted" :"" , - enable_changed ==1 ?"enabled " : - enable_changed ==-1 ?"disabled " :"" , - source->pending ?"pending" :"" ); + source->parent->pending, + source->asserted, + source->enable_count, + source->enable_max, + source->vect, + source->asserted ?"asserted " : + assert_adj ?"deasserted" :"" , + enable_changed ==1 ?"enabled " : + enable_changed ==-1 ?"disabled " :"" , + source->pending ?"pending" :"" );#endif } }
@@ -99,13 +99,13 @@ int sh_intc_get_pending_vector(struct intc_desc *desc, int imask)for (i =0 ; i < desc->nr_sources; i++) {struct intc_source *source = desc->sources + i; -if (source->pending) { +if (source->pending) {#ifdef DEBUG_INTC_SOURCES printf ("sh_intc: (%d) returning interrupt source 0x%x\n" , - desc->pending, source->vect); + desc->pending, source->vect);#endif return source->vect; - } + } }abort ();
@@ -119,16 +119,16 @@ int sh_intc_get_pending_vector(struct intc_desc *desc, int imask)#define INTC_MODE_IS_PRIO 8static unsigned int sh_intc_mode (unsigned long address, -unsigned long set_reg,unsigned long clr_reg) +unsigned long set_reg,unsigned long clr_reg) {if ((address !=INTC_A7 (set_reg)) && - (address !=INTC_A7 (clr_reg))) + (address !=INTC_A7 (clr_reg)))return INTC_MODE_NONE ;if (set_reg && clr_reg) {if (address ==INTC_A7 (set_reg))return INTC_MODE_DUAL_SET ; -else +else return INTC_MODE_DUAL_CLR ; }
@@ -139,12 +139,12 @@ static unsigned int sh_intc_mode(unsigned long address, }static void sh_intc_locate (struct intc_desc *desc, -unsigned long address, -unsigned long **datap, -intc_enum **enums, -unsigned int *first, -unsigned int *width, -unsigned int *modep) +unsigned long address, +unsigned long **datap, +intc_enum **enums, +unsigned int *first, +unsigned int *width, +unsigned int *modep) {unsigned int i, mode;
@@ -152,54 +152,54 @@ static void sh_intc_locate(struct intc_desc *desc,if (desc->mask_regs) {for (i =0 ; i < desc->nr_mask_regs; i++) { -struct intc_mask_reg *mr = desc->mask_regs + i; +struct intc_mask_reg *mr = desc->mask_regs + i; - mode =sh_intc_mode (address, mr->set_reg, mr->clr_reg); -if (mode ==INTC_MODE_NONE ) + mode =sh_intc_mode (address, mr->set_reg, mr->clr_reg); +if (mode ==INTC_MODE_NONE )continue ; - *modep = mode; - *datap = &mr->value; - *enums = mr->enum_ids; - *first = mr->reg_width -1 ; - *width =1 ; -return ; - } + *modep = mode; + *datap = &mr->value; + *enums = mr->enum_ids; + *first = mr->reg_width -1 ; + *width =1 ; +return ; + } }if (desc->prio_regs) {for (i =0 ; i < desc->nr_prio_regs; i++) { -struct intc_prio_reg *pr = desc->prio_regs + i; +struct intc_prio_reg *pr = desc->prio_regs + i; - mode =sh_intc_mode (address, pr->set_reg, pr->clr_reg); -if (mode ==INTC_MODE_NONE ) + mode =sh_intc_mode (address, pr->set_reg, pr->clr_reg); +if (mode ==INTC_MODE_NONE )continue ; - *modep = mode |INTC_MODE_IS_PRIO ; - *datap = &pr->value; - *enums = pr->enum_ids; - *first = (pr->reg_width / pr->field_width) -1 ; - *width = pr->field_width; -return ; - } + *modep = mode |INTC_MODE_IS_PRIO ; + *datap = &pr->value; + *enums = pr->enum_ids; + *first = (pr->reg_width / pr->field_width) -1 ; + *width = pr->field_width; +return ; + } }abort (); }static void sh_intc_toggle_mask (struct intc_desc *desc,intc_enum id, -int enable,int is_group) +int enable,int is_group) {struct intc_source *source = desc->sources + id;if (!id) -return ; +return ;if (!source->next_enum_id && (!source->enable_max || !source->vect)) {#ifdef DEBUG_INTC_SOURCES printf ("sh_intc: reserved interrupt source %d modified\n" , id);#endif -return ; +return ; }if (source->vect)
@@ -237,7 +237,7 @@ static uint64_t sh_intc_read(void *opaque, hwaddr offset,#endif sh_intc_locate (desc, (unsigned long )offset, &valuep, - &enum_ids, &first, &width, &mode); + &enum_ids, &first, &width, &mode);return *valuep; }
@@ -258,7 +258,7 @@ static void sh_intc_write(void *opaque, hwaddr offset,#endif sh_intc_locate (desc, (unsigned long )offset, &valuep, - &enum_ids, &first, &width, &mode); + &enum_ids, &first, &width, &mode);switch (mode) {case INTC_MODE_ENABLE_REG |INTC_MODE_IS_PRIO :break ;
@@ -270,11 +270,11 @@ static void sh_intc_write(void *opaque, hwaddr offset,for (k =0 ; k <= first; k++) { mask = ((1 << width) -1 ) << ((first - k) * width); -if ((*valuep & mask) == (value & mask)) +if ((*valuep & mask) == (value & mask))continue ;#if 0 -printf ("k = %d, first = %d, enum = %d, mask = 0x%08x\n" , - k, first, enum_ids[k], (unsigned int )mask); +printf ("k = %d, first = %d, enum = %d, mask = 0x%08x\n" , + k, first, enum_ids[k], (unsigned int )mask);#endif sh_intc_toggle_mask (desc, enum_ids[k], value & mask,0 ); }
@@ -301,11 +301,11 @@ struct intc_source *sh_intc_source(struct intc_desc *desc, intc_enum id) }static unsigned int sh_intc_register (MemoryRegion *sysmem, -struct intc_desc *desc, -const unsigned long address, -const char *type, -const char *action, -const unsigned int index) +struct intc_desc *desc, +const unsigned long address, +const char *type, +const char *action, +const unsigned int index) {char name[60 ];MemoryRegion *iomem, *iomem_p4, *iomem_a7;
@@ -333,74 +333,74 @@ static unsigned int sh_intc_register(MemoryRegion *sysmem, }static void sh_intc_register_source (struct intc_desc *desc, -intc_enum source, -struct intc_group *groups, -int nr_groups) +intc_enum source, +struct intc_group *groups, +int nr_groups) {unsigned int i, k;struct intc_source *s;if (desc->mask_regs) {for (i =0 ; i < desc->nr_mask_regs; i++) { -struct intc_mask_reg *mr = desc->mask_regs + i; +struct intc_mask_reg *mr = desc->mask_regs + i; -for (k =0 ; k <ARRAY_SIZE (mr->enum_ids); k++) { +for (k =0 ; k <ARRAY_SIZE (mr->enum_ids); k++) {if (mr->enum_ids[k] != source)continue ; - s =sh_intc_source (desc, mr->enum_ids[k]); -if (s) + s =sh_intc_source (desc, mr->enum_ids[k]); +if (s) s->enable_max++; - } - } + } + } }if (desc->prio_regs) {for (i =0 ; i < desc->nr_prio_regs; i++) { -struct intc_prio_reg *pr = desc->prio_regs + i; +struct intc_prio_reg *pr = desc->prio_regs + i; -for (k =0 ; k <ARRAY_SIZE (pr->enum_ids); k++) { +for (k =0 ; k <ARRAY_SIZE (pr->enum_ids); k++) {if (pr->enum_ids[k] != source)continue ; - s =sh_intc_source (desc, pr->enum_ids[k]); -if (s) + s =sh_intc_source (desc, pr->enum_ids[k]); +if (s) s->enable_max++; - } - } + } + } }if (groups) {for (i =0 ; i < nr_groups; i++) { -struct intc_group *gr = groups + i; +struct intc_group *gr = groups + i; -for (k =0 ; k <ARRAY_SIZE (gr->enum_ids); k++) { +for (k =0 ; k <ARRAY_SIZE (gr->enum_ids); k++) {if (gr->enum_ids[k] != source)continue ; - s =sh_intc_source (desc, gr->enum_ids[k]); -if (s) + s =sh_intc_source (desc, gr->enum_ids[k]); +if (s) s->enable_max++; - } - } + } + } } }void sh_intc_register_sources (struct intc_desc *desc, -struct intc_vect *vectors, -int nr_vectors, -struct intc_group *groups, -int nr_groups) +struct intc_vect *vectors, +int nr_vectors, +struct intc_group *groups, +int nr_groups) {unsigned int i, k;struct intc_source *s;for (i =0 ; i < nr_vectors; i++) { -struct intc_vect *vect = vectors + i; +struct intc_vect *vect = vectors + i; -sh_intc_register_source (desc, vect->enum_id, groups, nr_groups); - s =sh_intc_source (desc, vect->enum_id); +sh_intc_register_source (desc, vect->enum_id, groups, nr_groups); + s =sh_intc_source (desc, vect->enum_id);if (s) { s->vect = vect->vect;
@@ -413,34 +413,34 @@ void sh_intc_register_sources(struct intc_desc *desc,if (groups) {for (i =0 ; i < nr_groups; i++) { -struct intc_group *gr = groups + i; +struct intc_group *gr = groups + i; - s =sh_intc_source (desc, gr->enum_id); - s->next_enum_id = gr->enum_ids[0 ]; + s =sh_intc_source (desc, gr->enum_id); + s->next_enum_id = gr->enum_ids[0 ]; -for (k =1 ; k <ARRAY_SIZE (gr->enum_ids); k++) { +for (k =1 ; k <ARRAY_SIZE (gr->enum_ids); k++) {if (!gr->enum_ids[k])continue ; - s =sh_intc_source (desc, gr->enum_ids[k -1 ]); - s->next_enum_id = gr->enum_ids[k]; - } + s =sh_intc_source (desc, gr->enum_ids[k -1 ]); + s->next_enum_id = gr->enum_ids[k]; + }#ifdef DEBUG_INTC_SOURCES -printf ("sh_intc: registered group %d (%d/%d)\n" , - gr->enum_id, s->enable_count, s->enable_max); +printf ("sh_intc: registered group %d (%d/%d)\n" , + gr->enum_id, s->enable_count, s->enable_max);#endif - } + } } }int sh_intc_init (MemoryRegion *sysmem, -struct intc_desc *desc, -int nr_sources, -struct intc_mask_reg *mask_regs, -int nr_mask_regs, -struct intc_prio_reg *prio_regs, -int nr_prio_regs) +struct intc_desc *desc, +int nr_sources, +struct intc_mask_reg *mask_regs, +int nr_mask_regs, +struct intc_prio_reg *prio_regs, +int nr_prio_regs) {unsigned int i, j;
@@ -474,24 +474,24 @@ int sh_intc_init(MemoryRegion *sysmem, reg_struct->action##_reg, #type, #action, jif (desc->mask_regs) {for (i =0 ; i < desc->nr_mask_regs; i++) { -struct intc_mask_reg *mr = desc->mask_regs + i; +struct intc_mask_reg *mr = desc->mask_regs + i; j +=sh_intc_register (sysmem, desc,INT_REG_PARAMS (mr, mask, set, j)); j +=sh_intc_register (sysmem, desc,INT_REG_PARAMS (mr, mask, clr, j)); - } + } }if (desc->prio_regs) {for (i =0 ; i < desc->nr_prio_regs; i++) { -struct intc_prio_reg *pr = desc->prio_regs + i; +struct intc_prio_reg *pr = desc->prio_regs + i; j +=sh_intc_register (sysmem, desc,INT_REG_PARAMS (pr, prio, set, j)); j +=sh_intc_register (sysmem, desc,INT_REG_PARAMS (pr, prio, clr, j)); - } + } }#undef INT_REG_PARAMS
@@ -505,10 +505,10 @@ void sh_intc_set_irl(void *opaque, int n, int level)struct intc_source *s = opaque;int i, irl = level ^15 ;for (i =0 ; (s =sh_intc_source (s->parent, s->next_enum_id)); i++) { -if (i == irl) -sh_intc_toggle_source (s, s->enable_count?0 :1 , s->asserted?0 :1 ); -else -if (s->asserted) -sh_intc_toggle_source (s,0 ,-1 ); +if (i == irl) +sh_intc_toggle_source (s, s->enable_count?0 :1 , s->asserted?0 :1 ); +else +if (s->asserted) +sh_intc_toggle_source (s,0 ,-1 ); } }
hw/sh4/r2d.c +17 -17
@@ -56,10 +56,10 @@#define LINUX_LOAD_OFFSET 0x0800000#define INITRD_LOAD_OFFSET 0x1800000 -#define PA_IRLMSK 0x00 -#define PA_POWOFF 0x30 -#define PA_VERREG 0x32 -#define PA_OUTPORT 0x36 +#define PA_IRLMSK 0x00 +#define PA_POWOFF 0x30 +#define PA_VERREG 0x32 +#define PA_OUTPORT 0x36 typedef struct { uint16_t bcr;
@@ -96,19 +96,19 @@ enum r2d_fpga_irq { };static const struct {short irl;uint16_t msk; } irqtab[NR_IRQS ] = { - [CF_IDE ] = {1 ,1 <<9 }, - [CF_CD ] = {2 ,1 <<8 }, - [PCI_INTA ] = {9 ,1 <<14 }, - [PCI_INTB ] = {10 ,1 <<13 }, - [PCI_INTC ] = {3 ,1 <<12 }, - [PCI_INTD ] = {0 ,1 <<11 }, - [SM501 ] = {4 ,1 <<10 }, - [KEY ] = {5 ,1 <<6 }, - [RTC_A ] = {6 ,1 <<5 }, - [RTC_T ] = {7 ,1 <<4 }, - [SDCARD ] = {8 ,1 <<7 }, - [EXT ] = {11 ,1 <<0 }, - [TP ] = {12 ,1 <<15 }, + [CF_IDE ] = {1 ,1 <<9 }, + [CF_CD ] = {2 ,1 <<8 }, + [PCI_INTA ] = {9 ,1 <<14 }, + [PCI_INTB ] = {10 ,1 <<13 }, + [PCI_INTC ] = {3 ,1 <<12 }, + [PCI_INTD ] = {0 ,1 <<11 }, + [SM501 ] = {4 ,1 <<10 }, + [KEY ] = {5 ,1 <<6 }, + [RTC_A ] = {6 ,1 <<5 }, + [RTC_T ] = {7 ,1 <<4 }, + [SDCARD ] = {8 ,1 <<7 }, + [EXT ] = {11 ,1 <<0 }, + [TP ] = {12 ,1 <<15 }, };static void update_irl (r2d_fpga_t *fpga)
hw/sh4/sh7750.c +257 -258
825 lines not on this page · raw message
hw/sh4/sh7750_regnames.c +72 -72
156 lines not on this page · raw message
hw/sh4/sh7750_regs.h +796 -796
1,561 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.21.4
Part of the diff is not shown here. View the raw message.
PATCH v6 2/30 hw/sh4: Coding style: Fix multi-line comments
In reply to BALATON Zoltan--- hw/char/sh_serial.c | 6 +- hw/intc/sh_intc.c | 9 +- hw/sh4/r2d.c | 6 +- hw/sh4/sh7750.c | 22 +- hw/sh4/sh7750_regs.h | 504 +++++++++++++++++++++---------------------- hw/sh4/shix.c | 10 +- hw/timer/sh_timer.c | 7 +- 7 files changed, 286 insertions(+), 278 deletions(-)
hw/char/sh_serial.c +4 -2
@@ -115,8 +115,10 @@ static void sh_serial_write(void *opaque, hwaddr offs,case 0x0c :/* FTDR / TDR */ if (qemu_chr_fe_backend_connected (&s->chr)) { ch = val; -/* XXX this blocks entire thread. Rewrite to use -* qemu_chr_fe_write and background I/O callbacks */ +/* +* XXX this blocks entire thread. Rewrite to use +* qemu_chr_fe_write and background I/O callbacks +*/ qemu_chr_fe_write_all (&s->chr, &ch,1 ); } s->dr = val;
hw/intc/sh_intc.c +5 -4
@@ -450,8 +450,7 @@ int sh_intc_init(MemoryRegion *sysmem, desc->nr_mask_regs = nr_mask_regs; desc->prio_regs = prio_regs; desc->nr_prio_regs = nr_prio_regs; -/* Allocate 4 MemoryRegions per register (2 actions * 2 aliases). -**/ +/* Allocate 4 MemoryRegions per register (2 actions * 2 aliases) */ desc->iomem_aliases =g_new0 (MemoryRegion, (nr_mask_regs + nr_prio_regs) *4 );
@@ -498,8 +497,10 @@ int sh_intc_init(MemoryRegion *sysmem,return 0 ; } -/* Assert level <n> IRL interrupt. -0:deassert. 1:lowest priority,... 15:highest priority. */ +/* +* Assert level <n> IRL interrupt. +* 0:deassert. 1:lowest priority,... 15:highest priority +*/ void sh_intc_set_irl (void *opaque,int n,int level) {struct intc_source *s = opaque;
hw/sh4/r2d.c +4 -2
@@ -352,8 +352,10 @@ static void r2d_init(MachineState *machine) }if (kernel_cmdline) { -/* I see no evidence that this .kernel_cmdline buffer requires -NUL-termination, so using strncpy should be ok. */ +/* +* I see no evidence that this .kernel_cmdline buffer requires +* NUL-termination, so using strncpy should be ok. +*/ strncpy (boot_params.kernel_cmdline, kernel_cmdline,sizeof (boot_params.kernel_cmdline)); }
hw/sh4/sh7750.c +12 -10
@@ -82,9 +82,10 @@ static inline int has_bcr3_and_bcr4(SH7750State * s) {return s->cpu->env.features &SH_FEATURE_BCR3_AND_BCR4 ; } -/********************************************************************** -I/O ports -**********************************************************************/ + +/* +* I/O ports +*/ int sh7750_register_io_device (SH7750State * s,sh7750_io_device * device) {
@@ -194,9 +195,9 @@ static void portb_changed(SH7750State * s, uint16_t prev)gen_port_interrupts (s); } -/********************************************************************** -Memory -**********************************************************************/ +/* +* Memory +*/ static void error_access (const char *kind,hwaddr addr) {
@@ -491,7 +492,8 @@ static const MemoryRegionOps sh7750_mem_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -/* sh775x interrupt controller tables for sh_intc.c +/* +* sh775x interrupt controller tables for sh_intc.c * stolen from linux/arch/sh/kernel/cpu/sh4/setup-sh7750.c */
@@ -642,9 +644,9 @@ static struct intc_group groups_irl[] = { IRL_7, IRL_8, IRL_9, IRL_A, IRL_B, IRL_C, IRL_D, IRL_E), }; -/********************************************************************** -Memory mapped cache and TLB -**********************************************************************/ +/* +* Memory mapped cache and TLB +*/ #define MM_REGION_MASK 0x07000000#define MM_ICACHE_ADDR (0)
hw/sh4/sh7750_regs.h +252 -252
712 lines not on this page · raw message
hw/sh4/shix.c +5 -5
@@ -22,11 +22,11 @@* THE SOFTWARE. */ /* -Shix 2.0 board by Alexis Polti, described at -https://web.archive.org/web/20070917001736/perso.enst.fr/~polti/realisations/shix20 - -More information in target/sh4/README.sh4 -*/ +* Shix 2.0 board by Alexis Polti, described at +* https://web.archive.org/web/20070917001736/perso.enst.fr/~polti/realisations/shix20 +* +* More information in target/sh4/README.sh4 +*/ #include "qemu/osdep.h" #include "qapi/error.h" #include "cpu.h"
hw/timer/sh_timer.c +4 -3
@@ -104,9 +104,10 @@ static void sh_timer_write(void *opaque, hwaddr offset,case OFFSET_TCR :ptimer_transaction_begin (s->timer);if (s->enabled) { -/* Pause the timer if it is running. This may cause some -inaccuracy dure to rounding, but avoids a whole lot of other -messyness. */ +/* +* Pause the timer if it is running. This may cause some inaccuracy +* dure to rounding, but avoids a whole lot of other messyness +*/ ptimer_stop (s->timer); } freq = s->freq;
Signature · 1 line
2.21.4
PATCH v6 3/30 hw/sh4: Coding style: White space fixes
In reply to BALATON Zoltan--- hw/char/sh_serial.c | 23 ++++++++++------------- hw/intc/sh_intc.c | 39 +++++++++++++++++++++++---------------- hw/pci-host/sh_pci.c | 10 ++++------ hw/sh4/r2d.c | 39 ++++++++++++++++++++------------------- hw/sh4/sh7750.c | 26 +++++++++++++------------- hw/sh4/sh7750_regnames.c | 5 +++-- hw/sh4/sh7750_regs.h | 18 +++++++++--------- hw/sh4/shix.c | 2 +- hw/timer/sh_timer.c | 22 ++++++++++++++++------ include/hw/sh4/sh.h | 10 +++++----- 10 files changed, 104 insertions(+), 90 deletions(-)
hw/char/sh_serial.c +10 -13
@@ -75,7 +75,7 @@ typedef struct {qemu_irq bri; } sh_serial_state; -static void sh_serial_clear_fifo (sh_serial_state * s) +static void sh_serial_clear_fifo (sh_serial_state *s) {memset (s->rx_fifo,0 ,SH_RX_FIFO_LENGTH ); s->rx_cnt =0 ;
@@ -93,7 +93,7 @@ static void sh_serial_write(void *opaque, hwaddr offs,printf ("sh_serial: write offs=0x%02x val=0x%02x\n" , offs, val);#endif -switch (offs) { +switch (offs) {case 0x00 :/* SMR */ s->smr = val & ((s->feat &SH_SERIAL_FEAT_SCIF ) ?0x7b :0xff );return ;
@@ -131,7 +131,7 @@ static void sh_serial_write(void *opaque, hwaddr offs,#endif }if (s->feat &SH_SERIAL_FEAT_SCIF ) { -switch (offs) { +switch (offs) {case 0x10 :/* FSR */ if (!(val & (1 <<6 ))) s->flags &= ~SH_SERIAL_FLAG_TEND ;
@@ -178,9 +178,8 @@ static void sh_serial_write(void *opaque, hwaddr offs,case 0x24 :/* LSR */ return ; } - } -else { -switch (offs) { + }else { +switch (offs) {#if 0 case 0x0c : ret = s->dr;
@@ -207,7 +206,7 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs,uint32_t ret = ~0 ;#if 0 -switch (offs) { +switch (offs) {case 0x00 : ret = s->smr;break ;
@@ -223,7 +222,7 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs, }#endif if (s->feat &SH_SERIAL_FEAT_SCIF ) { -switch (offs) { +switch (offs) {case 0x00 :/* SMR */ ret = s->smr;break ;
@@ -270,9 +269,8 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs, ret =0 ;break ; } - } -else { -switch (offs) { + }else { +switch (offs) {#if 0 case 0x0c : ret = s->dr;
@@ -397,8 +395,7 @@ void sh_serial_init(MemoryRegion *sysmem,if (feat &SH_SERIAL_FEAT_SCIF ) { s->fcr =0 ; - } -else { + }else { s->dr =0xff ; }
hw/intc/sh_intc.c +23 -16
@@ -71,18 +71,18 @@ void sh_intc_toggle_source(struct intc_source *source, enable_changed ==-1 ?"disabled " :"" , source->pending ? "pending" : "");#endif - } + } } -static void sh_intc_set_irq (void *opaque,int n,int level) +static void sh_intc_set_irq (void *opaque,int n,int level) { -struct intc_desc *desc = opaque; -struct intc_source *source = &(desc->sources[n]); +struct intc_desc *desc = opaque; +struct intc_source *source = &(desc->sources[n]); -if (level && !source->asserted) -sh_intc_toggle_source (source,0 ,1 ); -else if (!level && source->asserted) -sh_intc_toggle_source (source,0 ,-1 ); +if (level && !source->asserted) +sh_intc_toggle_source (source,0 ,1 ); +else if (!level && source->asserted) +sh_intc_toggle_source (source,0 ,-1 ); }int sh_intc_get_pending_vector (struct intc_desc *desc,int imask)
@@ -236,7 +236,7 @@ static uint64_t sh_intc_read(void *opaque, hwaddr offset,printf ("sh_intc_read 0x%lx\n" , (unsigned long ) offset);#endif -sh_intc_locate (desc, (unsigned long )offset, &valuep, +sh_intc_locate (desc, (unsigned long )offset, &valuep, &enum_ids, &first, &width, &mode);return *valuep; }
@@ -257,14 +257,20 @@ static void sh_intc_write(void *opaque, hwaddr offset,printf ("sh_intc_write 0x%lx 0x%08x\n" , (unsigned long ) offset, value);#endif -sh_intc_locate (desc, (unsigned long )offset, &valuep, +sh_intc_locate (desc, (unsigned long )offset, &valuep, &enum_ids, &first, &width, &mode);switch (mode) { -case INTC_MODE_ENABLE_REG |INTC_MODE_IS_PRIO :break ; -case INTC_MODE_DUAL_SET : value |= *valuep;break ; -case INTC_MODE_DUAL_CLR : value = *valuep & ~value;break ; -default :abort (); +case INTC_MODE_ENABLE_REG |INTC_MODE_IS_PRIO : +break ; +case INTC_MODE_DUAL_SET : + value |= *valuep; +break ; +case INTC_MODE_DUAL_CLR : + value = *valuep & ~value; +break ; +default : +abort (); }for (k =0 ; k <= first; k++) {
@@ -465,7 +471,7 @@ int sh_intc_init(MemoryRegion *sysmem, } desc->irqs =qemu_allocate_irqs (sh_intc_set_irq, desc, nr_sources); - +memory_region_init_io (&desc->iomem,NULL , &sh_intc_ops, desc,"interrupt-controller" ,0x100000000ULL );
@@ -507,7 +513,8 @@ void sh_intc_set_irl(void *opaque, int n, int level)int i, irl = level ^15 ;for (i =0 ; (s =sh_intc_source (s->parent, s->next_enum_id)); i++) {if (i == irl) -sh_intc_toggle_source (s, s->enable_count?0 :1 , s->asserted?0 :1 ); +sh_intc_toggle_source (s, s->enable_count ?0 :1 , + s->asserted ?0 :1 );else if (s->asserted)sh_intc_toggle_source (s,0 ,-1 );
hw/pci-host/sh_pci.c +4 -6
@@ -49,13 +49,12 @@ struct SHPCIState {uint32_t iobr; }; -static void sh_pci_reg_write (void *p,hwaddr addr,uint64_t val, -unsigned size) +static void sh_pci_reg_write (void *p,hwaddr addr,uint64_t val,unsigned size) {SHPCIState *pcic = p;PCIHostState *phb =PCI_HOST_BRIDGE (pcic); -switch (addr) { +switch (addr) { case 0 ... 0xfc:stl_le_p (pcic->dev->config + addr, val);break ;
@@ -75,13 +74,12 @@ static void sh_pci_reg_write (void *p, hwaddr addr, uint64_t val, } } -static uint64_t sh_pci_reg_read (void *p,hwaddr addr, -unsigned size) +static uint64_t sh_pci_reg_read (void *p,hwaddr addr,unsigned size) {SHPCIState *pcic = p;PCIHostState *phb =PCI_HOST_BRIDGE (pcic); -switch (addr) { +switch (addr) { case 0 ... 0xfc:return ldl_le_p (pcic->dev->config + addr);case 0x1c0 :
hw/sh4/r2d.c +20 -19
@@ -96,19 +96,19 @@ enum r2d_fpga_irq { };static const struct {short irl;uint16_t msk; } irqtab[NR_IRQS ] = { - [CF_IDE ] = {1 ,1 <<9 }, - [CF_CD ] = {2 ,1 <<8 }, - [PCI_INTA ] = {9 ,1 <<14 }, - [PCI_INTB ] = {10 ,1 <<13 }, - [PCI_INTC ] = {3 ,1 <<12 }, - [PCI_INTD ] = {0 ,1 <<11 }, - [SM501 ] = {4 ,1 <<10 }, - [KEY ] = {5 ,1 <<6 }, - [RTC_A ] = {6 ,1 <<5 }, - [RTC_T ] = {7 ,1 <<4 }, - [SDCARD ] = {8 ,1 <<7 }, - [EXT ] = {11 ,1 <<0 }, - [TP ] = {12 ,1 <<15 }, + [CF_IDE ] = {1 ,1 <<9 }, + [CF_CD ] = {2 ,1 <<8 }, + [PCI_INTA ] = {9 ,1 <<14 }, + [PCI_INTB ] = {10 ,1 <<13 }, + [PCI_INTC ] = {3 ,1 <<12 }, + [PCI_INTD ] = {0 ,1 <<11 }, + [SM501 ] = {4 ,1 <<10 }, + [KEY ] = {5 ,1 <<6 }, + [RTC_A ] = {6 ,1 <<5 }, + [RTC_T ] = {7 ,1 <<4 }, + [SDCARD ] = {8 ,1 <<7 }, + [EXT ] = {11 ,1 <<0 }, + [TP ] = {12 ,1 <<15 }, };static void update_irl (r2d_fpga_t *fpga)
@@ -306,7 +306,7 @@ static void r2d_init(MachineState *machine)/* NIC: rtl8139 on-board, and 2 slots. */ for (i =0 ; i < nb_nics; i++)pci_nic_init_nofail (&nd_table[i], pci_bus, -"rtl8139" , i==0 ?"2" :NULL ); +"rtl8139" , i ==0 ?"2" :NULL );/* USB keyboard */ usb_create_simple (usb_bus_find (-1 ),"usb-kbd" );
@@ -321,8 +321,8 @@ static void r2d_init(MachineState *machine)SDRAM_BASE +LINUX_LOAD_OFFSET , INITRD_LOAD_OFFSET - LINUX_LOAD_OFFSET);if (kernel_size <0 ) { -fprintf (stderr,"qemu: could not load kernel '%s'\n" , kernel_filename); -exit (1 ); +fprintf (stderr,"qemu: could not load kernel '%s'\n" , kernel_filename); +exit (1 ); }/* initialization which should be done by firmware */
@@ -330,7 +330,8 @@ static void r2d_init(MachineState *machine) MEMTXATTRS_UNSPECIFIED, NULL); /* cs3 SDRAM */address_space_stw (&address_space_memory,SH7750_BCR2 ,3 << (3 *2 ),MEMTXATTRS_UNSPECIFIED ,NULL );/* cs3 32bit */ - reset_info->vector = (SDRAM_BASE +LINUX_LOAD_OFFSET ) |0xa0000000 ;/* Start from P2 area */ +/* Start from P2 area */ + reset_info->vector = (SDRAM_BASE +LINUX_LOAD_OFFSET ) |0xa0000000 ; }if (initrd_filename) {
@@ -341,8 +342,8 @@ static void r2d_init(MachineState *machine) SDRAM_SIZE - INITRD_LOAD_OFFSET);if (initrd_size <0 ) { -fprintf (stderr,"qemu: could not load initrd '%s'\n" , initrd_filename); -exit (1 ); +fprintf (stderr,"qemu: could not load initrd '%s'\n" , initrd_filename); +exit (1 ); }/* initialization which should be done by firmware */
hw/sh4/sh7750.c +13 -13
@@ -78,7 +78,7 @@ typedef struct SH7750State {struct intc_desc intc; } SH7750State; -static inline int has_bcr3_and_bcr4 (SH7750State * s) +static inline int has_bcr3_and_bcr4 (SH7750State *s) {return s->cpu->env.features &SH_FEATURE_BCR3_AND_BCR4 ; }
@@ -87,7 +87,7 @@ static inline int has_bcr3_and_bcr4(SH7750State * s)* I/O ports */ -int sh7750_register_io_device (SH7750State * s,sh7750_io_device * device) +int sh7750_register_io_device (SH7750State *s,sh7750_io_device *device) {int i;
@@ -102,7 +102,7 @@ int sh7750_register_io_device(SH7750State * s, sh7750_io_device * device)static uint16_t portdir (uint32_t v) { -#define EVENPORTMASK (n) ((v & (1<<((n)<<1))) >> (n)) +#define EVENPORTMASK (n) ((v & (1 << ((n) << 1))) >> (n))return EVENPORTMASK (15 ) |EVENPORTMASK (14 ) |EVENPORTMASK (13 ) | EVENPORTMASK(12) | EVENPORTMASK(11) | EVENPORTMASK(10) |
@@ -114,7 +114,7 @@ static uint16_t portdir(uint32_t v)static uint16_t portpullup (uint32_t v) { -#define ODDPORTMASK (n) ((v & (1<<(((n)<<1)+1))) >> (n)) +#define ODDPORTMASK (n) ((v & (1 << (((n) << 1) + 1))) >> (n))return ODDPORTMASK (15 ) |ODDPORTMASK (14 ) |ODDPORTMASK (13 ) | ODDPORTMASK(12) | ODDPORTMASK(11) | ODDPORTMASK(10) |
@@ -123,26 +123,26 @@ static uint16_t portpullup(uint32_t v)ODDPORTMASK (1 ) |ODDPORTMASK (0 ); } -static uint16_t porta_lines (SH7750State * s) +static uint16_t porta_lines (SH7750State *s) {return (s->portdira & s->pdtra) |/* CPU */ (s->periph_portdira & s->periph_pdtra) |/* Peripherals */ (~(s->portdira | s->periph_portdira) & s->portpullupa);/* Pullups */ } -static uint16_t portb_lines (SH7750State * s) +static uint16_t portb_lines (SH7750State *s) {return (s->portdirb & s->pdtrb) |/* CPU */ (s->periph_portdirb & s->periph_pdtrb) |/* Peripherals */ (~(s->portdirb | s->periph_portdirb) & s->portpullupb);/* Pullups */ } -static void gen_port_interrupts (SH7750State * s) +static void gen_port_interrupts (SH7750State *s) {/* XXXXX interrupts not generated */ } -static void porta_changed (SH7750State * s,uint16_t prev) +static void porta_changed (SH7750State *s,uint16_t prev) {uint16_t currenta, changes;int i, r =0 ;
@@ -171,7 +171,7 @@ static void porta_changed(SH7750State * s, uint16_t prev)gen_port_interrupts (s); } -static void portb_changed (SH7750State * s,uint16_t prev) +static void portb_changed (SH7750State *s,uint16_t prev) {uint16_t currentb, changes;int i, r =0 ;
@@ -228,7 +228,7 @@ static uint32_t sh7750_mem_readw(void *opaque, hwaddr addr)case SH7750_BCR2_A7 :return s->bcr2;case SH7750_BCR3_A7 : -if (!has_bcr3_and_bcr4 (s)) +if (!has_bcr3_and_bcr4 (s))error_access ("word read" , addr);return s->bcr3;case SH7750_FRQCR_A7 :
@@ -263,7 +263,7 @@ static uint32_t sh7750_mem_readl(void *opaque, hwaddr addr)case SH7750_BCR1_A7 :return s->bcr1;case SH7750_BCR4_A7 : -if (!has_bcr3_and_bcr4 (s)) +if (!has_bcr3_and_bcr4 (s))error_access ("long read" , addr);return s->bcr4;case SH7750_WCR1_A7 :
@@ -332,7 +332,7 @@ static void sh7750_mem_writew(void *opaque, hwaddr addr, s->bcr2 = mem_value;return ;case SH7750_BCR3_A7 : -if (!has_bcr3_and_bcr4 (s)) +if (!has_bcr3_and_bcr4 (s))error_access ("word write" , addr); s->bcr3 = mem_value;return ;
@@ -384,7 +384,7 @@ static void sh7750_mem_writel(void *opaque, hwaddr addr, s->bcr1 = mem_value;return ;case SH7750_BCR4_A7 : -if (!has_bcr3_and_bcr4 (s)) +if (!has_bcr3_and_bcr4 (s))error_access ("long write" , addr); s->bcr4 = mem_value;return ;
hw/sh4/sh7750_regnames.c +3 -2
@@ -81,14 +81,15 @@ static regname_t regnames[] = {REGNAME (SH7750_BCR3_A7)REGNAME (SH7750_BCR4_A7 )REGNAME (SH7750_SDMR2_A7 ) - REGNAME(SH7750_SDMR3_A7) {(uint32_t) - 1, NULL} +REGNAME (SH7750_SDMR3_A7 ) + { (uint32_t)-1, NULL } };const char *regname (uint32_t addr) {unsigned int i; -for (i =0 ; regnames[i].regaddr != (uint32_t ) -1 ; i++) { +for (i =0 ; regnames[i].regaddr != (uint32_t )-1 ; i++) {if (regnames[i].regaddr == addr)return regnames[i].regname; }
hw/sh4/sh7750_regs.h +9 -9
@@ -1015,7 +1015,7 @@*/ /* DMA Source Address Register - SAR0, SAR1, SAR2, SAR3 */ -#define SH7750_SAR_REGOFS (n) (0xA00000 + ((n)*16))/* offset */ +#define SH7750_SAR_REGOFS (n) (0xA00000 + ((n) * 16))/* offset */ #define SH7750_SAR (n) SH7750_P4_REG32(SH7750_SAR_REGOFS(n))#define SH7750_SAR_A7 (n) SH7750_A7_REG32(SH7750_SAR_REGOFS(n))#define SH7750_SAR0 SH7750_SAR(0)
@@ -1028,7 +1028,7 @@#define SH7750_SAR3_A7 SH7750_SAR_A7(3)/* DMA Destination Address Register - DAR0, DAR1, DAR2, DAR3 */ -#define SH7750_DAR_REGOFS (n) (0xA00004 + ((n)*16))/* offset */ +#define SH7750_DAR_REGOFS (n) (0xA00004 + ((n) * 16))/* offset */ #define SH7750_DAR (n) SH7750_P4_REG32(SH7750_DAR_REGOFS(n))#define SH7750_DAR_A7 (n) SH7750_A7_REG32(SH7750_DAR_REGOFS(n))#define SH7750_DAR0 SH7750_DAR(0)
@@ -1041,7 +1041,7 @@#define SH7750_DAR3_A7 SH7750_DAR_A7(3)/* DMA Transfer Count Register - DMATCR0, DMATCR1, DMATCR2, DMATCR3 */ -#define SH7750_DMATCR_REGOFS (n) (0xA00008 + ((n)*16))/* offset */ +#define SH7750_DMATCR_REGOFS (n) (0xA00008 + ((n) * 16))/* offset */ #define SH7750_DMATCR (n) SH7750_P4_REG32(SH7750_DMATCR_REGOFS(n))#define SH7750_DMATCR_A7 (n) SH7750_A7_REG32(SH7750_DMATCR_REGOFS(n))#define SH7750_DMATCR0_P4 SH7750_DMATCR(0)
@@ -1054,7 +1054,7 @@#define SH7750_DMATCR3_A7 SH7750_DMATCR_A7(3)/* DMA Channel Control Register - CHCR0, CHCR1, CHCR2, CHCR3 */ -#define SH7750_CHCR_REGOFS (n) (0xA0000C + ((n)*16))/* offset */ +#define SH7750_CHCR_REGOFS (n) (0xA0000C + ((n) * 16))/* offset */ #define SH7750_CHCR (n) SH7750_P4_REG32(SH7750_CHCR_REGOFS(n))#define SH7750_CHCR_A7 (n) SH7750_A7_REG32(SH7750_CHCR_REGOFS(n))#define SH7750_CHCR0 SH7750_CHCR(0)
@@ -1208,9 +1208,9 @@#define SH7750_PCTRA_A7 SH7750_A7_REG32(SH7750_PCTRA_REGOFS)#define SH7750_PCTRA_PBPUP (n) 0/* Bit n is pulled up */ -#define SH7750_PCTRA_PBNPUP (n) (1 << ((n)*2+1))/* Bit n is not pulled up */ +#define SH7750_PCTRA_PBNPUP (n) (1 << ((n) * 2 + 1))/* Bit n is not pulled up */ #define SH7750_PCTRA_PBINP (n) 0/* Bit n is an input */ -#define SH7750_PCTRA_PBOUT (n) (1 << ((n)*2))/* Bit n is an output */ +#define SH7750_PCTRA_PBOUT (n) (1 << ((n) * 2))/* Bit n is an output */ /* Port Data Register A - PDTRA(half) */ #define SH7750_PDTRA_REGOFS 0x800030/* offset */
@@ -1225,16 +1225,16 @@#define SH7750_PCTRB_A7 SH7750_A7_REG32(SH7750_PCTRB_REGOFS)#define SH7750_PCTRB_PBPUP (n) 0/* Bit n is pulled up */ -#define SH7750_PCTRB_PBNPUP (n) (1 << ((n-16)*2+1))/* Bit n is not pulled up */ +#define SH7750_PCTRB_PBNPUP (n) (1 << ((n - 16) * 2 + 1))/* Bit n is not pulled up */ #define SH7750_PCTRB_PBINP (n) 0/* Bit n is an input */ -#define SH7750_PCTRB_PBOUT (n) (1 << ((n-16)*2))/* Bit n is an output */ +#define SH7750_PCTRB_PBOUT (n) (1 << ((n - 16) * 2))/* Bit n is an output */ /* Port Data Register B - PDTRB(half) */ #define SH7750_PDTRB_REGOFS 0x800044/* offset */ #define SH7750_PDTRB SH7750_P4_REG32(SH7750_PDTRB_REGOFS)#define SH7750_PDTRB_A7 SH7750_A7_REG32(SH7750_PDTRB_REGOFS) -#define SH7750_PDTRB_BIT (n) (1 << ((n)-16)) +#define SH7750_PDTRB_BIT (n) (1 << ((n) - 16))/* GPIO Interrupt Control Register - GPIOIC(half) */ #define SH7750_GPIOIC_REGOFS 0x800048/* offset */
hw/sh4/shix.c +1 -1
@@ -48,7 +48,7 @@ static void shix_init(MachineState *machine)MemoryRegion *rom =g_new (MemoryRegion,1 );MemoryRegion *sdram =g_new (MemoryRegion,2 );const char *bios_name = machine->firmware ?:BIOS_FILENAME ; - + cpu =SUPERH_CPU (cpu_create (machine->cpu_type));/* Allocate memory space */
hw/timer/sh_timer.c +16 -6
@@ -55,7 +55,7 @@ static void sh_timer_update(sh_timer_state *s)int new_level = s->int_level && (s->tcr &TIMER_TCR_UNIE );if (new_level != s->old_level) -qemu_set_irq (s->irq, new_level); +qemu_set_irq (s->irq, new_level); s->old_level = s->int_level; s->int_level = new_level;
@@ -113,11 +113,21 @@ static void sh_timer_write(void *opaque, hwaddr offset, freq = s->freq;/* ??? Need to recalculate expiry time after changing divisor. */ switch (value &TIMER_TCR_TPSC ) { -case 0 : freq >>=2 ;break ; -case 1 : freq >>=4 ;break ; -case 2 : freq >>=6 ;break ; -case 3 : freq >>=8 ;break ; -case 4 : freq >>=10 ;break ; +case 0 : + freq >>=2 ; +break ; +case 1 : + freq >>=4 ; +break ; +case 2 : + freq >>=6 ; +break ; +case 3 : + freq >>=8 ; +break ; +case 4 : + freq >>=10 ; +break ;case 6 :case 7 :if (s->feat &TIMER_FEAT_EXTCLK ) {
include/hw/sh4/sh.h +5 -5
@@ -44,14 +44,14 @@ typedef struct {uint16_t portbmask_trigger;/* Return 0 if no action was taken */ int (*port_change_cb) (uint16_t porta,uint16_t portb, -uint16_t * periph_pdtra, -uint16_t * periph_portdira, -uint16_t * periph_pdtrb, -uint16_t * periph_portdirb); +uint16_t *periph_pdtra, +uint16_t *periph_portdira, +uint16_t *periph_pdtrb, +uint16_t *periph_portdirb); } sh7750_io_device;int sh7750_register_io_device (struct SH7750State *s, -sh7750_io_device * device); +sh7750_io_device *device);/* sh_serial.c */ #define SH_SERIAL_FEAT_SCIF (1 << 0)
Signature · 1 line
2.21.4
PATCH v6 4/30 hw/sh4: Coding style: Add missing braces
In reply to BALATON Zoltan--- hw/char/sh_serial.c | 48 ++++++++++++++-------- hw/intc/sh_intc.c | 87 ++++++++++++++++++++++------------------ hw/sh4/r2d.c | 15 ++++--- hw/sh4/sh7750.c | 24 +++++++---- hw/sh4/sh7750_regnames.c | 3 +- hw/timer/sh_timer.c | 22 +++++----- 6 files changed, 118 insertions(+), 81 deletions(-)
hw/char/sh_serial.c +32 -16
@@ -103,8 +103,9 @@ static void sh_serial_write(void *opaque, hwaddr offs,case 0x08 :/* SCR */ /* TODO : For SH7751, SCIF mask should be 0xfb. */ s->scr = val & ((s->feat &SH_SERIAL_FEAT_SCIF ) ?0xfa :0xff ); -if (!(val & (1 <<5 ))) +if (!(val & (1 <<5 ))) { s->flags |=SH_SERIAL_FLAG_TEND ; + }if ((s->feat &SH_SERIAL_FEAT_SCIF ) && s->txi) {qemu_set_irq (s->txi, val & (1 <<7 )); }
@@ -133,16 +134,21 @@ static void sh_serial_write(void *opaque, hwaddr offs,if (s->feat &SH_SERIAL_FEAT_SCIF ) {switch (offs) {case 0x10 :/* FSR */ -if (!(val & (1 <<6 ))) +if (!(val & (1 <<6 ))) { s->flags &= ~SH_SERIAL_FLAG_TEND ; -if (!(val & (1 <<5 ))) + } +if (!(val & (1 <<5 ))) { s->flags &= ~SH_SERIAL_FLAG_TDE ; -if (!(val & (1 <<4 ))) + } +if (!(val & (1 <<4 ))) { s->flags &= ~SH_SERIAL_FLAG_BRK ; -if (!(val & (1 <<1 ))) + } +if (!(val & (1 <<1 ))) { s->flags &= ~SH_SERIAL_FLAG_RDF ; -if (!(val & (1 <<0 ))) + } +if (!(val & (1 <<0 ))) { s->flags &= ~SH_SERIAL_FLAG_DR ; + }if (!(val & (1 <<1 )) || !(val & (1 <<0 ))) {if (s->rxi) {
@@ -231,29 +237,37 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs,break ;case 0x10 :/* FSR */ ret =0 ; -if (s->flags &SH_SERIAL_FLAG_TEND ) +if (s->flags &SH_SERIAL_FLAG_TEND ) { ret |= (1 <<6 ); -if (s->flags &SH_SERIAL_FLAG_TDE ) + } +if (s->flags &SH_SERIAL_FLAG_TDE ) { ret |= (1 <<5 ); -if (s->flags &SH_SERIAL_FLAG_BRK ) + } +if (s->flags &SH_SERIAL_FLAG_BRK ) { ret |= (1 <<4 ); -if (s->flags &SH_SERIAL_FLAG_RDF ) + } +if (s->flags &SH_SERIAL_FLAG_RDF ) { ret |= (1 <<1 ); -if (s->flags &SH_SERIAL_FLAG_DR ) + } +if (s->flags &SH_SERIAL_FLAG_DR ) { ret |= (1 <<0 ); + } -if (s->scr & (1 <<5 )) +if (s->scr & (1 <<5 )) { s->flags |=SH_SERIAL_FLAG_TDE |SH_SERIAL_FLAG_TEND ; + }break ;case 0x14 :if (s->rx_cnt >0 ) { ret = s->rx_fifo[s->rx_tail++]; s->rx_cnt--; -if (s->rx_tail ==SH_RX_FIFO_LENGTH ) +if (s->rx_tail ==SH_RX_FIFO_LENGTH ) { s->rx_tail =0 ; -if (s->rx_cnt < s->rtrg) + } +if (s->rx_cnt < s->rtrg) { s->flags &= ~SH_SERIAL_FLAG_RDF ; + } }break ;case 0x18 :
@@ -308,8 +322,9 @@ static int sh_serial_can_receive(sh_serial_state *s)static void sh_serial_receive_break (sh_serial_state *s) { -if (s->feat &SH_SERIAL_FEAT_SCIF ) +if (s->feat &SH_SERIAL_FEAT_SCIF ) { s->sr |= (1 <<4 ); + } }static int sh_serial_can_receive1 (void *opaque)
@@ -361,8 +376,9 @@ static void sh_serial_receive1(void *opaque, const uint8_t *buf, int size)static void sh_serial_event (void *opaque,QEMUChrEvent event) {sh_serial_state *s = opaque; -if (event ==CHR_EVENT_BREAK ) +if (event ==CHR_EVENT_BREAK ) {sh_serial_receive_break (s); + } }static const MemoryRegionOps sh_serial_ops = {
hw/intc/sh_intc.c +47 -40
205 lines not on this page · raw message
hw/sh4/r2d.c +9 -6
@@ -114,20 +114,23 @@ static const struct { short irl; uint16_t msk; } irqtab[NR_IRQS] = {static void update_irl (r2d_fpga_t *fpga) {int i, irl =15 ; -for (i =0 ; i <NR_IRQS ; i++) -if (fpga->irlmon & fpga->irlmsk & irqtab[i].msk) -if (irqtab[i].irl < irl) - irl = irqtab[i].irl; +for (i =0 ; i <NR_IRQS ; i++) { +if ((fpga->irlmon & fpga->irlmsk & irqtab[i].msk) && + irqtab[i].irl < irl) { + irl = irqtab[i].irl; + } + }qemu_set_irq (fpga->irl, irl ^15 ); }static void r2d_fpga_irq_set (void *opaque,int n,int level) {r2d_fpga_t *fpga = opaque; -if (level) +if (level) { fpga->irlmon |= irqtab[n].msk; -else + }else { fpga->irlmon &= ~irqtab[n].msk; + }update_irl (fpga); }
hw/sh4/sh7750.c +16 -8
@@ -153,8 +153,9 @@ static void porta_changed(SH7750State *s, uint16_t prev)fprintf (stderr,"pdtra=0x%04x, pctra=0x%08x\n" , s->pdtra, s->pctra);#endif currenta =porta_lines (s); -if (currenta == prev) +if (currenta == prev) {return ; + } changes = currenta ^ prev;for (i =0 ; i <NB_DEVICES ; i++) {
@@ -167,8 +168,9 @@ static void porta_changed(SH7750State *s, uint16_t prev) } } -if (r) +if (r) {gen_port_interrupts (s); + } }static void portb_changed (SH7750State *s,uint16_t prev)
@@ -177,8 +179,9 @@ static void portb_changed(SH7750State *s, uint16_t prev)int i, r =0 ; currentb =portb_lines (s); -if (currentb == prev) +if (currentb == prev) {return ; + } changes = currentb ^ prev;for (i =0 ; i <NB_DEVICES ; i++) {
@@ -191,8 +194,9 @@ static void portb_changed(SH7750State *s, uint16_t prev) } } -if (r) +if (r) {gen_port_interrupts (s); + } }/*
@@ -228,8 +232,9 @@ static uint32_t sh7750_mem_readw(void *opaque, hwaddr addr)case SH7750_BCR2_A7 :return s->bcr2;case SH7750_BCR3_A7 : -if (!has_bcr3_and_bcr4 (s)) +if (!has_bcr3_and_bcr4 (s)) {error_access ("word read" , addr); + }return s->bcr3;case SH7750_FRQCR_A7 :return 0 ;
@@ -263,8 +268,9 @@ static uint32_t sh7750_mem_readl(void *opaque, hwaddr addr)case SH7750_BCR1_A7 :return s->bcr1;case SH7750_BCR4_A7 : -if (!has_bcr3_and_bcr4 (s)) +if (!has_bcr3_and_bcr4 (s)) {error_access ("long read" , addr); + }return s->bcr4;case SH7750_WCR1_A7 :case SH7750_WCR2_A7 :
@@ -332,8 +338,9 @@ static void sh7750_mem_writew(void *opaque, hwaddr addr, s->bcr2 = mem_value;return ;case SH7750_BCR3_A7 : -if (!has_bcr3_and_bcr4 (s)) +if (!has_bcr3_and_bcr4 (s)) {error_access ("word write" , addr); + } s->bcr3 = mem_value;return ;case SH7750_PCR_A7 :
@@ -384,8 +391,9 @@ static void sh7750_mem_writel(void *opaque, hwaddr addr, s->bcr1 = mem_value;return ;case SH7750_BCR4_A7 : -if (!has_bcr3_and_bcr4 (s)) +if (!has_bcr3_and_bcr4 (s)) {error_access ("long write" , addr); + } s->bcr4 = mem_value;return ;case SH7750_WCR1_A7 :
hw/sh4/sh7750_regnames.c +2 -1
@@ -90,8 +90,9 @@ const char *regname(uint32_t addr)unsigned int i;for (i =0 ; regnames[i].regaddr != (uint32_t )-1 ; i++) { -if (regnames[i].regaddr == addr) +if (regnames[i].regaddr == addr) {return regnames[i].regname; + } }return "<unknown reg>" ;
hw/timer/sh_timer.c +12 -10
@@ -54,9 +54,9 @@ static void sh_timer_update(sh_timer_state *s) {int new_level = s->int_level && (s->tcr &TIMER_TCR_UNIE ); -if (new_level != s->old_level) +if (new_level != s->old_level) {qemu_set_irq (s->irq, new_level); - + } s->old_level = s->int_level; s->int_level = new_level; }
@@ -73,8 +73,9 @@ static uint32_t sh_timer_read(void *opaque, hwaddr offset)case OFFSET_TCR :return s->tcr | (s->int_level ?TIMER_TCR_UNF :0 );case OFFSET_TCPR : -if (s->feat &TIMER_FEAT_CAPT ) +if (s->feat &TIMER_FEAT_CAPT ) {return s->tcpr; + }/* fall through */ default :hw_error ("sh_timer_read: Bad offset %x\n" , (int )offset);
@@ -279,17 +280,18 @@ static uint64_t tmu012_read(void *opaque, hwaddr offset,return sh_timer_read (s->timer[2 ], offset -0x20 ); } -if (offset >=0x14 ) +if (offset >=0x14 ) {return sh_timer_read (s->timer[1 ], offset -0x14 ); - -if (offset >=0x08 ) + } +if (offset >=0x08 ) {return sh_timer_read (s->timer[0 ], offset -0x08 ); - -if (offset ==4 ) + } +if (offset ==4 ) {return s->tstr; - -if ((s->feat &TMU012_FEAT_TOCR ) && offset ==0 ) + } +if ((s->feat &TMU012_FEAT_TOCR ) && offset ==0 ) {return s->tocr; + }hw_error ("tmu012_write: Bad offset %x\n" , (int )offset);return 0 ;
Signature · 1 line
2.21.4
PATCH v6 5/30 hw/sh4: Coding style: Remove unnecessary casts
In reply to BALATON Zoltan--- hw/timer/sh_timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/timer/sh_timer.c +2 -2
@@ -233,7 +233,7 @@ static void *sh_timer_init(uint32_t freq, int feat, qemu_irq irq) {sh_timer_state *s; - s = (sh_timer_state *)g_malloc0 (sizeof (sh_timer_state)); + s =g_malloc0 (sizeof (*s)); s->freq = freq; s->feat = feat; s->tcor =0xffffffff ;
@@ -358,7 +358,7 @@ void tmu012_init(MemoryRegion *sysmem, hwaddr base,tmu012_state *s;int timer_feat = (feat &TMU012_FEAT_EXTCLK ) ?TIMER_FEAT_EXTCLK :0 ; - s = (tmu012_state *)g_malloc0 (sizeof (tmu012_state)); + s =g_malloc0 (sizeof (*s)); s->feat = feat; s->timer[0 ] =sh_timer_init (freq, timer_feat, ch0_irq); s->timer[1 ] =sh_timer_init (freq, timer_feat, ch1_irq);
Signature · 1 line
2.21.4
PATCH v6 6/30 hw/sh4: Fix typos in a comment
In reply to BALATON Zoltan--- hw/timer/sh_timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/sh_timer.c +1 -1
@@ -107,7 +107,7 @@ static void sh_timer_write(void *opaque, hwaddr offset,if (s->enabled) {/* * Pause the timer if it is running. This may cause some inaccuracy -* dure to rounding, but avoids a whole lot of other messyness +* due to rounding, but avoids a whole lot of other messiness */ ptimer_stop (s->timer); }
Signature · 1 line
2.21.4
PATCH v6 7/30 hw/sh4: Change debug printfs to traces
In reply to BALATON Zoltan--- hw/char/sh_serial.c | 13 ++----- hw/char/trace-events | 4 +++ hw/intc/sh_intc.c | 79 +++++++++++-------------------------------- hw/intc/trace-events | 8 +++++ hw/sh4/sh7750.c | 8 ++--- hw/sh4/trace-events | 3 ++ hw/sh4/trace.h | 1 + hw/timer/sh_timer.c | 22 +++--------- hw/timer/trace-events | 5 +++ meson.build | 1 + 10 files changed, 52 insertions(+), 92 deletions(-) create mode 100644 hw/sh4/trace-events create mode 100644 hw/sh4/trace.h
hw/char/sh_serial.c +3 -10
@@ -31,8 +31,7 @@#include "chardev/char-fe.h" #include "qapi/error.h" #include "qemu/timer.h" - -//#define DEBUG_SERIAL +#include "trace.h" #define SH_SERIAL_FLAG_TEND (1 << 0)#define SH_SERIAL_FLAG_TDE (1 << 1)
@@ -89,10 +88,7 @@ static void sh_serial_write(void *opaque, hwaddr offs,sh_serial_state *s = opaque;unsigned char ch; -#ifdef DEBUG_SERIAL -printf ("sh_serial: write offs=0x%02x val=0x%02x\n" , - offs, val); -#endif +trace_sh_serial_write (size, offs, val);switch (offs) {case 0x00 :/* SMR */ s->smr = val & ((s->feat &SH_SERIAL_FEAT_SCIF ) ?0x7b :0xff );
@@ -301,10 +297,7 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs,break ; } } -#ifdef DEBUG_SERIAL -printf ("sh_serial: read offs=0x%02x val=0x%x\n" , - offs, ret); -#endif +trace_sh_serial_read (size, offs, ret);if (ret & ~((1 <<16 ) -1 )) { fprintf(stderr, "sh_serial: unsupported read from 0x%02"
hw/char/trace-events +4 -0
@@ -101,3 +101,7 @@ exynos_uart_rx_timeout(uint32_t channel, uint32_t stat, uint32_t intsp) "UART%d: # cadence_uart.c cadence_uart_baudrate(unsigned baudrate) "baudrate %u" + +# sh_serial.c +sh_serial_read(unsigned size, uint64_t offs, uint64_t val) " size %d offs 0x%02" PRIx64 " -> 0x%02" PRIx64 +sh_serial_write(unsigned size, uint64_t offs, uint64_t val) "size %d offs 0x%02" PRIx64 " <- 0x%02" PRIx64
hw/intc/sh_intc.c +20 -59
158 lines not on this page · raw message
hw/intc/trace-events +8 -0
@@ -238,3 +238,11 @@ goldfish_pic_write(void *dev, int idx, unsigned int addr, unsigned int size, uin goldfish_pic_reset(void *dev, int idx) "pic: %p goldfish-irq.%d" goldfish_pic_realize(void *dev, int idx) "pic: %p goldfish-irq.%d" goldfish_pic_instance_init(void *dev) "pic: %p goldfish-irq" + +# sh_intc.c +sh_intc_sources(int p, int a, int c, int m, unsigned short v, const char *s1, const char *s2, const char *s3) "(%d/%d/%d/%d) interrupt source 0x%x %s%s%s" +sh_intc_pending(int p, unsigned short v) "(%d) returning interrupt source 0x%x" +sh_intc_register(const char *s, int id, unsigned short v, int c, int m) "%s %d -> 0x%04x (%d/%d)" +sh_intc_read(unsigned size, uint64_t offset, unsigned long val) "size %d 0x%" PRIx64 " -> 0x%" PRIx64 +sh_intc_write(unsigned size, uint64_t offset, unsigned long val) "size %d 0x%" PRIx64 " <- 0x%" PRIx64 +sh_intc_set(int id, int enable) "setting interrupt group %d to %d"
hw/sh4/sh7750.c +3 -5
@@ -32,6 +32,7 @@#include "hw/sh4/sh_intc.h" #include "hw/timer/tmu012.h" #include "exec/exec-all.h" +#include "trace.h" #define NB_DEVICES 4
@@ -147,15 +148,11 @@ static void porta_changed(SH7750State *s, uint16_t prev)uint16_t currenta, changes;int i, r =0 ; -#if 0 -fprintf (stderr,"porta changed from 0x%04x to 0x%04x\n" , - prev,porta_lines (s)); -fprintf (stderr,"pdtra=0x%04x, pctra=0x%08x\n" , s->pdtra, s->pctra); -#endif currenta =porta_lines (s);if (currenta == prev) {return ; } +trace_sh7750_porta (prev, currenta, s->pdtra, s->pctra); changes = currenta ^ prev;for (i =0 ; i <NB_DEVICES ; i++) {
@@ -182,6 +179,7 @@ static void portb_changed(SH7750State *s, uint16_t prev)if (currentb == prev) {return ; } +trace_sh7750_portb (prev, currentb, s->pdtrb, s->pctrb); changes = currentb ^ prev;for (i =0 ; i <NB_DEVICES ; i++) {
hw/sh4/trace-events new file +3 -0
@@ -0,0 +1,3 @@ +# sh7750.c +sh7750_porta(uint16_t prev, uint16_t cur, uint16_t pdtr, uint16_t pctr) "porta changed from 0x%04x to 0x%04x\npdtra=0x%04x, pctra=0x%08x" +sh7750_portb(uint16_t prev, uint16_t cur, uint16_t pdtr, uint16_t pctr) "portb changed from 0x%04x to 0x%04x\npdtrb=0x%04x, pctrb=0x%08x"
hw/sh4/trace.h new file +1 -0
@@ -0,0 +1 @@ +#include "trace/trace-hw_sh4.h"
hw/timer/sh_timer.c +4 -18
@@ -15,8 +15,7 @@#include "hw/sh4/sh.h" #include "hw/timer/tmu012.h" #include "hw/ptimer.h" - -//#define DEBUG_TIMER +#include "trace.h" #define TIMER_TCR_TPSC (7 << 0)#define TIMER_TCR_CKEG (3 << 3)
@@ -203,10 +202,7 @@ static void sh_timer_start_stop(void *opaque, int enable) {sh_timer_state *s = (sh_timer_state *)opaque; -#ifdef DEBUG_TIMER -printf ("sh_timer_start_stop %d (%d)\n" , enable, s->enabled); -#endif - +trace_sh_timer_start_stop (enable, s->enabled);ptimer_transaction_begin (s->timer);if (s->enabled && !enable) {ptimer_stop (s->timer);
@@ -216,10 +212,6 @@ static void sh_timer_start_stop(void *opaque, int enable) }ptimer_transaction_commit (s->timer); s->enabled = !!enable; - -#ifdef DEBUG_TIMER -printf ("sh_timer_start_stop done %d\n" , s->enabled); -#endif }static void sh_timer_tick (void *opaque)
@@ -269,10 +261,7 @@ static uint64_t tmu012_read(void *opaque, hwaddr offset, {tmu012_state *s = (tmu012_state *)opaque; -#ifdef DEBUG_TIMER -printf ("tmu012_read 0x%lx\n" , (unsigned long ) offset); -#endif - +trace_sh_timer_read (offset);if (offset >=0x20 ) {if (!(s->feat &TMU012_FEAT_3CHAN )) {hw_error ("tmu012_write: Bad channel offset %x\n" , (int )offset);
@@ -302,10 +291,7 @@ static void tmu012_write(void *opaque, hwaddr offset, {tmu012_state *s = (tmu012_state *)opaque; -#ifdef DEBUG_TIMER -printf ("tmu012_write 0x%lx 0x%08x\n" , (unsigned long ) offset, value); -#endif - +trace_sh_timer_write (offset, value);if (offset >=0x20 ) {if (!(s->feat &TMU012_FEAT_3CHAN )) {hw_error ("tmu012_write: Bad channel offset %x\n" , (int )offset);
hw/timer/trace-events +5 -0
@@ -94,3 +94,8 @@ sifive_pwm_set_alarm(uint64_t alarm, uint64_t now) "Setting alarm to: 0x%" PRIx6 sifive_pwm_interrupt(int num) "Interrupt %d" sifive_pwm_read(uint64_t offset) "Read at address: 0x%" PRIx64 sifive_pwm_write(uint64_t data, uint64_t offset) "Write 0x%" PRIx64 " at address: 0x%" PRIx64 + +# sh_timer.c +sh_timer_start_stop(int enable, int current) "%d (%d)" +sh_timer_read(uint64_t offset) "tmu012_read 0x%" PRIx64 +sh_timer_write(uint64_t offset, uint64_t value) "tmu012_write 0x%" PRIx64 " 0x%08" PRIx64
meson.build +1 -0
@@ -2459,6 +2459,7 @@ if have_system 'hw/s390x', 'hw/scsi', 'hw/sd', + 'hw/sh4', 'hw/sparc', 'hw/sparc64', 'hw/ssi',
Signature · 1 line
2.21.4
Re: [PATCH v6 07/30] hw/sh4: Change debug printfs to traces
Quoted 194 lines · BALATON Zoltan
Signed-off-by BALATON Zoltan <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- hw/char/sh_serial.c | 13 ++----- hw/char/trace-events | 4 +++ hw/intc/sh_intc.c | 79 +++++++++++-------------------------------- hw/intc/trace-events | 8 +++++ hw/sh4/sh7750.c | 8 ++--- hw/sh4/trace-events | 3 ++ hw/sh4/trace.h | 1 + hw/timer/sh_timer.c | 22 +++--------- hw/timer/trace-events | 5 +++ meson.build | 1 + 10 files changed, 52 insertions(+), 92 deletions(-) create mode 100644 hw/sh4/trace-events create mode 100644 hw/sh4/trace.hhw/intc/sh_intc.c +20
-59@@ -9,13 +9,12 @@*/ #include "qemu/osdep.h" +#include "qemu/log.h" #include "cpu.h" #include "hw/sh4/sh_intc.h" #include "hw/irq.h" #include "hw/sh4/sh.h" - -//#define DEBUG_INTC -//#define DEBUG_INTC_SOURCES +#include "trace.h" #define INTC_A7 (x) ((x) & 0x1fffffff)@@ -57,20 +56,14 @@ void sh_intc_toggle_source(struct intc_source *source, } } -if (enable_changed || assert_adj || pending_changed) { -#ifdef DEBUG_INTC_SOURCES -printf ("sh_intc: (%d/%d/%d/%d) interrupt source 0x%x %s%s%s\n" , - source->parent->pending, - source->asserted, - source->enable_count, - source->enable_max, - source->vect, - source->asserted ?"asserted " : - assert_adj ?"deasserted" :"" , - enable_changed ==1 ?"enabled " : - enable_changed ==-1 ?"disabled " :"" , - source->pending ?"pending" :"" ); -#endif +if (enable_changed || assert_adj || pending_changed) { +trace_sh_intc_sources (source->parent->pending, source->asserted, + source->enable_count, source->enable_max, + source->vect, source->asserted ?"asserted " : + assert_adj ?"deasserted" :"" , + enable_changed ==1 ?"enabled " : + enable_changed ==-1 ?"disabled " :"" , + source->pending ?"pending" :"" ); } }@@ -101,10 +94,7 @@ int sh_intc_get_pending_vector(struct intc_desc *desc, int imask)struct intc_source *source = desc->sources + i;if (source->pending) { -#ifdef DEBUG_INTC_SOURCES -printf ("sh_intc: (%d) returning interrupt source 0x%x\n" , - desc->pending, source->vect); -#endif +trace_sh_intc_pending (desc->pending, source->vect);return source->vect; } }@@ -199,30 +189,22 @@ static void sh_intc_toggle_mask(struct intc_desc *desc, intc_enum id,return ; }if (!source->next_enum_id && (!source->enable_max || !source->vect)) { -#ifdef DEBUG_INTC_SOURCES -printf ("sh_intc: reserved interrupt source %d modified\n" , id); -#endif +qemu_log_mask (LOG_UNIMP , +"sh_intc: reserved interrupt source %d modified\n" , id);return ; }if (source->vect) {sh_intc_toggle_source (source, enable ?1 :-1 ,0 ); } -#ifdef DEBUG_INTC - else { -printf ("setting interrupt group %d to %d\n" , id, !!enable); - } -#endif if ((is_group || !source->vect) && source->next_enum_id) {sh_intc_toggle_mask (desc, source->next_enum_id, enable,1 ); } -#ifdef DEBUG_INTC if (!source->vect) { -printf ("setting interrupt group %d to %d - done\n" , id, !!enable); +trace_sh_intc_set (id, !!enable); } -#endif } static uint64_t sh_intc_read(void *opaque, hwaddr offset,@@ -235,12 +217,9 @@ static uint64_t sh_intc_read(void *opaque, hwaddr offset,unsigned int mode =0 ;unsigned long *valuep; -#ifdef DEBUG_INTC -printf ("sh_intc_read 0x%lx\n" , (unsigned long ) offset); -#endif -sh_intc_locate (desc, (unsigned long )offset, &valuep, &enum_ids, &first, &width, &mode); +trace_sh_intc_read (size, offset, *valuep);return *valuep; }@@ -256,13 +235,9 @@ static void sh_intc_write(void *opaque, hwaddr offset,unsigned long *valuep;unsigned long mask; -#ifdef DEBUG_INTC -printf ("sh_intc_write 0x%lx 0x%08x\n" , (unsigned long ) offset, value); -#endif - +trace_sh_intc_write (size, offset, value);sh_intc_locate (desc, (unsigned long )offset, &valuep, &enum_ids, &first, &width, &mode); -switch (mode) {case INTC_MODE_ENABLE_REG |INTC_MODE_IS_PRIO :break ;@@ -282,18 +257,10 @@ static void sh_intc_write(void *opaque, hwaddr offset,if ((*valuep & mask) == (value & mask)) {continue ; } -#if 0 -printf ("k = %d, first = %d, enum = %d, mask = 0x%08x\n" , - k, first, enum_ids[k], (unsigned int )mask); -#endif sh_intc_toggle_mask (desc, enum_ids[k], value & mask,0 ); } *valuep = value; - -#ifdef DEBUG_INTC -printf ("sh_intc_write 0x%lx -> 0x%08x\n" , (unsigned long ) offset, value); -#endif }static const MemoryRegionOps sh_intc_ops = {@@ -416,11 +383,8 @@ void sh_intc_register_sources(struct intc_desc *desc, s =sh_intc_source (desc, vect->enum_id);if (s) { s->vect = vect->vect; - -#ifdef DEBUG_INTC_SOURCES -printf ("sh_intc: registered source %d -> 0x%04x (%d/%d)\n" , - vect->enum_id, s->vect, s->enable_count, s->enable_max); -#endif +trace_sh_intc_register ("source" , vect->enum_id, s->vect, + s->enable_count, s->enable_max); } }@@ -438,11 +402,8 @@ void sh_intc_register_sources(struct intc_desc *desc, s =sh_intc_source (desc, gr->enum_ids[k -1 ]); s->next_enum_id = gr->enum_ids[k]; } - -#ifdef DEBUG_INTC_SOURCES -printf ("sh_intc: registered group %d (%d/%d)\n" , - gr->enum_id, s->enable_count, s->enable_max); -#endif +trace_sh_intc_register ("group" , gr->enum_id,0xffff , + s->enable_count, s->enable_max); } } }hw/intc/trace-events +0
-0@@ -238,3 +238,11 @@ goldfish_pic_write(void *dev, int idx, unsigned int addr, unsigned int size, uin goldfish_pic_reset(void *dev, int idx) "pic: %p goldfish-irq.%d"
hw/intc/trace-events goldfish_pic_write(void *dev, int idx, unsigned int addr, unsigned int size, uin · line 248
Quoted 10 lines
hw/intc/trace-events +8
-0goldfish_pic_realize(void *dev, int idx) "pic: %p goldfish-irq.%d" goldfish_pic_instance_init(void *dev) "pic: %p goldfish-irq" + +# sh_intc.c +sh_intc_sources(int p, int a, int c, int m, unsigned short v, const char *s1, const char *s2, const char *s3) "(%d/%d/%d/%d) interrupt source 0x%x %s%s%s" +sh_intc_pending(int p, unsigned short v) "(%d) returning interrupt source 0x%x" +sh_intc_register(const char *s, int id, unsigned short v, int c, int m) "%s %d -> 0x%04x (%d/%d)" +sh_intc_read(unsigned size, uint64_t offset, unsigned long val) "size %d 0x%" PRIx64 " -> 0x%" PRIx64 +sh_intc_write(unsigned size, uint64_t offset, unsigned long val) "size %d 0x%" PRIx64 " <- 0x%" PRIx64 +sh_intc_set(int id, int enable) "setting interrupt group %d to %d"
I had to include the following diff to successfully build on 32-bit hosts:
-- >8 --
hw/intc/sh_intc.c +0 -0
@@ -206,7 +206,7 @@ static uint64_t sh_intc_read(void *opaque, hwaddr
offset, unsigned size)
sh_intc_locate(desc, (unsigned long)offset, &valuep,
&enum_ids, &first, &width, &mode);
- trace_sh_intc_read(size, offset, *valuep);
+ trace_sh_intc_read(size, (uint64_t)offset, *valuep);
return *valuep;}
@@ -222,7 +222,7 @@ static void sh_intc_write(void *opaque, hwaddr offset,
unsigned int k;
unsigned long mask;- trace_sh_intc_write(size, offset, value);
+ trace_sh_intc_write(size, (uint64_t)offset, value);
sh_intc_locate(desc, (unsigned long)offset, &valuep,
&enum_ids, &first, &width, &mode);
switch (mode) {hw/intc/trace-events +0 -0
@@ -242,7 +242,7 @@ goldfish_pic_instance_init(void *dev) "pic: %p
goldfish-irq"
# sh_intc.c sh_intc_sources(int p, int a, int c, int m, unsigned short v, const char *s1, const char *s2, const char *s3) "(%d/%d/%d/%d) interrupt source 0x%x %s%s%s" sh_intc_pending(int p, unsigned short v) "(%d) returning interrupt source 0x%x" -sh_intc_register(const char *s, int id, unsigned short v, int c, int m) "%s %d -> 0x%04x (%d/%d)" -sh_intc_read(unsigned size, uint64_t offset, unsigned long val) "size %d 0x%" PRIx64 " -> 0x%" PRIx64 -sh_intc_write(unsigned size, uint64_t offset, unsigned long val) "size %d 0x%" PRIx64 " <- 0x%" PRIx64 +sh_intc_register(const char *s, int id, unsigned short v, int c, int m) "%s %u -> 0x%04x (%d/%d)" +sh_intc_read(unsigned size, uint64_t offset, unsigned long val) "size %u 0x%" PRIx64 " -> 0x%lx" +sh_intc_write(unsigned size, uint64_t offset, unsigned long val) "size %u 0x%" PRIx64 " <- 0x%lx" sh_intc_set(int id, int enable) "setting interrupt group %d to %d" ---
Next time please run a CI pipeline.
PATCH v6 8/30 hw/sh4/r2d: Use error_report instead of fprintf to stderr
In reply to BALATON Zoltan--- hw/sh4/r2d.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/sh4/r2d.c +3 -2
@@ -26,6 +26,7 @@#include "qemu/osdep.h" #include "qemu/units.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "cpu.h" #include "hw/sysbus.h" #include "hw/sh4/sh.h"
@@ -324,7 +325,7 @@ static void r2d_init(MachineState *machine)SDRAM_BASE +LINUX_LOAD_OFFSET , INITRD_LOAD_OFFSET - LINUX_LOAD_OFFSET);if (kernel_size <0 ) { -fprintf (stderr,"qemu: could not load kernel '%s'\n" , kernel_filename); +error_report ("qemu: could not load kernel '%s'" , kernel_filename);exit (1 ); }
@@ -345,7 +346,7 @@ static void r2d_init(MachineState *machine) SDRAM_SIZE - INITRD_LOAD_OFFSET);if (initrd_size <0 ) { -fprintf (stderr,"qemu: could not load initrd '%s'\n" , initrd_filename); +error_report ("qemu: could not load initrd '%s'" , initrd_filename);exit (1 ); }
Signature · 1 line
2.21.4
PATCH v6 9/30 hw/char/sh_serial: Do not abort on invalid access
In reply to BALATON ZoltanReplace fprintf with qemu_log_mask LOG_GUEST_ERROR as the intention is to handle valid accesses in these functions so if we get to these errors then it's an invalid access. Do not abort as that would allow the guest to crash QEMU and the practice in other devices is to not do that just log and ignore the invalid access. While at it also simplify the complex bit ops to check if a return value was set which can be done much simpler and clearer.
--- hw/char/sh_serial.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
hw/char/sh_serial.c +10 -9
@@ -31,6 +31,7 @@#include "chardev/char-fe.h" #include "qapi/error.h" #include "qemu/timer.h" +#include "qemu/log.h" #include "trace.h" #define SH_SERIAL_FLAG_TEND (1 << 0)
@@ -195,17 +196,16 @@ static void sh_serial_write(void *opaque, hwaddr offs,return ; } } - -fprintf (stderr,"sh_serial: unsupported write to 0x%02" - HWADDR_PRIx"\n" , offs); -abort (); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: unsupported write to 0x%02" HWADDR_PRIx"\n" , + __func__, offs); }static uint64_t sh_serial_read (void *opaque,hwaddr offs,unsigned size) {sh_serial_state *s = opaque; -uint32_t ret = ~0 ; +uint32_t ret =UINT32_MAX ;#if 0 switch (offs) {
@@ -299,10 +299,11 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs, }trace_sh_serial_read (size, offs, ret); -if (ret & ~((1 <<16 ) -1 )) { -fprintf (stderr,"sh_serial: unsupported read from 0x%02" - HWADDR_PRIx"\n" , offs); -abort (); +if (ret >UINT16_MAX ) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: unsupported read from 0x%02" HWADDR_PRIx"\n" , + __func__, offs); + ret =0 ; }return ret;
Signature · 1 line
2.21.4
PATCH v6 10/30 hw/char/sh_serial: Rename type sh_serial_state to SHSerialState
In reply to BALATON ZoltanCoding style says types should be camel case.
--- hw/char/sh_serial.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
hw/char/sh_serial.c +11 -13
@@ -73,9 +73,9 @@ typedef struct {qemu_irq txi;qemu_irq tei;qemu_irq bri; -} sh_serial_state; +} SHSerialState; -static void sh_serial_clear_fifo (sh_serial_state *s) +static void sh_serial_clear_fifo (SHSerialState *s) {memset (s->rx_fifo,0 ,SH_RX_FIFO_LENGTH ); s->rx_cnt =0 ;
@@ -86,7 +86,7 @@ static void sh_serial_clear_fifo(sh_serial_state *s)static void sh_serial_write (void *opaque,hwaddr offs,uint64_t val,unsigned size) { -sh_serial_state *s = opaque; +SHSerialState *s = opaque;unsigned char ch;trace_sh_serial_write (size, offs, val);
@@ -204,7 +204,7 @@ static void sh_serial_write(void *opaque, hwaddr offs,static uint64_t sh_serial_read (void *opaque,hwaddr offs,unsigned size) { -sh_serial_state *s = opaque; +SHSerialState *s = opaque;uint32_t ret =UINT32_MAX ;#if 0
@@ -309,12 +309,12 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs,return ret; } -static int sh_serial_can_receive (sh_serial_state *s) +static int sh_serial_can_receive (SHSerialState *s) {return s->scr & (1 <<4 ); } -static void sh_serial_receive_break (sh_serial_state *s) +static void sh_serial_receive_break (SHSerialState *s) {if (s->feat &SH_SERIAL_FEAT_SCIF ) { s->sr |= (1 <<4 );
@@ -323,13 +323,13 @@ static void sh_serial_receive_break(sh_serial_state *s)static int sh_serial_can_receive1 (void *opaque) { -sh_serial_state *s = opaque; +SHSerialState *s = opaque;return sh_serial_can_receive (s); }static void sh_serial_timeout_int (void *opaque) { -sh_serial_state *s = opaque; +SHSerialState *s = opaque; s->flags |=SH_SERIAL_FLAG_RDF ;if (s->scr & (1 <<6 ) && s->rxi) {
@@ -339,7 +339,7 @@ static void sh_serial_timeout_int(void *opaque)static void sh_serial_receive1 (void *opaque,const uint8_t *buf,int size) { -sh_serial_state *s = opaque; +SHSerialState *s = opaque;if (s->feat &SH_SERIAL_FEAT_SCIF ) {int i;
@@ -369,7 +369,7 @@ static void sh_serial_receive1(void *opaque, const uint8_t *buf, int size)static void sh_serial_event (void *opaque,QEMUChrEvent event) { -sh_serial_state *s = opaque; +SHSerialState *s = opaque;if (event ==CHR_EVENT_BREAK ) {sh_serial_receive_break (s); }
@@ -390,9 +390,7 @@ void sh_serial_init(MemoryRegion *sysmem, qemu_irq tei_source, qemu_irq bri_source) { -sh_serial_state *s; - - s =g_malloc0 (sizeof (sh_serial_state)); +SHSerialState *s =g_malloc0 (sizeof (*s)); s->feat = feat; s->flags =SH_SERIAL_FLAG_TEND |SH_SERIAL_FLAG_TDE ;
Signature · 1 line
2.21.4
PATCH v6 11/30 hw/char/sh_serial: Embed QEMUTimer in state struct
In reply to BALATON ZoltanInstead of allocating timer with timer_new store it directly in the state struct. This makes it simpler to free it together with the device.
--- hw/char/sh_serial.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
hw/char/sh_serial.c +5 -5
@@ -65,7 +65,7 @@ typedef struct {int rtrg;CharBackend chr; -QEMUTimer *fifo_timeout_timer; +QEMUTimer fifo_timeout_timer;uint64_t etu;/* Elementary Time Unit (ns) */ qemu_irq eri;
@@ -353,11 +353,11 @@ static void sh_serial_receive1(void *opaque, const uint8_t *buf, int size)if (s->rx_cnt >= s->rtrg) { s->flags |=SH_SERIAL_FLAG_RDF ;if (s->scr & (1 <<6 ) && s->rxi) { -timer_del (s->fifo_timeout_timer); +timer_del (&s->fifo_timeout_timer);qemu_set_irq (s->rxi,1 ); } }else { -timer_mod (s->fifo_timeout_timer, +timer_mod (&s->fifo_timeout_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +15 * s->etu); } }
@@ -427,8 +427,8 @@ void sh_serial_init(MemoryRegion *sysmem, sh_serial_event, NULL, s, NULL, true); } - s->fifo_timeout_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , - sh_serial_timeout_int, s); +timer_init_ns (&s->fifo_timeout_timer,QEMU_CLOCK_VIRTUAL , + sh_serial_timeout_int, s); s->etu =NANOSECONDS_PER_SECOND /9600 ; s->eri = eri_source; s->rxi = rxi_source;
Signature · 1 line
2.21.4
Re: [PATCH v6 11/30] hw/char/sh_serial: Embed QEMUTimer in state struct
Quoted 7 lines · BALATON Zoltan
Instead of allocating timer with
timer_newstore it directly in the state struct. This makes it simpler to free it together with the device.Signed-off-by BALATON Zoltan <[email protected]>--- hw/char/sh_serial.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
PATCH v6 12/30 hw/char/sh_serial: Split off sh_serial_reset() from sh_serial_init()
In reply to BALATON Zoltan--- hw/char/sh_serial.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
hw/char/sh_serial.c +17 -12
@@ -381,18 +381,8 @@ static const MemoryRegionOps sh_serial_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -void sh_serial_init (MemoryRegion *sysmem, -hwaddr base,int feat, -uint32_t freq,Chardev *chr, -qemu_irq eri_source, -qemu_irq rxi_source, -qemu_irq txi_source, -qemu_irq tei_source, -qemu_irq bri_source) +static void sh_serial_reset (SHSerialState *s) { -SHSerialState *s =g_malloc0 (sizeof (*s)); - - s->feat = feat; s->flags =SH_SERIAL_FLAG_TEND |SH_SERIAL_FLAG_TDE ; s->rtrg =1 ;
@@ -401,13 +391,28 @@ void sh_serial_init(MemoryRegion *sysmem, s->scr =1 <<5 ;/* pretend that TX is enabled so early printk works */ s->sptr =0 ; -if (feat &SH_SERIAL_FEAT_SCIF ) { +if (s->feat &SH_SERIAL_FEAT_SCIF ) { s->fcr =0 ; }else { s->dr =0xff ; }sh_serial_clear_fifo (s); +} + +void sh_serial_init (MemoryRegion *sysmem, +hwaddr base,int feat, +uint32_t freq,Chardev *chr, +qemu_irq eri_source, +qemu_irq rxi_source, +qemu_irq txi_source, +qemu_irq tei_source, +qemu_irq bri_source) +{ +SHSerialState *s =g_malloc0 (sizeof (*s)); + + s->feat = feat; +sh_serial_reset (s);memory_region_init_io (&s->iomem,NULL , &sh_serial_ops, s,"serial" ,0x100000000ULL );
Signature · 1 line
2.21.4
Re: [PATCH v6 12/30] hw/char/sh_serial: Split off sh_serial_reset() from sh_serial_init()
Quoted 4 lines · BALATON Zoltan
Signed-off-by BALATON Zoltan <[email protected]>--- hw/char/sh_serial.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
PATCH v6 13/30 hw/char/sh_serial: QOM-ify
In reply to BALATON Zoltan--- hw/char/sh_serial.c | 98 +++++++++++++++++++++++++++------------------ hw/sh4/sh7750.c | 56 +++++++++++++++++++------- include/hw/sh4/sh.h | 9 +---- 3 files changed, 101 insertions(+), 62 deletions(-)
hw/char/sh_serial.c +59 -39
@@ -26,7 +26,11 @@*/ #include "qemu/osdep.h" +#include "hw/sysbus.h" #include "hw/irq.h" +#include "hw/qdev-core.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" #include "hw/sh4/sh.h" #include "chardev/char-fe.h" #include "qapi/error.h"
@@ -42,10 +46,10 @@#define SH_RX_FIFO_LENGTH (16) -typedef struct { - MemoryRegion iomem; - MemoryRegion iomem_p4; - MemoryRegion iomem_a7; +OBJECT_DECLARE_SIMPLE_TYPE(SHSerialState, SH_SERIAL) + +struct SHSerialState { +SysBusDevice parent;uint8_t smr;uint8_t brr;uint8_t scr;
@@ -59,8 +63,7 @@ typedef struct {uint8_t rx_tail;uint8_t rx_head; -int freq; -int feat; +uint8_t feat;int flags;int rtrg;
@@ -73,7 +76,11 @@ typedef struct {qemu_irq txi;qemu_irq tei;qemu_irq bri; -} SHSerialState; +}; + +typedef struct {}SHSerialStateClass ; + +OBJECT_DEFINE_TYPE(SHSerialState, sh_serial, SH_SERIAL, SYS_BUS_DEVICE)static void sh_serial_clear_fifo (SHSerialState *s) {
@@ -381,8 +388,10 @@ static const MemoryRegionOps sh_serial_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void sh_serial_reset (SHSerialState *s) +static void sh_serial_reset (DeviceState *dev) { +SHSerialState *s =SH_SERIAL (dev); + s->flags =SH_SERIAL_FLAG_TEND |SH_SERIAL_FLAG_TDE ; s->rtrg =1 ;
@@ -400,33 +409,21 @@ static void sh_serial_reset(SHSerialState *s)sh_serial_clear_fifo (s); } -void sh_serial_init (MemoryRegion *sysmem, -hwaddr base,int feat, -uint32_t freq,Chardev *chr, -qemu_irq eri_source, -qemu_irq rxi_source, -qemu_irq txi_source, -qemu_irq tei_source, -qemu_irq bri_source) +static void sh_serial_realize (DeviceState *d,Error **errp) { -SHSerialState *s =g_malloc0 (sizeof (*s)); - - s->feat = feat; -sh_serial_reset (s); - -memory_region_init_io (&s->iomem,NULL , &sh_serial_ops, s, -"serial" ,0x100000000ULL ); - -memory_region_init_alias (&s->iomem_p4,NULL ,"serial-p4" , &s->iomem, -0 ,0x28 ); -memory_region_add_subregion (sysmem,P4ADDR (base), &s->iomem_p4); - -memory_region_init_alias (&s->iomem_a7,NULL ,"serial-a7" , &s->iomem, -0 ,0x28 ); -memory_region_add_subregion (sysmem,A7ADDR (base), &s->iomem_a7); - -if (chr) { -qemu_chr_fe_init (&s->chr, chr, &error_abort); +SHSerialState *s =SH_SERIAL (d); +MemoryRegion *iomem =g_malloc (sizeof (*iomem)); + +assert (d->id); +memory_region_init_io (iomem,OBJECT (d), &sh_serial_ops, s, d->id,0x28 ); +sysbus_init_mmio (SYS_BUS_DEVICE (d), iomem); +qdev_init_gpio_out_named (d, &s->eri,"eri" ,1 ); +qdev_init_gpio_out_named (d, &s->rxi,"rxi" ,1 ); +qdev_init_gpio_out_named (d, &s->txi,"txi" ,1 ); +qdev_init_gpio_out_named (d, &s->tei,"tei" ,1 ); +qdev_init_gpio_out_named (d, &s->bri,"bri" ,1 ); + +if (qemu_chr_fe_backend_connected (&s->chr)) {qemu_chr_fe_set_handlers (&s->chr, sh_serial_can_receive1, sh_serial_receive1, sh_serial_event,NULL , s,NULL , true);
@@ -435,9 +432,32 @@ void sh_serial_init(MemoryRegion *sysmem,timer_init_ns (&s->fifo_timeout_timer,QEMU_CLOCK_VIRTUAL , sh_serial_timeout_int, s); s->etu =NANOSECONDS_PER_SECOND /9600 ; - s->eri = eri_source; - s->rxi = rxi_source; - s->txi = txi_source; - s->tei = tei_source; - s->bri = bri_source; +} + +static void sh_serial_finalize (Object *obj) +{ +SHSerialState *s =SH_SERIAL (obj); + +timer_del (&s->fifo_timeout_timer); +} + +static void sh_serial_init (Object *obj) +{ +} + +static Property sh_serial_properties[] = { +DEFINE_PROP_CHR ("chardev" , SHSerialState, chr), +DEFINE_PROP_UINT8 ("features" , SHSerialState, feat,0 ), +DEFINE_PROP_END_OF_LIST () +}; + +static void sh_serial_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + +device_class_set_props (dc, sh_serial_properties); + dc->realize = sh_serial_realize; + dc->reset = sh_serial_reset; +/* Reason: part of SuperH CPU/SoC, needs to be wired up */ + dc->user_creatable = false; }
hw/sh4/sh7750.c +41 -15
77 lines not on this page · raw message
include/hw/sh4/sh.h +1 -8
@@ -54,15 +54,8 @@ int sh7750_register_io_device(struct SH7750State *s, sh7750_io_device *device);/* sh_serial.c */ +#define TYPE_SH_SERIAL "sh-serial"#define SH_SERIAL_FEAT_SCIF (1 << 0) -void sh_serial_init (MemoryRegion *sysmem, -hwaddr base,int feat, -uint32_t freq,Chardev *chr, -qemu_irq eri_source, -qemu_irq rxi_source, -qemu_irq txi_source, -qemu_irq tei_source, -qemu_irq bri_source);/* sh7750.c */ qemu_irq sh7750_irl (struct SH7750State *s);
Signature · 1 line
2.21.4
Re: [PATCH v6 13/30] hw/char/sh_serial: QOM-ify
Quoted 29 lines · BALATON Zoltan
Signed-off-by BALATON Zoltan <[email protected]>--- hw/char/sh_serial.c | 98 +++++++++++++++++++++++++++------------------ hw/sh4/sh7750.c | 56 +++++++++++++++++++------- include/hw/sh4/sh.h | 9 +---- 3 files changed, 101 insertions(+), 62 deletions(-)hw/char/sh_serial.c +1
-20-void sh_serial_init (MemoryRegion *sysmem, -hwaddr base,int feat, -uint32_t freq,Chardev *chr, -qemu_irq eri_source, -qemu_irq rxi_source, -qemu_irq txi_source, -qemu_irq tei_source, -qemu_irq bri_source) +static void sh_serial_realize (DeviceState *d,Error **errp) { -SHSerialState *s =g_malloc0 (sizeof (*s)); - - s->feat = feat; -sh_serial_reset (s); - -memory_region_init_io (&s->iomem,NULL , &sh_serial_ops, s, -"serial" ,0x100000000ULL ); - -memory_region_init_alias (&s->iomem_p4,NULL ,"serial-p4" , &s->iomem, -0 ,0x28 ); -memory_region_add_subregion (sysmem,P4ADDR (base), &s->iomem_p4); -
hw/char/sh_serial.c static void sh_serial_reset(SHSerialState *s) · line 417
Quoted 10 lines
hw/char/sh_serial.c +4
-6-memory_region_init_alias (&s->iomem_a7,NULL ,"serial-a7" , &s->iomem, -0 ,0x28 ); -memory_region_add_subregion (sysmem,A7ADDR (base), &s->iomem_a7); - -if (chr) { -qemu_chr_fe_init (&s->chr, chr, &error_abort); +SHSerialState *s =SH_SERIAL (d); +MemoryRegion *iomem =g_malloc (sizeof (*iomem)); + +assert (d->id);
DeviceRealize() takes a Error* parameter... But well since this is not user_creatable I suppose it is understandable enough.
Quoted 90 lines
hw/char/sh_serial.c +37
-5+memory_region_init_io (iomem,OBJECT (d), &sh_serial_ops, s, d->id,0x28 ); +sysbus_init_mmio (SYS_BUS_DEVICE (d), iomem); +qdev_init_gpio_out_named (d, &s->eri,"eri" ,1 ); +qdev_init_gpio_out_named (d, &s->rxi,"rxi" ,1 ); +qdev_init_gpio_out_named (d, &s->txi,"txi" ,1 ); +qdev_init_gpio_out_named (d, &s->tei,"tei" ,1 ); +qdev_init_gpio_out_named (d, &s->bri,"bri" ,1 ); + +if (qemu_chr_fe_backend_connected (&s->chr)) {qemu_chr_fe_set_handlers (&s->chr, sh_serial_can_receive1, sh_serial_receive1, sh_serial_event,NULL , s,NULL , true);@@ -435,9 +432,32 @@ void sh_serial_init(MemoryRegion *sysmem,timer_init_ns (&s->fifo_timeout_timer,QEMU_CLOCK_VIRTUAL , sh_serial_timeout_int, s); s->etu =NANOSECONDS_PER_SECOND /9600 ; - s->eri = eri_source; - s->rxi = rxi_source; - s->txi = txi_source; - s->tei = tei_source; - s->bri = bri_source; +} + +static void sh_serial_finalize (Object *obj) +{ +SHSerialState *s =SH_SERIAL (obj); + +timer_del (&s->fifo_timeout_timer); +} + +static void sh_serial_init (Object *obj) +{ +} + +static Property sh_serial_properties[] = { +DEFINE_PROP_CHR ("chardev" , SHSerialState, chr), +DEFINE_PROP_UINT8 ("features" , SHSerialState, feat,0 ), +DEFINE_PROP_END_OF_LIST () +}; + +static void sh_serial_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + +device_class_set_props (dc, sh_serial_properties); + dc->realize = sh_serial_realize; + dc->reset = sh_serial_reset; +/* Reason: part of SuperH CPU/SoC, needs to be wired up */ + dc->user_creatable = false; }hw/sh4/sh7750.c +7
-8@@ -24,9 +24,13 @@*/ #include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/sysbus.h" #include "hw/irq.h" #include "hw/sh4/sh.h" #include "sysemu/sysemu.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" #include "sh7750_regs.h" #include "sh7750_regnames.h" #include "hw/sh4/sh_intc.h" @@ -762,6 +766,9 @@ static const MemoryRegionOps sh7750_mmct_ops = {SH7750State *sh7750_init (SuperHCPU *cpu,MemoryRegion *sysmem) {SH7750State *s; +DeviceState *dev; +SysBusDevice *sb; +MemoryRegion *mr, *alias; s =g_malloc0 (sizeof (SH7750State)); s->cpu = cpu;@@ -807,21 +814,40 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem) cpu->env.intc_handle = &s->intc; -sh_serial_init (sysmem,0x1fe00000 , -0 , s->periph_freq,serial_hd (0 ), - s->intc.irqs[SCI1_ERI ], - s->intc.irqs[SCI1_RXI ], - s->intc.irqs[SCI1_TXI ], - s->intc.irqs[SCI1_TEI ], -NULL ); - sh_serial_init(sysmem, 0x1fe80000,
hw/sh4/sh7750.c SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem) · line 819
Quoted 10 lines
hw/sh4/sh7750.c +3
-7-SH_SERIAL_FEAT_SCIF , - s->periph_freq,serial_hd (1 ), - s->intc.irqs[SCIF_ERI ], - s->intc.irqs[SCIF_RXI ], - s->intc.irqs[SCIF_TXI ], -NULL , - s->intc.irqs[SCIF_BRI]); +/* SCI */ + dev =qdev_new (TYPE_SH_SERIAL ); + dev->id = (char *)"sci" ;
No, this is g_strdup() (freed in device_finalize()).
Quoted 7 lines
hw/sh4/sh7750.c +7
-0+qdev_prop_set_chr (dev,"chardev" ,serial_hd (0 )); + sb =SYS_BUS_DEVICE (dev); +sysbus_realize_and_unref (sb, &error_fatal); +sysbus_mmio_map (sb,0 ,0xffe00000 ); + alias =g_malloc (sizeof (*alias)); + mr =sysbus_mmio_get_region (sb,0 ); + memory_region_init_alias(alias, OBJECT(dev), "sci-a7", mr,
hw/sh4/sh7750.c SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem) · line 836
Quoted 10 lines
hw/sh4/sh7750.c +10
-0+ 0, memory_region_size(mr)); +memory_region_add_subregion (sysmem,A7ADDR (0xffe00000 ), alias); +qdev_connect_gpio_out_named (dev,"eri" ,0 , s->intc.irqs[SCI1_ERI ]); +qdev_connect_gpio_out_named (dev,"rxi" ,0 , s->intc.irqs[SCI1_RXI ]); +qdev_connect_gpio_out_named (dev,"txi" ,0 , s->intc.irqs[SCI1_TXI ]); +qdev_connect_gpio_out_named (dev,"tei" ,0 , s->intc.irqs[SCI1_TEI ]); + +/* SCIF */ + dev =qdev_new (TYPE_SH_SERIAL ); + dev->id = (char *)"scif" ;
g_strdup()
If you agree I can fix when applying.
Re: [PATCH v6 13/30] hw/char/sh_serial: QOM-ify
Quoted 35 lines · Philippe Mathieu-Daudé
Quoted 34 lines · BALATON Zoltan
Signed-off-by BALATON Zoltan <[email protected]>--- hw/char/sh_serial.c | 98 +++++++++++++++++++++++++++------------------ hw/sh4/sh7750.c | 56 +++++++++++++++++++------- include/hw/sh4/sh.h | 9 +---- 3 files changed, 101 insertions(+), 62 deletions(-)hw/char/sh_serial.c +1
-25-void sh_serial_init (MemoryRegion *sysmem, -hwaddr base,int feat, -uint32_t freq,Chardev *chr, -qemu_irq eri_source, -qemu_irq rxi_source, -qemu_irq txi_source, -qemu_irq tei_source, -qemu_irq bri_source) +static void sh_serial_realize (DeviceState *d,Error **errp) { -SHSerialState *s =g_malloc0 (sizeof (*s)); - - s->feat = feat; -sh_serial_reset (s); - -memory_region_init_io (&s->iomem,NULL , &sh_serial_ops, s, -"serial" ,0x100000000ULL ); - -memory_region_init_alias (&s->iomem_p4,NULL ,"serial-p4" , &s->iomem, -0 ,0x28 ); -memory_region_add_subregion (sysmem,P4ADDR (base), &s->iomem_p4); - -memory_region_init_alias (&s->iomem_a7,NULL ,"serial-a7" , &s->iomem, -0 ,0x28 ); -memory_region_add_subregion (sysmem,A7ADDR (base), &s->iomem_a7); - -if (chr) {
Quoted 8 lines
hw/char/sh_serial.c static void sh_serial_reset(SHSerialState *s) · line 417
Quoted 5 lines
hw/char/sh_serial.c +4
-1-qemu_chr_fe_init (&s->chr, chr, &error_abort); +SHSerialState *s =SH_SERIAL (d); +MemoryRegion *iomem =g_malloc (sizeof (*iomem)); + +assert (d->id);
DeviceRealize()takes a Error* parameter... But well since this is notuser_creatableI suppose it is understandable enough.
Yes, my view is that assert is to note programmer error and error is to report user error and since this is an internal object of the SH model which is not user creatable that's why I put assert here.
Quoted 121 lines
Quoted 90 lines
hw/char/sh_serial.c +37
-5+memory_region_init_io (iomem,OBJECT (d), &sh_serial_ops, s, d->id,0x28 ); +sysbus_init_mmio (SYS_BUS_DEVICE (d), iomem); +qdev_init_gpio_out_named (d, &s->eri,"eri" ,1 ); +qdev_init_gpio_out_named (d, &s->rxi,"rxi" ,1 ); +qdev_init_gpio_out_named (d, &s->txi,"txi" ,1 ); +qdev_init_gpio_out_named (d, &s->tei,"tei" ,1 ); +qdev_init_gpio_out_named (d, &s->bri,"bri" ,1 ); + +if (qemu_chr_fe_backend_connected (&s->chr)) {qemu_chr_fe_set_handlers (&s->chr, sh_serial_can_receive1, sh_serial_receive1, sh_serial_event,NULL , s,NULL , true);@@ -435,9 +432,32 @@ void sh_serial_init(MemoryRegion *sysmem,timer_init_ns (&s->fifo_timeout_timer,QEMU_CLOCK_VIRTUAL , sh_serial_timeout_int, s); s->etu =NANOSECONDS_PER_SECOND /9600 ; - s->eri = eri_source; - s->rxi = rxi_source; - s->txi = txi_source; - s->tei = tei_source; - s->bri = bri_source; +} + +static void sh_serial_finalize (Object *obj) +{ +SHSerialState *s =SH_SERIAL (obj); + +timer_del (&s->fifo_timeout_timer); +} + +static void sh_serial_init (Object *obj) +{ +} + +static Property sh_serial_properties[] = { +DEFINE_PROP_CHR ("chardev" , SHSerialState, chr), +DEFINE_PROP_UINT8 ("features" , SHSerialState, feat,0 ), +DEFINE_PROP_END_OF_LIST () +}; + +static void sh_serial_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + +device_class_set_props (dc, sh_serial_properties); + dc->realize = sh_serial_realize; + dc->reset = sh_serial_reset; +/* Reason: part of SuperH CPU/SoC, needs to be wired up */ + dc->user_creatable = false; }hw/sh4/sh7750.c +7
-8@@ -24,9 +24,13 @@*/ #include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/sysbus.h" #include "hw/irq.h" #include "hw/sh4/sh.h" #include "sysemu/sysemu.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" #include "sh7750_regs.h" #include "sh7750_regnames.h" #include "hw/sh4/sh_intc.h" @@ -762,6 +766,9 @@ static const MemoryRegionOps sh7750_mmct_ops = {SH7750State *sh7750_init (SuperHCPU *cpu,MemoryRegion *sysmem) {SH7750State *s; +DeviceState *dev; +SysBusDevice *sb; +MemoryRegion *mr, *alias; s =g_malloc0 (sizeof (SH7750State)); s->cpu = cpu;@@ -807,21 +814,40 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem) cpu->env.intc_handle = &s->intc; -sh_serial_init (sysmem,0x1fe00000 , -0 , s->periph_freq,serial_hd (0 ), - s->intc.irqs[SCI1_ERI ], - s->intc.irqs[SCI1_RXI ], - s->intc.irqs[SCI1_TXI ], - s->intc.irqs[SCI1_TEI ], -NULL ); - sh_serial_init(sysmem, 0x1fe80000,hw/sh4/sh7750.c SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem) · line 819
Quoted 10 lines
hw/sh4/sh7750.c +3
-7-SH_SERIAL_FEAT_SCIF , - s->periph_freq,serial_hd (1 ), - s->intc.irqs[SCIF_ERI ], - s->intc.irqs[SCIF_RXI ], - s->intc.irqs[SCIF_TXI ], -NULL , - s->intc.irqs[SCIF_BRI]); +/* SCI */ + dev =qdev_new (TYPE_SH_SERIAL ); + dev->id = (char *)"sci" ;No, this is
g_strdup()(freed indevice_finalize()).Quoted 7 lines
hw/sh4/sh7750.c +7
-0+qdev_prop_set_chr (dev,"chardev" ,serial_hd (0 )); + sb =SYS_BUS_DEVICE (dev); +sysbus_realize_and_unref (sb, &error_fatal); +sysbus_mmio_map (sb,0 ,0xffe00000 ); + alias =g_malloc (sizeof (*alias)); + mr =sysbus_mmio_get_region (sb,0 ); + memory_region_init_alias(alias, OBJECT(dev), "sci-a7", mr,hw/sh4/sh7750.c SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem) · line 836
Quoted 10 lines
hw/sh4/sh7750.c +10
-0+ 0, memory_region_size(mr)); +memory_region_add_subregion (sysmem,A7ADDR (0xffe00000 ), alias); +qdev_connect_gpio_out_named (dev,"eri" ,0 , s->intc.irqs[SCI1_ERI ]); +qdev_connect_gpio_out_named (dev,"rxi" ,0 , s->intc.irqs[SCI1_RXI ]); +qdev_connect_gpio_out_named (dev,"txi" ,0 , s->intc.irqs[SCI1_TXI ]); +qdev_connect_gpio_out_named (dev,"tei" ,0 , s->intc.irqs[SCI1_TEI ]); + +/* SCIF */ + dev =qdev_new (TYPE_SH_SERIAL ); + dev->id = (char *)"scif" ;
Quoted 3 lines
g_strdup()If you agree I can fix when applying.
Indeed you're right, please fix this up.
Regards,
BALATON Zoltan
PATCH v6 14/30 hw/char/sh_serial: Add device id to trace output
In reply to BALATON ZoltanNormally there are at least two sh_serial instances. Add device id to trace messages to make it clear which instance they belong to otherwise its not possible to tell which serial device is accessed.
--- hw/char/sh_serial.c | 6 ++++-- hw/char/trace-events | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-)
hw/char/sh_serial.c +4 -2
@@ -94,9 +94,10 @@ static void sh_serial_write(void *opaque, hwaddr offs, uint64_t val, unsigned size) {SHSerialState *s = opaque; +DeviceState *d =DEVICE (s);unsigned char ch; -trace_sh_serial_write (size, offs, val); +trace_sh_serial_write (d->id, size, offs, val);switch (offs) {case 0x00 :/* SMR */ s->smr = val & ((s->feat &SH_SERIAL_FEAT_SCIF ) ?0x7b :0xff );
@@ -212,6 +213,7 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs, unsigned size) {SHSerialState *s = opaque; +DeviceState *d =DEVICE (s);uint32_t ret =UINT32_MAX ;#if 0
@@ -304,7 +306,7 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs,break ; } } -trace_sh_serial_read (size, offs, ret); +trace_sh_serial_read (d->id, size, offs, ret);if (ret >UINT16_MAX ) { qemu_log_mask(LOG_GUEST_ERROR,
hw/char/trace-events +2 -2
@@ -103,5 +103,5 @@ exynos_uart_rx_timeout(uint32_t channel, uint32_t stat, uint32_t intsp) "UART%d: cadence_uart_baudrate(unsigned baudrate) "baudrate %u" # sh_serial.c -sh_serial_read(unsigned size, uint64_t offs, uint64_t val) " size %d offs 0x%02" PRIx64 " -> 0x%02" PRIx64 -sh_serial_write(unsigned size, uint64_t offs, uint64_t val) "size %d offs 0x%02" PRIx64 " <- 0x%02" PRIx64 +sh_serial_read(char *id, unsigned size, uint64_t offs, uint64_t val) " %s size %d offs 0x%02" PRIx64 " -> 0x%02" PRIx64 +sh_serial_write(char *id, unsigned size, uint64_t offs, uint64_t val) "%s size %d offs 0x%02" PRIx64 " <- 0x%02" PRIx64
Signature · 1 line
2.21.4
PATCH v6 15/30 hw/intc/sh_intc: Use existing macro instead of local one
In reply to BALATON ZoltanThe INTC_A7 local macro does the same as the A7ADDR from include/sh/sh.h so use the latter and drop the local macro definition.
--- hw/intc/sh_intc.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
hw/intc/sh_intc.c +5 -7
@@ -16,8 +16,6 @@#include "hw/sh4/sh.h" #include "trace.h" -#define INTC_A7 (x) ((x) & 0x1fffffff) -void sh_intc_toggle_source (struct intc_source *source,int enable_adj,int assert_adj) {
@@ -112,12 +110,12 @@ int sh_intc_get_pending_vector(struct intc_desc *desc, int imask)static unsigned int sh_intc_mode (unsigned long address,unsigned long set_reg,unsigned long clr_reg) { -if ((address !=INTC_A7 (set_reg)) && - (address !=INTC_A7 (clr_reg))) +if ((address !=A7ADDR (set_reg)) && + (address !=A7ADDR (clr_reg)))return INTC_MODE_NONE ;if (set_reg && clr_reg) { -if (address ==INTC_A7 (set_reg)) { +if (address ==A7ADDR (set_reg)) {return INTC_MODE_DUAL_SET ; }else {return INTC_MODE_DUAL_CLR ;
@@ -297,11 +295,11 @@ static unsigned int sh_intc_register(MemoryRegion *sysmem,#define SH_INTC_IOMEM_FORMAT "interrupt-controller-%s-%s-%s"snprintf (name,sizeof (name),SH_INTC_IOMEM_FORMAT , type, action,"p4" ); -memory_region_init_alias (iomem_p4,NULL , name, iomem,INTC_A7 (address),4 ); +memory_region_init_alias (iomem_p4,NULL , name, iomem,A7ADDR (address),4 );memory_region_add_subregion (sysmem,P4ADDR (address), iomem_p4);snprintf (name,sizeof (name),SH_INTC_IOMEM_FORMAT , type, action,"a7" ); -memory_region_init_alias (iomem_a7,NULL , name, iomem,INTC_A7 (address),4 ); +memory_region_init_alias (iomem_a7,NULL , name, iomem,A7ADDR (address),4 );memory_region_add_subregion (sysmem,A7ADDR (address), iomem_a7);#undef SH_INTC_IOMEM_FORMAT
Signature · 1 line
2.21.4
PATCH v6 16/30 hw/intc/sh_intc: Turn some defines into an enum
In reply to BALATON ZoltanTurn the INTC_MODE defines into an enum and clean up the function returning these to make it clearer by removing nested ifs and superfluous parenthesis. The one remaining #define is a flag which is moved further apart by changing its value from 8 to 0x80 to leave some spare bits as this is or-ed with the enum value at some places.
--- hw/intc/sh_intc.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-)
hw/intc/sh_intc.c +19 -24
@@ -100,33 +100,27 @@ int sh_intc_get_pending_vector(struct intc_desc *desc, int imask)abort (); } -#define INTC_MODE_NONE 0 -#define INTC_MODE_DUAL_SET 1 -#define INTC_MODE_DUAL_CLR 2 -#define INTC_MODE_ENABLE_REG 3 -#define INTC_MODE_MASK_REG 4 -#define INTC_MODE_IS_PRIO 8 - -static unsigned int sh_intc_mode (unsigned long address, -unsigned long set_reg,unsigned long clr_reg) +#define INTC_MODE_IS_PRIO 0x80 +typedef enum { +INTC_MODE_NONE , +INTC_MODE_DUAL_SET , +INTC_MODE_DUAL_CLR , +INTC_MODE_ENABLE_REG , +INTC_MODE_MASK_REG , +}SHIntCMode ; + + +static SHIntCMode sh_intc_mode (unsigned long address,unsigned long set_reg, +unsigned long clr_reg) { -if ((address !=A7ADDR (set_reg)) && - (address !=A7ADDR (clr_reg))) +if (address !=A7ADDR (set_reg) && address !=A7ADDR (clr_reg)) {return INTC_MODE_NONE ; - -if (set_reg && clr_reg) { -if (address ==A7ADDR (set_reg)) { -return INTC_MODE_DUAL_SET ; - }else { -return INTC_MODE_DUAL_CLR ; - } } - -if (set_reg) { -return INTC_MODE_ENABLE_REG ; - }else { -return INTC_MODE_MASK_REG ; +if (set_reg && clr_reg) { +return address ==A7ADDR (set_reg) ? +INTC_MODE_DUAL_SET :INTC_MODE_DUAL_CLR ; } +return set_reg ?INTC_MODE_ENABLE_REG :INTC_MODE_MASK_REG ; } static void sh_intc_locate(struct intc_desc *desc,
@@ -137,7 +131,8 @@ static void sh_intc_locate(struct intc_desc *desc,unsigned int *width, unsigned int *modep) { - unsigned int i, mode; + SHIntCMode mode; +unsigned int i;/* this is slow but works for now */
Signature · 1 line
2.21.4
Re: [PATCH v6 16/30] hw/intc/sh_intc: Turn some defines into an enum
Quoted 26 lines · BALATON Zoltan
Turn the
INTC_MODEdefines into an enum and clean up the function returning these to make it clearer by removing nested ifs and superfluous parenthesis. The one remaining #define is a flag which is moved further apart by changing its value from 8 to0x80to leave some spare bits as this is or-ed with the enum value at some places.Signed-off-by BALATON Zoltan <[email protected]>--- hw/intc/sh_intc.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-)hw/intc/sh_intc.c +0
-7@@ -100,33 +100,27 @@ int sh_intc_get_pending_vector(struct intc_desc *desc, int imask)abort (); } -#define INTC_MODE_NONE 0 -#define INTC_MODE_DUAL_SET 1 -#define INTC_MODE_DUAL_CLR 2 -#define INTC_MODE_ENABLE_REG 3 -#define INTC_MODE_MASK_REG 4 -#define INTC_MODE_IS_PRIO 8 -
hw/intc/sh_intc.c int sh_intc_get_pending_vector(struct intc_desc *desc, int imask) · line 110
Quoted 10 lines
hw/intc/sh_intc.c +8
-2-static unsigned int sh_intc_mode (unsigned long address, -unsigned long set_reg,unsigned long clr_reg) +#define INTC_MODE_IS_PRIO 0x80 +typedef enum { +INTC_MODE_NONE , +INTC_MODE_DUAL_SET , +INTC_MODE_DUAL_CLR , +INTC_MODE_ENABLE_REG , +INTC_MODE_MASK_REG , +}SHIntCMode ;
This doesn't seem clearer, because sh_intc_write() does:
switch (mode) {
case INTC_MODE_ENABLE_REG | INTC_MODE_IS_PRIO:
break;
case INTC_MODE_DUAL_SET:
value |= *valuep;
break;
case INTC_MODE_DUAL_CLR:
value = *valuep & ~value;
break;
default:
g_assert_not_reached();
}Anyway I expect this whole file to be rewritten by Yoshinori, so I don't mind much.
PATCH v6 17/30 hw/intc/sh_intc: Rename iomem region
In reply to BALATON ZoltanRename the iomem region to "intc" from "interrupt-controller" which makes the info mtree output less wide as it is already too wide because of all the aliases. Also drop the format macro which was only used twice in close proximity so we can just use the literal string instead without a macro definition.
--- hw/intc/sh_intc.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
hw/intc/sh_intc.c +4 -7
@@ -288,15 +288,13 @@ static unsigned int sh_intc_register(MemoryRegion *sysmem, iomem_p4 = desc->iomem_aliases + index; iomem_a7 = iomem_p4 +1 ; -#define SH_INTC_IOMEM_FORMAT "interrupt-controller-%s-%s-%s" -snprintf (name,sizeof (name),SH_INTC_IOMEM_FORMAT , type, action,"p4" ); +snprintf (name,sizeof (name),"intc-%s-%s-%s" , type, action,"p4" );memory_region_init_alias (iomem_p4,NULL , name, iomem,A7ADDR (address),4 );memory_region_add_subregion (sysmem,P4ADDR (address), iomem_p4); -snprintf (name,sizeof (name),SH_INTC_IOMEM_FORMAT , type, action,"a7" ); +snprintf (name,sizeof (name),"intc-%s-%s-%s" , type, action,"a7" );memory_region_init_alias (iomem_a7,NULL , name, iomem,A7ADDR (address),4 );memory_region_add_subregion (sysmem,A7ADDR (address), iomem_a7); -#undef SH_INTC_IOMEM_FORMAT/* used to increment aliases index */ return 2 ;
@@ -432,9 +430,8 @@ int sh_intc_init(MemoryRegion *sysmem, } desc->irqs =qemu_allocate_irqs (sh_intc_set_irq, desc, nr_sources); - -memory_region_init_io (&desc->iomem,NULL , &sh_intc_ops, desc, -"interrupt-controller" ,0x100000000ULL ); +memory_region_init_io (&desc->iomem,NULL , &sh_intc_ops, desc,"intc" , +0x100000000ULL );#define INT_REG_PARAMS (reg_struct, type, action, j) \ reg_struct->action##_reg, #type, #action, j
Signature · 1 line
2.21.4
PATCH v6 18/30 hw/intc/sh_intc: Drop another useless macro
In reply to BALATON ZoltanThe INT_REG_PARAMS macro was only used a few times within one function on adjacent lines and is actually more complex than writing out the parameters so simplify it by expanding the macro at call sites and dropping the #define.
--- hw/intc/sh_intc.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
hw/intc/sh_intc.c +4 -11
@@ -433,16 +433,12 @@ int sh_intc_init(MemoryRegion *sysmem,memory_region_init_io (&desc->iomem,NULL , &sh_intc_ops, desc,"intc" ,0x100000000ULL ); -#define INT_REG_PARAMS (reg_struct, type, action, j) \ - reg_struct->action##_reg, #type, #action, jif (desc->mask_regs) {for (i =0 ; i < desc->nr_mask_regs; i++) {struct intc_mask_reg *mr = desc->mask_regs + i; - j +=sh_intc_register (sysmem, desc, -INT_REG_PARAMS (mr, mask, set, j)); - j +=sh_intc_register (sysmem, desc, -INT_REG_PARAMS (mr, mask, clr, j)); + j +=sh_intc_register (sysmem, desc, mr->set_reg,"mask" ,"set" , j); + j +=sh_intc_register (sysmem, desc, mr->clr_reg,"mask" ,"clr" , j); } }
@@ -450,13 +446,10 @@ int sh_intc_init(MemoryRegion *sysmem,for (i =0 ; i < desc->nr_prio_regs; i++) {struct intc_prio_reg *pr = desc->prio_regs + i; - j +=sh_intc_register (sysmem, desc, -INT_REG_PARAMS (pr, prio, set, j)); - j +=sh_intc_register (sysmem, desc, -INT_REG_PARAMS (pr, prio, clr, j)); + j +=sh_intc_register (sysmem, desc, pr->set_reg,"prio" ,"set" , j); + j +=sh_intc_register (sysmem, desc, pr->clr_reg,"prio" ,"clr" , j); } } -#undef INT_REG_PARAMSreturn 0 ; }
Signature · 1 line
2.21.4
PATCH v6 19/30 hw/intc/sh_intc: Move sh_intc_register() closer to its only user
In reply to BALATON ZoltanThe sh_intc_register() function is only used at one place. Move them together so it's easier to see what's going on.
--- hw/intc/sh_intc.c | 60 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-)
hw/intc/sh_intc.c +30 -30
@@ -270,36 +270,6 @@ struct intc_source *sh_intc_source(struct intc_desc *desc, intc_enum id)return NULL ; } -static unsigned int sh_intc_register (MemoryRegion *sysmem, -struct intc_desc *desc, -const unsigned long address, -const char *type, -const char *action, -const unsigned int index) -{ -char name[60 ]; -MemoryRegion *iomem, *iomem_p4, *iomem_a7; - -if (!address) { -return 0 ; - } - - iomem = &desc->iomem; - iomem_p4 = desc->iomem_aliases + index; - iomem_a7 = iomem_p4 +1 ; - -snprintf (name,sizeof (name),"intc-%s-%s-%s" , type, action,"p4" ); -memory_region_init_alias (iomem_p4,NULL , name, iomem,A7ADDR (address),4 ); -memory_region_add_subregion (sysmem,P4ADDR (address), iomem_p4); - -snprintf (name,sizeof (name),"intc-%s-%s-%s" , type, action,"a7" ); -memory_region_init_alias (iomem_a7,NULL , name, iomem,A7ADDR (address),4 ); -memory_region_add_subregion (sysmem,A7ADDR (address), iomem_a7); - -/* used to increment aliases index */ -return 2 ; -} - static void sh_intc_register_source(struct intc_desc *desc, intc_enum source, struct intc_group *groups,
@@ -399,6 +369,36 @@ void sh_intc_register_sources(struct intc_desc *desc, } } +static unsigned int sh_intc_register (MemoryRegion *sysmem, +struct intc_desc *desc, +const unsigned long address, +const char *type, +const char *action, +const unsigned int index) +{ +char name[60 ]; +MemoryRegion *iomem, *iomem_p4, *iomem_a7; + +if (!address) { +return 0 ; + } + + iomem = &desc->iomem; + iomem_p4 = desc->iomem_aliases + index; + iomem_a7 = iomem_p4 +1 ; + +snprintf (name,sizeof (name),"intc-%s-%s-%s" , type, action,"p4" ); +memory_region_init_alias (iomem_p4,NULL , name, iomem,A7ADDR (address),4 ); +memory_region_add_subregion (sysmem,P4ADDR (address), iomem_p4); + +snprintf (name,sizeof (name),"intc-%s-%s-%s" , type, action,"a7" ); +memory_region_init_alias (iomem_a7,NULL , name, iomem,A7ADDR (address),4 ); +memory_region_add_subregion (sysmem,A7ADDR (address), iomem_a7); + +/* used to increment aliases index */ +return 2 ; +} + int sh_intc_init(MemoryRegion *sysmem, struct intc_desc *desc, int nr_sources,
Signature · 1 line
2.21.4
PATCH v6 20/30 hw/intc/sh_intc: Remove excessive parenthesis
In reply to BALATON ZoltanDrop unneded parenthesis and split up one complex expression to write it with less brackets so it's easier to follow.
--- hw/intc/sh_intc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
hw/intc/sh_intc.c +5 -4
@@ -23,7 +23,7 @@ void sh_intc_toggle_source(struct intc_source *source,int pending_changed =0 ;int old_pending; -if ((source->enable_count == source->enable_max) && (enable_adj ==-1 )) { +if (source->enable_count == source->enable_max && enable_adj ==-1 ) { enable_changed =-1 ; } source->enable_count += enable_adj;
@@ -68,7 +68,7 @@ void sh_intc_toggle_source(struct intc_source *source,static void sh_intc_set_irq (void *opaque,int n,int level) {struct intc_desc *desc = opaque; -struct intc_source *source = &(desc->sources[n]); +struct intc_source *source = &desc->sources[n];if (level && !source->asserted) {sh_intc_toggle_source (source,0 ,1 );
@@ -164,7 +164,7 @@ static void sh_intc_locate(struct intc_desc *desc, *modep = mode |INTC_MODE_IS_PRIO ; *datap = &pr->value; *enums = pr->enum_ids; - *first = (pr->reg_width / pr->field_width) -1 ; + *first = pr->reg_width / pr->field_width -1 ; *width = pr->field_width;return ; }
@@ -245,7 +245,8 @@ static void sh_intc_write(void *opaque, hwaddr offset, }for (k =0 ; k <= first; k++) { - mask = ((1 << width) -1 ) << ((first - k) * width); + mask = (1 << width) -1 ; + mask <<= (first - k) * width;if ((*valuep & mask) == (value & mask)) {continue ;
Signature · 1 line
2.21.4
PATCH v6 21/30 hw/intc/sh_intc: Use array index instead of pointer arithmetics
In reply to BALATON ZoltanAddress of element i is one word thus clearer than array + i.
--- hw/intc/sh_intc.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
hw/intc/sh_intc.c +14 -14
@@ -89,7 +89,7 @@ int sh_intc_get_pending_vector(struct intc_desc *desc, int imask) }for (i =0 ; i < desc->nr_sources; i++) { -struct intc_source *source = desc->sources + i; +struct intc_source *source = &desc->sources[i];if (source->pending) {trace_sh_intc_pending (desc->pending, source->vect);
@@ -138,7 +138,7 @@ static void sh_intc_locate(struct intc_desc *desc,if (desc->mask_regs) {for (i =0 ; i < desc->nr_mask_regs; i++) { -struct intc_mask_reg *mr = desc->mask_regs + i; +struct intc_mask_reg *mr = &desc->mask_regs[i]; mode =sh_intc_mode (address, mr->set_reg, mr->clr_reg);if (mode ==INTC_MODE_NONE ) {
@@ -155,7 +155,7 @@ static void sh_intc_locate(struct intc_desc *desc,if (desc->prio_regs) {for (i =0 ; i < desc->nr_prio_regs; i++) { -struct intc_prio_reg *pr = desc->prio_regs + i; +struct intc_prio_reg *pr = &desc->prio_regs[i]; mode =sh_intc_mode (address, pr->set_reg, pr->clr_reg);if (mode ==INTC_MODE_NONE ) {
@@ -176,7 +176,7 @@ static void sh_intc_locate(struct intc_desc *desc,static void sh_intc_toggle_mask (struct intc_desc *desc,intc_enum id,int enable,int is_group) { -struct intc_source *source = desc->sources + id; +struct intc_source *source = &desc->sources[id];if (!id) {return ;
@@ -266,7 +266,7 @@ static const MemoryRegionOps sh_intc_ops = {struct intc_source *sh_intc_source (struct intc_desc *desc,intc_enum id) {if (id) { -return desc->sources + id; +return &desc->sources[id]; }return NULL ; }
@@ -281,7 +281,7 @@ static void sh_intc_register_source(struct intc_desc *desc,if (desc->mask_regs) {for (i =0 ; i < desc->nr_mask_regs; i++) { -struct intc_mask_reg *mr = desc->mask_regs + i; +struct intc_mask_reg *mr = &desc->mask_regs[i];for (k =0 ; k <ARRAY_SIZE (mr->enum_ids); k++) {if (mr->enum_ids[k] != source) {
@@ -297,7 +297,7 @@ static void sh_intc_register_source(struct intc_desc *desc,if (desc->prio_regs) {for (i =0 ; i < desc->nr_prio_regs; i++) { -struct intc_prio_reg *pr = desc->prio_regs + i; +struct intc_prio_reg *pr = &desc->prio_regs[i];for (k =0 ; k <ARRAY_SIZE (pr->enum_ids); k++) {if (pr->enum_ids[k] != source) {
@@ -313,7 +313,7 @@ static void sh_intc_register_source(struct intc_desc *desc,if (groups) {for (i =0 ; i < nr_groups; i++) { -struct intc_group *gr = groups + i; +struct intc_group *gr = &groups[i];for (k =0 ; k <ARRAY_SIZE (gr->enum_ids); k++) {if (gr->enum_ids[k] != source) {
@@ -339,7 +339,7 @@ void sh_intc_register_sources(struct intc_desc *desc,struct intc_source *s;for (i =0 ; i < nr_vectors; i++) { -struct intc_vect *vect = vectors + i; +struct intc_vect *vect = &vectors[i];sh_intc_register_source (desc, vect->enum_id, groups, nr_groups); s =sh_intc_source (desc, vect->enum_id);
@@ -352,7 +352,7 @@ void sh_intc_register_sources(struct intc_desc *desc,if (groups) {for (i =0 ; i < nr_groups; i++) { -struct intc_group *gr = groups + i; +struct intc_group *gr = &groups[i]; s =sh_intc_source (desc, gr->enum_id); s->next_enum_id = gr->enum_ids[0 ];
@@ -385,7 +385,7 @@ static unsigned int sh_intc_register(MemoryRegion *sysmem, } iomem = &desc->iomem; - iomem_p4 = desc->iomem_aliases + index; + iomem_p4 = &desc->iomem_aliases[index]; iomem_a7 = iomem_p4 +1 ;snprintf (name,sizeof (name),"intc-%s-%s-%s" , type, action,"p4" );
@@ -425,7 +425,7 @@ int sh_intc_init(MemoryRegion *sysmem, desc->sources =g_malloc0 (i);for (i =0 ; i < desc->nr_sources; i++) { -struct intc_source *source = desc->sources + i; +struct intc_source *source = &desc->sources[i]; source->parent = desc; }
@@ -436,7 +436,7 @@ int sh_intc_init(MemoryRegion *sysmem,if (desc->mask_regs) {for (i =0 ; i < desc->nr_mask_regs; i++) { -struct intc_mask_reg *mr = desc->mask_regs + i; +struct intc_mask_reg *mr = &desc->mask_regs[i]; j +=sh_intc_register (sysmem, desc, mr->set_reg,"mask" ,"set" , j); j +=sh_intc_register (sysmem, desc, mr->clr_reg,"mask" ,"clr" , j);
@@ -445,7 +445,7 @@ int sh_intc_init(MemoryRegion *sysmem,if (desc->prio_regs) {for (i =0 ; i < desc->nr_prio_regs; i++) { -struct intc_prio_reg *pr = desc->prio_regs + i; +struct intc_prio_reg *pr = &desc->prio_regs[i]; j +=sh_intc_register (sysmem, desc, pr->set_reg,"prio" ,"set" , j); j +=sh_intc_register (sysmem, desc, pr->clr_reg,"prio" ,"clr" , j);
Signature · 1 line
2.21.4
PATCH v6 22/30 hw/intc/sh_intc: Inline and drop sh_intc_source() function
In reply to BALATON ZoltanThis function is very simple and provides no advantage. Call sites become simpler without it so just write it in line and drop the separate function.
--- hw/intc/sh_intc.c | 54 ++++++++++++++++------------------------ hw/sh4/sh7750.c | 4 +-- include/hw/sh4/sh_intc.h | 2 +- 3 files changed, 25 insertions(+), 35 deletions(-)
hw/intc/sh_intc.c +22 -32
@@ -263,33 +263,22 @@ static const MemoryRegionOps sh_intc_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -struct intc_source *sh_intc_source (struct intc_desc *desc,intc_enum id) -{ -if (id) { -return &desc->sources[id]; - } -return NULL ; -} -static void sh_intc_register_source (struct intc_desc *desc,intc_enum source,struct intc_group *groups,int nr_groups) {unsigned int i, k; -struct intc_source *s; +intc_enum id;if (desc->mask_regs) {for (i =0 ; i < desc->nr_mask_regs; i++) {struct intc_mask_reg *mr = &desc->mask_regs[i];for (k =0 ; k <ARRAY_SIZE (mr->enum_ids); k++) { -if (mr->enum_ids[k] != source) { -continue ; - } - s =sh_intc_source (desc, mr->enum_ids[k]); -if (s) { - s->enable_max++; + id = mr->enum_ids[k]; +if (id && id == source) { + desc->sources[id].enable_max++; } } }
@@ -300,12 +289,9 @@ static void sh_intc_register_source(struct intc_desc *desc,struct intc_prio_reg *pr = &desc->prio_regs[i];for (k =0 ; k <ARRAY_SIZE (pr->enum_ids); k++) { -if (pr->enum_ids[k] != source) { -continue ; - } - s =sh_intc_source (desc, pr->enum_ids[k]); -if (s) { - s->enable_max++; + id = pr->enum_ids[k]; +if (id && id == source) { + desc->sources[id].enable_max++; } } }
@@ -316,12 +302,9 @@ static void sh_intc_register_source(struct intc_desc *desc,struct intc_group *gr = &groups[i];for (k =0 ; k <ARRAY_SIZE (gr->enum_ids); k++) { -if (gr->enum_ids[k] != source) { -continue ; - } - s =sh_intc_source (desc, gr->enum_ids[k]); -if (s) { - s->enable_max++; + id = gr->enum_ids[k]; +if (id && id == source) { + desc->sources[id].enable_max++; } } }
@@ -336,14 +319,16 @@ void sh_intc_register_sources(struct intc_desc *desc, int nr_groups) {unsigned int i, k; +intc_enum id;struct intc_source *s;for (i =0 ; i < nr_vectors; i++) {struct intc_vect *vect = &vectors[i];sh_intc_register_source (desc, vect->enum_id, groups, nr_groups); - s =sh_intc_source (desc, vect->enum_id); -if (s) { + id = vect->enum_id; +if (id) { + s = &desc->sources[id]; s->vect = vect->vect;trace_sh_intc_register ("source" , vect->enum_id, s->vect, s->enable_count, s->enable_max);
@@ -354,14 +339,16 @@ void sh_intc_register_sources(struct intc_desc *desc,for (i =0 ; i < nr_groups; i++) {struct intc_group *gr = &groups[i]; - s =sh_intc_source (desc, gr->enum_id); + id = gr->enum_id; + s = &desc->sources[id]; s->next_enum_id = gr->enum_ids[0 ];for (k =1 ; k <ARRAY_SIZE (gr->enum_ids); k++) {if (!gr->enum_ids[k]) {continue ; } - s =sh_intc_source (desc, gr->enum_ids[k -1 ]); + id = gr->enum_ids[k -1 ]; + s = &desc->sources[id]; s->next_enum_id = gr->enum_ids[k]; } trace_sh_intc_register("group", gr->enum_id, 0xffff,
@@ -463,7 +450,10 @@ void sh_intc_set_irl(void *opaque, int n, int level) {struct intc_source *s = opaque;int i, irl = level ^15 ; -for (i =0 ; (s =sh_intc_source (s->parent, s->next_enum_id)); i++) { +intc_enum id = s->next_enum_id; + +for (i =0 ; id; id = s->next_enum_id, i++) { + s = &s->parent->sources[id];if (i == irl) {sh_intc_toggle_source (s, s->enable_count ?0 :1 , s->asserted ?0 :1 );
hw/sh4/sh7750.c +2 -2
@@ -899,6 +899,6 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem)qemu_irq sh7750_irl (SH7750State *s) { -sh_intc_toggle_source (sh_intc_source (&s->intc,IRL ),1 ,0 );/* enable */ -return qemu_allocate_irq (sh_intc_set_irl,sh_intc_source (&s->intc,IRL ),0 ); +sh_intc_toggle_source (&s->intc.sources[IRL ],1 ,0 );/* enable */ +return qemu_allocate_irq (sh_intc_set_irl, &s->intc.sources[IRL ],0 ); }
include/hw/sh4/sh_intc.h +1 -1
@@ -58,7 +58,7 @@ struct intc_desc { };int sh_intc_get_pending_vector (struct intc_desc *desc,int imask); -struct intc_source *sh_intc_source (struct intc_desc *desc,intc_enum id); +void sh_intc_toggle_source (struct intc_source *source,int enable_adj,int assert_adj);
Signature · 1 line
2.21.4
Re: [PATCH v6 22/30] hw/intc/sh_intc: Inline and drop sh_intc_source() function
Quoted 18 lines · BALATON Zoltan
This function is very simple and provides no advantage. Call sites become simpler without it so just write it in line and drop the separate function.
Signed-off-by BALATON Zoltan <[email protected]>--- hw/intc/sh_intc.c | 54 ++++++++++++++++------------------------ hw/sh4/sh7750.c | 4 +-- include/hw/sh4/sh_intc.h | 2 +- 3 files changed, 25 insertions(+), 35 deletions(-)static void sh_intc_register_source(struct
intc_desc*desc,
intc_enumsource, structintc_group*groups, intnr_groups){ unsigned int i, k;
hw/intc/sh_intc.c static const MemoryRegionOps sh_intc_ops = { · line 272
Quoted 2 lines
hw/intc/sh_intc.c +1
-1-struct intc_source *s; +intc_enum id;
Maybe:
assert(source != UNUSED);
hw/intc/sh_intc.c static const MemoryRegionOps sh_intc_ops = { · line 280
Quoted 13 lines
if (desc->mask_regs) { for (i = 0; i < desc->nr_mask_regs; i++) { struct intc_mask_reg *mr = &desc->mask_regs[i]; for (k = 0; k < ARRAY_SIZE(mr->enum_ids); k++) {hw/intc/sh_intc.c +2
-6-if (mr->enum_ids[k] != source) { -continue ; - } - s =sh_intc_source (desc, mr->enum_ids[k]); -if (s) { - s->enable_max++; + id = mr->enum_ids[k]; +if (id && id == source) {
Then you can drop the 'id' checks.
Quoted 4 lines
+ desc->sources[id].enable_max++;
}
}
}Re: [PATCH v6 22/30] hw/intc/sh_intc: Inline and drop sh_intc_source() function
Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 18 lines · BALATON Zoltan
This function is very simple and provides no advantage. Call sites become simpler without it so just write it in line and drop the separate function.
Signed-off-by BALATON Zoltan <[email protected]>--- hw/intc/sh_intc.c | 54 ++++++++++++++++------------------------ hw/sh4/sh7750.c | 4 +-- include/hw/sh4/sh_intc.h | 2 +- 3 files changed, 25 insertions(+), 35 deletions(-)static void sh_intc_register_source(struct
intc_desc*desc,
intc_enumsource, structintc_group*groups, intnr_groups){ unsigned int i, k;hw/intc/sh_intc.c static const MemoryRegionOps sh_intc_ops = { · line 272
Quoted 2 lines
hw/intc/sh_intc.c +1
-1-struct intc_source *s; +intc_enum id;Maybe:
assert(source != UNUSED);hw/intc/sh_intc.c static const MemoryRegionOps sh_intc_ops = { · line 280
Quoted 13 lines
if (desc->mask_regs) { for (i = 0; i < desc->nr_mask_regs; i++) { struct intc_mask_reg *mr = &desc->mask_regs[i]; for (k = 0; k < ARRAY_SIZE(mr->enum_ids); k++) {hw/intc/sh_intc.c +2
-6-if (mr->enum_ids[k] != source) { -continue ; - } - s =sh_intc_source (desc, mr->enum_ids[k]); -if (s) { - s->enable_max++; + id = mr->enum_ids[k]; +if (id && id == source) {
Quoted 1 line
Then you can drop the 'id' checks.
I've tried to preserve the original brhaviour in this patch and not change it for now. This will need to be rewritten anyway beause it does not handle priorities and hard to QOM-ify as it is so I'll come back to this where these will probably change, so for now just leave it to keep the existing behaviour. Then we can revise it later in separate patch.
Thanks for taking the time to review my patches, much appreciated.
Regards,
BALATON Zoltan
Quoted 6 lines
Quoted 4 lines
+ desc->sources[id].enable_max++; } } }
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH v6 22/30] hw/intc/sh_intc: Inline and drop sh_intc_source() function
Quoted 41 lines · BALATON Zoltan
Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 11 lines · BALATON Zoltan
This function is very simple and provides no advantage. Call sites become simpler without it so just write it in line and drop the separate function.
Signed-off-by BALATON Zoltan <[email protected]>---
hw/intc/sh_intc.c | 54 ++++++++++++++++------------------------ hw/sh4/sh7750.c | 4 +--
include/hw/sh4/sh_intc.h | 2 +-3 files changed, 25 insertions(+), 35 deletions(-)Quoted 9 lines
static void
sh_intc_register_source(struct intc_desc *desc, intc_enum source, struct intc_group *groups, int nr_groups)
{
unsigned int i, k;
- structintc_source*s;
+intc_enumid;Maybe:
assert(source != UNUSED);
Quoted 13 lines
if (
desc->mask_regs) {
for (i = 0; i <desc->nr_mask_regs; i++) { structintc_mask_reg*mr = &desc->mask_regs[i];for (k = 0; k <
ARRAY_SIZE(mr->enum_ids); k++) { - if (mr->enum_ids[k] != source) {
- continue;
- }
- s =sh_intc_source(desc, mr->enum_ids[k]); - if (s) {
- s->enable_max++;
+ id = mr->enum_ids[k];
+ if (id && id == source) {
Quoted 7 lines
Quoted 1 line
Then you can drop the 'id' checks.
I've tried to preserve the original brhaviour in this patch and not change it for now. This will need to be rewritten anyway beause it does not handle priorities and hard to QOM-ify as it is so I'll come back to this where these will probably change, so for now just leave it to keep the existing behaviour. Then we can revise it later in separate patch.
Fine.
Quoted 11 lines
Thanks for taking the time to review my patches, much appreciated.
Regards,
BALATON ZoltanQuoted 6 lines
Quoted 4 lines
+ desc->sources[id].enable_max++; }
}
}
PATCH v6 23/30 hw/intc/sh_intc: Replace abort() with g_assert_not_reached()
In reply to BALATON ZoltanAll the places that call abort should not happen which is better marked by g_assert_not_reached.
--- hw/intc/sh_intc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
hw/intc/sh_intc.c +3 -5
@@ -96,8 +96,7 @@ int sh_intc_get_pending_vector(struct intc_desc *desc, int imask)return source->vect; } } - -abort (); +g_assert_not_reached (); }#define INTC_MODE_IS_PRIO 0x80
@@ -169,8 +168,7 @@ static void sh_intc_locate(struct intc_desc *desc,return ; } } - -abort (); +g_assert_not_reached (); } static void sh_intc_toggle_mask(struct intc_desc *desc, intc_enum id,
@@ -241,7 +239,7 @@ static void sh_intc_write(void *opaque, hwaddr offset, value = *valuep & ~value;break ;default : -abort (); +g_assert_not_reached (); }for (k =0 ; k <= first; k++) {
Signature · 1 line
2.21.4
PATCH v6 24/30 hw/intc/sh_intc: Avoid using continue in loops
In reply to BALATON ZoltanInstead of if !expr continue else do something it is more straight forward to say if expr then do something, especially if the action is just a few lines. Remove such uses of continue to make the code easier to follow.
--- hw/intc/sh_intc.c | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-)
hw/intc/sh_intc.c +20 -24
@@ -140,15 +140,14 @@ static void sh_intc_locate(struct intc_desc *desc,struct intc_mask_reg *mr = &desc->mask_regs[i]; mode =sh_intc_mode (address, mr->set_reg, mr->clr_reg); -if (mode ==INTC_MODE_NONE ) { -continue ; +if (mode !=INTC_MODE_NONE ) { + *modep = mode; + *datap = &mr->value; + *enums = mr->enum_ids; + *first = mr->reg_width -1 ; + *width =1 ; +return ; } - *modep = mode; - *datap = &mr->value; - *enums = mr->enum_ids; - *first = mr->reg_width -1 ; - *width =1 ; -return ; } }
@@ -157,15 +156,14 @@ static void sh_intc_locate(struct intc_desc *desc,struct intc_prio_reg *pr = &desc->prio_regs[i]; mode =sh_intc_mode (address, pr->set_reg, pr->clr_reg); -if (mode ==INTC_MODE_NONE ) { -continue ; +if (mode !=INTC_MODE_NONE ) { + *modep = mode |INTC_MODE_IS_PRIO ; + *datap = &pr->value; + *enums = pr->enum_ids; + *first = pr->reg_width / pr->field_width -1 ; + *width = pr->field_width; +return ; } - *modep = mode |INTC_MODE_IS_PRIO ; - *datap = &pr->value; - *enums = pr->enum_ids; - *first = pr->reg_width / pr->field_width -1 ; - *width = pr->field_width; -return ; } }g_assert_not_reached ();
@@ -246,10 +244,9 @@ static void sh_intc_write(void *opaque, hwaddr offset, mask = (1 << width) -1 ; mask <<= (first - k) * width; -if ((*valuep & mask) == (value & mask)) { -continue ; +if ((*valuep & mask) != (value & mask)) { +sh_intc_toggle_mask (desc, enum_ids[k], value & mask,0 ); } -sh_intc_toggle_mask (desc, enum_ids[k], value & mask,0 ); } *valuep = value;
@@ -342,12 +339,11 @@ void sh_intc_register_sources(struct intc_desc *desc, s->next_enum_id = gr->enum_ids[0 ];for (k =1 ; k <ARRAY_SIZE (gr->enum_ids); k++) { -if (!gr->enum_ids[k]) { -continue ; +if (gr->enum_ids[k]) { + id = gr->enum_ids[k -1 ]; + s = &desc->sources[id]; + s->next_enum_id = gr->enum_ids[k]; } - id = gr->enum_ids[k -1 ]; - s = &desc->sources[id]; - s->next_enum_id = gr->enum_ids[k]; }trace_sh_intc_register ("group" , gr->enum_id,0xffff , s->enable_count, s->enable_max);
Signature · 1 line
2.21.4
PATCH v6 25/30 hw/intc/sh_intc: Simplify allocating sources array
In reply to BALATON ZoltanUse g_new0 instead of g_malloc0 and avoid some unneeded temporary variable assignments.
--- hw/intc/sh_intc.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
hw/intc/sh_intc.c +4 -11
@@ -400,21 +400,14 @@ int sh_intc_init(MemoryRegion *sysmem,/* Allocate 4 MemoryRegions per register (2 actions * 2 aliases) */ desc->iomem_aliases =g_new0 (MemoryRegion, (nr_mask_regs + nr_prio_regs) *4 ); - - j =0 ; - i =sizeof (struct intc_source ) * nr_sources; - desc->sources =g_malloc0 (i); - -for (i =0 ; i < desc->nr_sources; i++) { -struct intc_source *source = &desc->sources[i]; - - source->parent = desc; + desc->sources = g_new0(struct intc_source, nr_sources); +for (i =0 ; i < nr_sources; i++) { + desc->sources[i].parent = desc; } - desc->irqs =qemu_allocate_irqs (sh_intc_set_irq, desc, nr_sources);memory_region_init_io (&desc->iomem,NULL , &sh_intc_ops, desc,"intc" ,0x100000000ULL ); - + j =0 ;if (desc->mask_regs) {for (i =0 ; i < desc->nr_mask_regs; i++) {struct intc_mask_reg *mr = &desc->mask_regs[i];
Signature · 1 line
2.21.4
Re: [PATCH v6 25/30] hw/intc/sh_intc: Simplify allocating sources array
Quoted 7 lines · BALATON Zoltan
Use
g_new0instead ofg_malloc0and avoid some unneeded temporary variable assignments.Signed-off-by BALATON Zoltan <[email protected]>--- hw/intc/sh_intc.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
PATCH v6 26/30 hw/intc/sh_intc: Remove unneeded local variable initialisers
In reply to BALATON ZoltanThe sh_intc_locate function will either init these or not return so no need to initialise them.
--- hw/intc/sh_intc.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
hw/intc/sh_intc.c +10 -11
@@ -196,14 +196,13 @@ static void sh_intc_toggle_mask(struct intc_desc *desc, intc_enum id, } } -static uint64_t sh_intc_read (void *opaque,hwaddr offset, -unsigned size) +static uint64_t sh_intc_read (void *opaque,hwaddr offset,unsigned size) {struct intc_desc *desc = opaque; -intc_enum *enum_ids =NULL ; -unsigned int first =0 ; -unsigned int width =0 ; -unsigned int mode =0 ; +intc_enum *enum_ids; +unsigned int first; +unsigned int width; +unsigned int mode;unsigned long *valuep; sh_intc_locate(desc, (unsigned long)offset, &valuep,
@@ -216,12 +215,12 @@ static void sh_intc_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) {struct intc_desc *desc = opaque; -intc_enum *enum_ids =NULL ; -unsigned int first =0 ; -unsigned int width =0 ; -unsigned int mode =0 ; -unsigned int k; +intc_enum *enum_ids; +unsigned int first; +unsigned int width; +unsigned int mode;unsigned long *valuep; +unsigned int k;unsigned long mask;trace_sh_intc_write (size, offset, value);
Signature · 1 line
2.21.4
Re: [PATCH v6 26/30] hw/intc/sh_intc: Remove unneeded local variable initialisers
Quoted 7 lines · BALATON Zoltan
The
sh_intc_locatefunction will either init these or not return so no need to initialise them.Signed-off-by BALATON Zoltan <[email protected]>--- hw/intc/sh_intc.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
PATCH v6 27/30 hw/timer/sh_timer: Rename sh_timer_state to SHTimerState
In reply to BALATON ZoltanAccording to coding style types should be camel case, also remove unneded casts from void *.
---
The tmu012_state is left for now, that's the real exported object with SHTimerState being an internal object for a single timer. I'll come back to this when QOM-ifying so only handled SHTimerState in this patch.
hw/timer/sh_timer.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
hw/timer/sh_timer.c +9 -9
@@ -45,11 +45,11 @@ typedef struct {int feat;int enabled;qemu_irq irq; -} sh_timer_state; +} SHTimerState;/* Check all active timers, and schedule the next timer interrupt. */ -static void sh_timer_update (sh_timer_state *s) +static void sh_timer_update (SHTimerState *s) {int new_level = s->int_level && (s->tcr &TIMER_TCR_UNIE );
@@ -62,7 +62,7 @@ static void sh_timer_update(sh_timer_state *s)static uint32_t sh_timer_read (void *opaque,hwaddr offset) { -sh_timer_state *s = (sh_timer_state *)opaque; +SHTimerState *s = opaque;switch (offset >>2 ) {case OFFSET_TCOR :
@@ -85,7 +85,7 @@ static uint32_t sh_timer_read(void *opaque, hwaddr offset)static void sh_timer_write (void *opaque,hwaddr offset,uint32_t value) { -sh_timer_state *s = (sh_timer_state *)opaque; +SHTimerState *s = opaque;int freq;switch (offset >>2 ) {
@@ -200,7 +200,7 @@ static void sh_timer_write(void *opaque, hwaddr offset,static void sh_timer_start_stop (void *opaque,int enable) { -sh_timer_state *s = (sh_timer_state *)opaque; +SHTimerState *s = opaque;trace_sh_timer_start_stop (enable, s->enabled);ptimer_transaction_begin (s->timer);
@@ -216,14 +216,14 @@ static void sh_timer_start_stop(void *opaque, int enable)static void sh_timer_tick (void *opaque) { -sh_timer_state *s = (sh_timer_state *)opaque; +SHTimerState *s = opaque; s->int_level = s->enabled;sh_timer_update (s); }static void *sh_timer_init (uint32_t freq,int feat,qemu_irq irq) { -sh_timer_state *s; +SHTimerState *s; s =g_malloc0 (sizeof (*s)); s->freq = freq;
@@ -259,7 +259,7 @@ typedef struct {static uint64_t tmu012_read (void *opaque,hwaddr offset,unsigned size) { -tmu012_state *s = (tmu012_state *)opaque; +tmu012_state *s = opaque;trace_sh_timer_read (offset);if (offset >=0x20 ) {
@@ -289,7 +289,7 @@ static uint64_t tmu012_read(void *opaque, hwaddr offset,static void tmu012_write (void *opaque,hwaddr offset,uint64_t value,unsigned size) { -tmu012_state *s = (tmu012_state *)opaque; +tmu012_state *s = opaque;trace_sh_timer_write (offset, value);if (offset >=0x20 ) {
Signature · 1 line
2.21.4
PATCH v6 28/30 hw/timer/sh_timer: Do not wrap lines that are not too long
In reply to BALATON ZoltanIt's more readable to keep things on one line if it fits the length limit.
--- hw/timer/sh_timer.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
hw/timer/sh_timer.c +3 -6
@@ -82,8 +82,7 @@ static uint32_t sh_timer_read(void *opaque, hwaddr offset) } } -static void sh_timer_write (void *opaque,hwaddr offset, -uint32_t value) +static void sh_timer_write (void *opaque,hwaddr offset,uint32_t value) {SHTimerState *s = opaque;int freq;
@@ -256,8 +255,7 @@ typedef struct {int feat; } tmu012_state; -static uint64_t tmu012_read (void *opaque,hwaddr offset, -unsigned size) +static uint64_t tmu012_read (void *opaque,hwaddr offset,unsigned size) {tmu012_state *s = opaque;
@@ -336,8 +334,7 @@ static const MemoryRegionOps tmu012_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -void tmu012_init (MemoryRegion *sysmem,hwaddr base, -int feat,uint32_t freq, +void tmu012_init (MemoryRegion *sysmem,hwaddr base,int feat,uint32_t freq,qemu_irq ch0_irq,qemu_irq ch1_irq,qemu_irq ch2_irq0,qemu_irq ch2_irq1) {
Signature · 1 line
2.21.4
PATCH v6 29/30 hw/timer/sh_timer: Fix timer memory region size
In reply to BALATON ZoltanThe timer memory region is only accessed via aliases that are 0x1000 bytes long, no need to have the timer region larger than that.
--- hw/timer/sh_timer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/timer/sh_timer.c +1 -2
@@ -350,8 +350,7 @@ void tmu012_init(MemoryRegion *sysmem, hwaddr base, int feat, uint32_t freq, ch2_irq0); /* ch2_irq1 not supported */ } -memory_region_init_io (&s->iomem,NULL , &tmu012_ops, s, -"timer" ,0x100000000ULL ); +memory_region_init_io (&s->iomem,NULL , &tmu012_ops, s,"timer" ,0x1000 );memory_region_init_alias (&s->iomem_p4,NULL ,"timer-p4" , &s->iomem,0 ,0x1000 );
Signature · 1 line
2.21.4
Re: [PATCH v6 29/30] hw/timer/sh_timer: Fix timer memory region size
Quoted 13 lines · BALATON Zoltan
The timer memory region is only accessed via aliases that are
0x1000bytes long, no need to have the timer region larger than that.Signed-off-by BALATON Zoltan <[email protected]>--- hw/timer/sh_timer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)hw/timer/sh_timer.c +0
-0
hw/timer/sh_timer.c void tmu012_init(MemoryRegion *sysmem, hwaddr base, int feat, uint32_t freq, · line 353
Quoted 6 lines
hw/timer/sh_timer.c +1
-2@@ -350,8 +350,7 @@ void tmu012_init(MemoryRegion *sysmem, hwaddr base, int feat, uint32_t freq, ch2_irq0); /* ch2_irq1 not supported */ } -memory_region_init_io (&s->iomem,NULL , &tmu012_ops, s, -"timer" ,0x100000000ULL ); +memory_region_init_io (&s->iomem,NULL , &tmu012_ops, s,"timer" ,0x1000 );
Per the manual (R01UH0457EJ0401 Rev. 4.01 [*]) Page 317/1128, Table 12.2 "TMU Registers" the first 3 timers (implemented by the tmu012_state structure) fit in a region of 0x30 bytes.
Looking at hw/timer/sh_timer.c I only see a maximum access of 0x40, where 0x1000 comes from? The P4/A7 aliases?
If you have a way to test and ack, I can replace by 0x40 when applying.
Re: [PATCH v6 29/30] hw/timer/sh_timer: Fix timer memory region size
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 16 lines · BALATON Zoltan
The timer memory region is only accessed via aliases that are
0x1000bytes long, no need to have the timer region larger than that.Signed-off-by BALATON Zoltan <[email protected]>--- hw/timer/sh_timer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)hw/timer/sh_timer.c +0
-0@@ -350,8 +350,7 @@ void tmu012_init(MemoryRegion *sysmem, hwaddr base, int feat, uint32_t freq, ch2_irq0); /* ch2_irq1 not supported */ }
Quoted 7 lines
hw/timer/sh_timer.c void tmu012_init(MemoryRegion *sysmem, hwaddr base, int feat, uint32_t freq, · line 353
Quoted 3 lines
hw/timer/sh_timer.c +1
-2-memory_region_init_io (&s->iomem,NULL , &tmu012_ops, s, -"timer" ,0x100000000ULL ); +memory_region_init_io (&s->iomem,NULL , &tmu012_ops, s,"timer" ,0x1000 );Per the manual (R01UH0457EJ0401 Rev. 4.01 [*]) Page 317/1128, Table 12.2 "TMU Registers" the first 3 timers (implemented by the
tmu012_statestructure) fit in a region of0x30bytes.
Sent a v7 of this patch only changing it to 0x30 with which the Linux image I've tested still boots but don't know if it uses a timer at all.
Quoted 1 line
Looking at
hw/timer/sh_timer.cI only see a maximum access of0x40,
Where do you see 0x40?
Quoted 1 line
where
0x1000comes from? The P4/A7 aliases?
Yes, as the commit message said. Since this was a last minute change I tried to be safe and not change anything guest visible at this point.
Quoted 1 line
If you have a way to test and ack, I can replace by
0x40when applying.
If you think 0x40 is better then I'm fine with that but I don't see a register after 0x2c which is 32 bits so 0x30 length should be enough according to that.
Regards.
BALATON Zoltan
Re: [PATCH v6 29/30] hw/timer/sh_timer: Fix timer memory region size
Quoted 29 lines · BALATON Zoltan
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 18 lines · BALATON Zoltan
The timer memory region is only accessed via aliases that are
0x1000bytes long, no need to have the timer region larger than that.Signed-off-by BALATON Zoltan <[email protected]>---
hw/timer/sh_timer.c | 3 +--1 file changed, 1 insertion(+), 2 deletions(-)hw/timer/sh_timer.c +0
-0@@ -350,8 +350,7 @@ void tmu012_init(MemoryRegion *sysmem, hwaddr base, int feat, uint32_t freq,
ch2_irq0); /*ch2_irq1not supported */
}Quoted 8 lines
Quoted 4 lines
- memory_region_init_io(&s->iomem, NULL,
&tmu012_ops, s, - "timer",0x100000000ULL);
+memory_region_init_io(&s->iomem, NULL, &tmu012_ops, s, "timer", 0x1000);Per the manual (R01UH0457EJ0401 Rev. 4.01 [*]) Page 317/1128, Table 12.2 "TMU Registers" the first 3 timers (implemented by the
tmu012_statestructure) fit in a region of0x30bytes.
Quoted 6 lines
Sent a v7 of this patch only changing it to
0x30with which the Linux image I've tested still boots but don't know if it uses a timer at all.Quoted 1 line
Looking at
hw/timer/sh_timer.cI only see a maximum access of0x40,Where do you see
0x40?
I just looked at tmu012_read(), not sh_timer_read(). Now looking at it, the later only parses a 0x10 region, so total is 0x30 indeed.
Quoted 5 lines
Quoted 2 lines
where
0x1000comes from? The P4/A7 aliases?Yes, as the commit message said. Since this was a last minute change I tried to be safe and not change anything guest visible at this point.
We should avoid last minute changes days before soft freeze ;)
Quoted 5 lines
Quoted 1 line
If you have a way to test and ack, I can replace by
0x40when applying.If you think
0x40is better then I'm fine with that but I don't see a register after0x2cwhich is 32 bits so0x30length should be enough according to that.
Yes, 0x30 is correct, I'll take your v7 patch.
Thanks,
Phil.
PATCH v7 29/30 hw/timer/sh_timer: Fix timer memory region size
In reply to BALATON ZoltanThe timer unit only has registers that fit in a region 0x30 bytes long. No need to have the timer region larger than that.
--- hw/timer/sh_timer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
hw/timer/sh_timer.c +3 -4
@@ -350,15 +350,14 @@ void tmu012_init(MemoryRegion *sysmem, hwaddr base, int feat, uint32_t freq, ch2_irq0); /* ch2_irq1 not supported */ } -memory_region_init_io (&s->iomem,NULL , &tmu012_ops, s, -"timer" ,0x100000000ULL ); +memory_region_init_io (&s->iomem,NULL , &tmu012_ops, s,"timer" ,0x30 );memory_region_init_alias (&s->iomem_p4,NULL ,"timer-p4" , - &s->iomem,0 ,0x1000 ); + &s->iomem,0 ,memory_region_size (&s->iomem));memory_region_add_subregion (sysmem,P4ADDR (base), &s->iomem_p4);memory_region_init_alias (&s->iomem_a7,NULL ,"timer-a7" , - &s->iomem,0 ,0x1000 ); + &s->iomem,0 ,memory_region_size (&s->iomem));memory_region_add_subregion (sysmem,A7ADDR (base), &s->iomem_a7);/* ??? Save/restore. */ }
Signature · 1 line
2.21.4
Re: [PATCH v7 29/30] hw/timer/sh_timer: Fix timer memory region size
Quoted 22 lines · BALATON Zoltan
The timer unit only has registers that fit in a region
0x30bytes long. No need to have the timer region larger than that.Signed-off-by BALATON Zoltan <[email protected]>--- hw/timer/sh_timer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)hw/timer/sh_timer.c +1
-2@@ -350,15 +350,14 @@ void tmu012_init(MemoryRegion *sysmem, hwaddr base, int feat, uint32_t freq, ch2_irq0); /* ch2_irq1 not supported */ } -memory_region_init_io (&s->iomem,NULL , &tmu012_ops, s, -"timer" ,0x100000000ULL ); +memory_region_init_io (&s->iomem,NULL , &tmu012_ops, s,"timer" ,0x30 ); memory_region_init_alias(&s->iomem_p4, NULL, "timer-p4",
hw/timer/sh_timer.c void tmu012_init(MemoryRegion *sysmem, hwaddr base, int feat, uint32_t freq, · line 363
Quoted 10 lines
hw/timer/sh_timer.c +2
-2- &s->iomem, 0, 0x1000); + &s->iomem, 0, memory_region_size(&s->iomem));memory_region_add_subregion (sysmem,P4ADDR (base), &s->iomem_p4);memory_region_init_alias (&s->iomem_a7,NULL ,"timer-a7" , - &s->iomem,0 ,0x1000 ); + &s->iomem,0 ,memory_region_size (&s->iomem));memory_region_add_subregion (sysmem,A7ADDR (base), &s->iomem_a7);/* ??? Save/restore. */ }
PATCH v6 30/30 hw/timer/sh_timer: Remove use of hw_error
In reply to BALATON ZoltanThe hw_error function calls abort and is not meant to be used by devices. Use qemu_log_mask instead to log and ignore invalid accesses. Also fix format strings to allow dropping type casts of hwaddr and use __func__ instead of hard coding function name in the message which were wrong in two cases.
--- hw/timer/sh_timer.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-)
hw/timer/sh_timer.c +25 -15
@@ -10,7 +10,7 @@#include "qemu/osdep.h" #include "exec/memory.h" -#include "hw/hw.h" +#include "qemu/log.h" #include "hw/irq.h" #include "hw/sh4/sh.h" #include "hw/timer/tmu012.h"
@@ -75,11 +75,10 @@ static uint32_t sh_timer_read(void *opaque, hwaddr offset)if (s->feat &TIMER_FEAT_CAPT ) {return s->tcpr; } -/* fall through */ -default : -hw_error ("sh_timer_read: Bad offset %x\n" , (int )offset); -return 0 ; } +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); +return 0 ; }static void sh_timer_write (void *opaque,hwaddr offset,uint32_t value)
@@ -134,7 +133,8 @@ static void sh_timer_write(void *opaque, hwaddr offset, uint32_t value) }/* fallthrough */ default : -hw_error ("sh_timer_write: Reserved TPSC value\n" ); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Reserved TPSC value\n" , __func__); }switch ((value &TIMER_TCR_CKEG ) >>3 ) {case 0 :
@@ -147,7 +147,8 @@ static void sh_timer_write(void *opaque, hwaddr offset, uint32_t value) }/* fallthrough */ default : -hw_error ("sh_timer_write: Reserved CKEG value\n" ); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Reserved CKEG value\n" , __func__); }switch ((value &TIMER_TCR_ICPE ) >>6 ) {case 0 :
@@ -159,7 +160,8 @@ static void sh_timer_write(void *opaque, hwaddr offset, uint32_t value) }/* fallthrough */ default : -hw_error ("sh_timer_write: Reserved ICPE value\n" ); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Reserved ICPE value\n" , __func__); }if ((value &TIMER_TCR_UNF ) ==0 ) { s->int_level =0 ;
@@ -168,13 +170,15 @@ static void sh_timer_write(void *opaque, hwaddr offset, uint32_t value) value &= ~TIMER_TCR_UNF ;if ((value &TIMER_TCR_ICPF ) && (!(s->feat &TIMER_FEAT_CAPT ))) { -hw_error ("sh_timer_write: Reserved ICPF value\n" ); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Reserved ICPF value\n" , __func__); } value &= ~TIMER_TCR_ICPF ;/* capture not supported */ if (value &TIMER_TCR_RESERVED ) { -hw_error ("sh_timer_write: Reserved TCR bits set\n" ); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Reserved TCR bits set\n" , __func__); } s->tcr = value;ptimer_set_limit (s->timer, s->tcor,0 );
@@ -192,7 +196,8 @@ static void sh_timer_write(void *opaque, hwaddr offset, uint32_t value) }/* fallthrough */ default : -hw_error ("sh_timer_write: Bad offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, offset); }sh_timer_update (s); }
@@ -262,7 +267,9 @@ static uint64_t tmu012_read(void *opaque, hwaddr offset, unsigned size)trace_sh_timer_read (offset);if (offset >=0x20 ) {if (!(s->feat &TMU012_FEAT_3CHAN )) { -hw_error ("tmu012_write: Bad channel offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad channel offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); }return sh_timer_read (s->timer[2 ], offset -0x20 ); }
@@ -280,7 +287,8 @@ static uint64_t tmu012_read(void *opaque, hwaddr offset, unsigned size)return s->tocr; } -hw_error ("tmu012_write: Bad offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, offset);return 0 ; }
@@ -292,7 +300,9 @@ static void tmu012_write(void *opaque, hwaddr offset,trace_sh_timer_write (offset, value);if (offset >=0x20 ) {if (!(s->feat &TMU012_FEAT_3CHAN )) { -hw_error ("tmu012_write: Bad channel offset %x\n" , (int )offset); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad channel offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); }sh_timer_write (s->timer[2 ], offset -0x20 , value);return ;
@@ -315,7 +325,7 @@ static void tmu012_write(void *opaque, hwaddr offset,sh_timer_start_stop (s->timer[2 ], value & (1 <<2 )); }else {if (value & (1 <<2 )) { -hw_error ("tmu012_write: Bad channel\n" ); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad channel\n" , __func__); } }
Signature · 1 line
2.21.4
Re: [PATCH v6 30/30] hw/timer/sh_timer: Remove use of hw_error
Quoted 26 lines · BALATON Zoltan
The
hw_errorfunction calls abort and is not meant to be used by devices. Useqemu_log_maskinstead to log and ignore invalid accesses. Also fix format strings to allow dropping type casts of hwaddr and use__func__instead of hard coding function name in the message which were wrong in two cases.Signed-off-by BALATON Zoltan <[email protected]>--- hw/timer/sh_timer.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-)hw/timer/sh_timer.c +1
-1@@ -10,7 +10,7 @@#include "qemu/osdep.h" #include "exec/memory.h" -#include "hw/hw.h" +#include "qemu/log.h" #include "hw/irq.h" #include "hw/sh4/sh.h" #include "hw/timer/tmu012.h" @@ -75,11 +75,10 @@ static uint32_t sh_timer_read(void *opaque, hwaddr offset)if (s->feat &TIMER_FEAT_CAPT ) {
hw/timer/sh_timer.c static uint32_t sh_timer_read(void *opaque, hwaddr offset) · line 81
Quoted 10 lines
hw/timer/sh_timer.c +3
-4return s->tcpr; } -/* fall through */ -default : -hw_error ("sh_timer_read: Bad offset %x\n" , (int )offset); -return 0 ; } +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); +return 0 ;
Note, keeping the default case allow to refactor for single return, so it is easier to add trace event.
Anyhow,
Re: [PATCH v6 30/30] hw/timer/sh_timer: Remove use of hw_error
Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 26 lines · BALATON Zoltan
The
hw_errorfunction calls abort and is not meant to be used by devices. Useqemu_log_maskinstead to log and ignore invalid accesses. Also fix format strings to allow dropping type casts of hwaddr and use__func__instead of hard coding function name in the message which were wrong in two cases.Signed-off-by BALATON Zoltan <[email protected]>--- hw/timer/sh_timer.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-)hw/timer/sh_timer.c +1
-1@@ -10,7 +10,7 @@#include "qemu/osdep.h" #include "exec/memory.h" -#include "hw/hw.h" +#include "qemu/log.h" #include "hw/irq.h" #include "hw/sh4/sh.h" #include "hw/timer/tmu012.h" @@ -75,11 +75,10 @@ static uint32_t sh_timer_read(void *opaque, hwaddr offset)if (s->feat &TIMER_FEAT_CAPT ) {hw/timer/sh_timer.c static uint32_t sh_timer_read(void *opaque, hwaddr offset) · line 81
Quoted 10 lines
hw/timer/sh_timer.c +3
-4return s->tcpr; } -/* fall through */ -default : -hw_error ("sh_timer_read: Bad offset %x\n" , (int )offset); -return 0 ; } +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); +return 0 ;Note, keeping the default case allow to refactor for single return, so it is easier to add trace event.
Quoted 2 lines
Anyhow,
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
It's easy enough to change back if adding a trace point in the future so for now I'd leave it at the end outside the if as in this patch. This could be revisited when QOM-ifying it in the future, don't think it's a big deal.
Regards,
BALATON Zoltan
Quoted 35 lines · BALATON Zoltan
This now includes the previous code style clean up series so everything is in the series now. This got big enough for now so I'll wait until these are merged (hopefully before the freeze) before going on so I don't have to carry them in my tree. Only plan to submit another version if needed from review otherwise that's it for now, hopefully this is the last version.
v6: Found some lines with wrong indentation missed in code style clean up and one line missed removing
sh_intc_sourcefrom header so I'm posting the whole series with these two small fixes, otherwise same as v5 but rebased on fixed code style series which is now also included.BALATON Zoltan (30):
hw/sh4: Coding style: Remove tabs
hw/sh4: Coding style: Fix multi-line comments
hw/sh4: Coding style: White space fixes
hw/sh4: Coding style: Add missing braces
hw/sh4: Coding style: Remove unnecessary casts
hw/sh4: Fix typos in a comment
hw/sh4: Change debug printfs to traces
hw/sh4/r2d: Useerror_reportinstead of fprintf to stderr hw/char/sh_serial: Do not abort on invalid access hw/char/sh_serial: Rename typesh_serial_stateto SHSerialState hw/char/sh_serial: Embed QEMUTimer in state struct hw/char/sh_serial: Split offsh_serial_reset()fromsh_serial_init()hw/char/sh_serial: QOM-ify
hw/char/sh_serial: Add device id to trace output hw/intc/sh_intc: Use existing macro instead of local one hw/intc/sh_intc: Turn some defines into an enum hw/intc/sh_intc: Rename iomem region
hw/intc/sh_intc: Drop another useless macro hw/intc/sh_intc: Movesh_intc_register()closer to its only user hw/intc/sh_intc: Remove excessive parenthesis hw/intc/sh_intc: Use array index instead of pointer arithmetics hw/intc/sh_intc: Inline and dropsh_intc_source()function
Quoted 8 lines
hw/intc/sh_intc: Replace
abort()withg_assert_not_reached()hw/intc/sh_intc: Avoid using continue in loops hw/intc/sh_intc: Simplify allocating sources array hw/intc/sh_intc: Remove unneeded local variable initialisers hw/timer/sh_timer: Renamesh_timer_stateto SHTimerState hw/timer/sh_timer: Do not wrap lines that are not too long hw/timer/sh_timer: Fix timer memory region size hw/timer/sh_timer: Remove use ofhw_error
Hmm there is something odd with your mailer, your patches are not sent in order, making it hard for tools to collect them.
Quoted 45 lines · Philippe Mathieu-Daudé
Quoted 35 lines · BALATON Zoltan
This now includes the previous code style clean up series so everything is in the series now. This got big enough for now so I'll wait until these are merged (hopefully before the freeze) before going on so I don't have to carry them in my tree. Only plan to submit another version if needed from review otherwise that's it for now, hopefully this is the last version.
v6: Found some lines with wrong indentation missed in code style clean up and one line missed removing
sh_intc_sourcefrom header so I'm posting the whole series with these two small fixes, otherwise same as v5 but rebased on fixed code style series which is now also included.BALATON Zoltan (30):
hw/sh4: Coding style: Remove tabs
hw/sh4: Coding style: Fix multi-line comments
hw/sh4: Coding style: White space fixes
hw/sh4: Coding style: Add missing braces
hw/sh4: Coding style: Remove unnecessary casts
hw/sh4: Fix typos in a comment
hw/sh4: Change debug printfs to traces
hw/sh4/r2d: Useerror_reportinstead of fprintf to stderr hw/char/sh_serial: Do not abort on invalid access hw/char/sh_serial: Rename typesh_serial_stateto SHSerialState hw/char/sh_serial: Embed QEMUTimer in state struct hw/char/sh_serial: Split offsh_serial_reset()fromsh_serial_init()hw/char/sh_serial: QOM-ify
hw/char/sh_serial: Add device id to trace output hw/intc/sh_intc: Use existing macro instead of local one hw/intc/sh_intc: Turn some defines into an enum hw/intc/sh_intc: Rename iomem region
hw/intc/sh_intc: Drop another useless macro hw/intc/sh_intc: Movesh_intc_register()closer to its only user hw/intc/sh_intc: Remove excessive parenthesis hw/intc/sh_intc: Use array index instead of pointer arithmetics hw/intc/sh_intc: Inline and dropsh_intc_source()functionQuoted 8 lines
hw/intc/sh_intc: Replace
abort()withg_assert_not_reached()hw/intc/sh_intc: Avoid using continue in loops hw/intc/sh_intc: Simplify allocating sources array hw/intc/sh_intc: Remove unneeded local variable initialisers hw/timer/sh_timer: Renamesh_timer_stateto SHTimerState hw/timer/sh_timer: Do not wrap lines that are not too long hw/timer/sh_timer: Fix timer memory region size hw/timer/sh_timer: Remove use ofhw_error
Quoted 2 lines
Hmm there is something odd with your mailer, your patches are not sent in order, making it hard for tools to collect them.
I know, sorry. Sort by name, that should fix the order. I use git format-patch but maybe don't know the right option for it to generate correct dates.
Regards,
BALATON Zoltan
Quoted 23 lines · BALATON Zoltan
BALATON Zoltan (30):
hw/sh4: Coding style: Remove tabs
hw/sh4: Coding style: Fix multi-line comments
hw/sh4: Coding style: White space fixes
hw/sh4: Coding style: Add missing braces
hw/sh4: Coding style: Remove unnecessary casts
hw/sh4: Fix typos in a comment
hw/sh4: Change debug printfs to traces
hw/sh4/r2d: Useerror_reportinstead of fprintf to stderr hw/char/sh_serial: Do not abort on invalid access hw/char/sh_serial: Rename typesh_serial_stateto SHSerialState hw/char/sh_serial: Embed QEMUTimer in state struct hw/char/sh_serial: Split offsh_serial_reset()fromsh_serial_init()hw/char/sh_serial: QOM-ify
hw/char/sh_serial: Add device id to trace output hw/intc/sh_intc: Use existing macro instead of local one hw/intc/sh_intc: Turn some defines into an enum hw/intc/sh_intc: Rename iomem region
hw/intc/sh_intc: Drop another useless macro hw/intc/sh_intc: Movesh_intc_register()closer to its only user hw/intc/sh_intc: Remove excessive parenthesis hw/intc/sh_intc: Use array index instead of pointer arithmetics hw/intc/sh_intc: Inline and dropsh_intc_source()function
Quoted 8 lines
hw/intc/sh_intc: Replace
abort()withg_assert_not_reached()hw/intc/sh_intc: Avoid using continue in loops hw/intc/sh_intc: Simplify allocating sources array hw/intc/sh_intc: Remove unneeded local variable initialisers hw/timer/sh_timer: Renamesh_timer_stateto SHTimerState hw/timer/sh_timer: Do not wrap lines that are not too long hw/timer/sh_timer: Fix timer memory region size hw/timer/sh_timer: Remove use ofhw_error
Thanks, series queued.
Since you are hacking the SH-4 machines, please have a look at Yoshinori work, possibly helping with reviewing once he respin these series, which are good material (and where we want to take our emulation) but are not yet ready for upstream:
"Unified peripheral emulation for Renesas chips"
https://www.mail-archive.com/[email protected]/msg811384.html
"Integrate renesas MCU/SoC timer module"
https://www.mail-archive.com/[email protected]/msg818332.html
Regards,
Phil.
Hello,
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 23 lines · BALATON Zoltan
BALATON Zoltan (30):
hw/sh4: Coding style: Remove tabs
hw/sh4: Coding style: Fix multi-line comments
hw/sh4: Coding style: White space fixes
hw/sh4: Coding style: Add missing braces
hw/sh4: Coding style: Remove unnecessary casts
hw/sh4: Fix typos in a comment
hw/sh4: Change debug printfs to traces
hw/sh4/r2d: Useerror_reportinstead of fprintf to stderr hw/char/sh_serial: Do not abort on invalid access hw/char/sh_serial: Rename typesh_serial_stateto SHSerialState hw/char/sh_serial: Embed QEMUTimer in state struct hw/char/sh_serial: Split offsh_serial_reset()fromsh_serial_init()hw/char/sh_serial: QOM-ify
hw/char/sh_serial: Add device id to trace output hw/intc/sh_intc: Use existing macro instead of local one hw/intc/sh_intc: Turn some defines into an enum hw/intc/sh_intc: Rename iomem region
hw/intc/sh_intc: Drop another useless macro hw/intc/sh_intc: Movesh_intc_register()closer to its only user hw/intc/sh_intc: Remove excessive parenthesis hw/intc/sh_intc: Use array index instead of pointer arithmetics hw/intc/sh_intc: Inline and dropsh_intc_source()functionQuoted 8 lines
hw/intc/sh_intc: Replace
abort()withg_assert_not_reached()hw/intc/sh_intc: Avoid using continue in loops hw/intc/sh_intc: Simplify allocating sources array hw/intc/sh_intc: Remove unneeded local variable initialisers hw/timer/sh_timer: Renamesh_timer_stateto SHTimerState hw/timer/sh_timer: Do not wrap lines that are not too long hw/timer/sh_timer: Fix timer memory region size hw/timer/sh_timer: Remove use ofhw_error
Quoted 1 line
Thanks, series queued.
Thanks again for taking care of this.
Quoted 10 lines
Since you are hacking the SH-4 machines, please have a look at Yoshinori work, possibly helping with reviewing once he respin these series, which are good material (and where we want to take our emulation) but are not yet ready for upstream:
"Unified peripheral emulation for Renesas chips"
https://www.mail-archive.com/[email protected]/msg811384.html"Integrate renesas MCU/SoC timer module"
https://www.mail-archive.com/[email protected]/msg818332.html
I'll try to do what I can but don't know SH too much just found it interesting so looked at it a bit. These series seem to touch timer and serial so I'll keep out of those now to not cause more rebasing for Yoshinori. (If you told me before then maybe I've left those but hopefully the clean up in this series does not cause big problems for rebasing the RX series and maybe help a little to see clearer what existing code does or where it should go.)
I plan to work on sh_intc next as that seems to need some improvements. Yoshinori, do you have any patches or plans for sh_intc? Maybe the interrupt controllers are different in RX and SH so these will be kept separate but asking to avoid doing work that's intended to be replaced anyway.
Regards,
BALATON Zoltan