Message ID | 20180420145249.32435-14-peter.maydell@linaro.org |
---|---|
State | New |
Headers | show |
Series | Drop compile time limit on number of serial ports | expand |
On 04/20/2018 11:52 AM, Peter Maydell wrote: > Create a new function max_serial_hds() which returns the number of > serial ports defined by the user. This is needed only by spapr. > This allows us to remove the MAX_SERIAL_PORTS define. > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> > --- > include/sysemu/sysemu.h | 6 ++++-- > hw/ppc/spapr.c | 2 +- > vl.c | 5 +++++ > 3 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h > index 989cbc2b7b..612659a718 100644 > --- a/include/sysemu/sysemu.h > +++ b/include/sysemu/sysemu.h > @@ -159,10 +159,12 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); > > /* serial ports */ > > -#define MAX_SERIAL_PORTS 4 > - > /* Return the Chardev for serial port i, or NULL if none */ > Chardev *serial_hd(int i); > +/* return the number of serial ports defined by the user. serial_hd(i) > + * will always return NULL for any i which is greater than or equal to this. > + */ > +int max_serial_hds(void); What about naming it serial_hds_count() to keep this under the serial_ namespace? And about using a size_t for num_serial_hds? Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > > /* parallel ports */ > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index b0ecfaca9e..8d2d36a606 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -2589,7 +2589,7 @@ static void spapr_machine_init(MachineState *machine) > /* Set up VIO bus */ > spapr->vio_bus = spapr_vio_bus_init(); > > - for (i = 0; i < MAX_SERIAL_PORTS; i++) { > + for (i = 0; i < max_serial_hds(); i++) { > if (serial_hd(i)) { > spapr_vty_create(spapr->vio_bus, serial_hd(i)); > } > diff --git a/vl.c b/vl.c > index a8a98c5a37..b587187052 100644 > --- a/vl.c > +++ b/vl.c > @@ -2524,6 +2524,11 @@ Chardev *serial_hd(int i) > return NULL; > } > > +int max_serial_hds(void) > +{ > + return num_serial_hds; > +} > + > static int parallel_parse(const char *devname) > { > static int index = 0; >
On 20.04.2018 16:52, Peter Maydell wrote: > Create a new function max_serial_hds() which returns the number of > serial ports defined by the user. This is needed only by spapr. > > This allows us to remove the MAX_SERIAL_PORTS define. > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> > --- > include/sysemu/sysemu.h | 6 ++++-- > hw/ppc/spapr.c | 2 +- > vl.c | 5 +++++ > 3 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h > index 989cbc2b7b..612659a718 100644 > --- a/include/sysemu/sysemu.h > +++ b/include/sysemu/sysemu.h > @@ -159,10 +159,12 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); > > /* serial ports */ > > -#define MAX_SERIAL_PORTS 4 > - > /* Return the Chardev for serial port i, or NULL if none */ > Chardev *serial_hd(int i); > +/* return the number of serial ports defined by the user. serial_hd(i) > + * will always return NULL for any i which is greater than or equal to this. > + */ > +int max_serial_hds(void); > > /* parallel ports */ > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index b0ecfaca9e..8d2d36a606 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -2589,7 +2589,7 @@ static void spapr_machine_init(MachineState *machine) > /* Set up VIO bus */ > spapr->vio_bus = spapr_vio_bus_init(); > > - for (i = 0; i < MAX_SERIAL_PORTS; i++) { > + for (i = 0; i < max_serial_hds(); i++) { > if (serial_hd(i)) { > spapr_vty_create(spapr->vio_bus, serial_hd(i)); > } > diff --git a/vl.c b/vl.c > index a8a98c5a37..b587187052 100644 > --- a/vl.c > +++ b/vl.c > @@ -2524,6 +2524,11 @@ Chardev *serial_hd(int i) > return NULL; > } > > +int max_serial_hds(void) > +{ > + return num_serial_hds; > +} > + > static int parallel_parse(const char *devname) > { > static int index = 0; > Reviewed-by: Thomas Huth <thuth@redhat.com>
On 20 April 2018 at 18:50, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote: > On 04/20/2018 11:52 AM, Peter Maydell wrote: >> Create a new function max_serial_hds() which returns the number of >> serial ports defined by the user. This is needed only by spapr. >> This allows us to remove the MAX_SERIAL_PORTS define. >> >> Signed-off-by: Peter Maydell <peter.maydell@linaro.org> >> --- >> include/sysemu/sysemu.h | 6 ++++-- >> hw/ppc/spapr.c | 2 +- >> vl.c | 5 +++++ >> 3 files changed, 10 insertions(+), 3 deletions(-) >> >> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h >> index 989cbc2b7b..612659a718 100644 >> --- a/include/sysemu/sysemu.h >> +++ b/include/sysemu/sysemu.h >> @@ -159,10 +159,12 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); >> >> /* serial ports */ >> >> -#define MAX_SERIAL_PORTS 4 >> - >> /* Return the Chardev for serial port i, or NULL if none */ >> Chardev *serial_hd(int i); >> +/* return the number of serial ports defined by the user. serial_hd(i) >> + * will always return NULL for any i which is greater than or equal to this. >> + */ >> +int max_serial_hds(void); > > What about naming it serial_hds_count() to keep this under the serial_ > namespace? OK, makes sense. > And about using a size_t for num_serial_hds? This doesn't seem worthwhile though. Since the rename of max_serial_hds is the only change here, I propose to apply this to master (fixing up the function name in this patch in the process), to reduce the number of conflicts with other changes currently in-flight. thanks -- PMM
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 989cbc2b7b..612659a718 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -159,10 +159,12 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); /* serial ports */ -#define MAX_SERIAL_PORTS 4 - /* Return the Chardev for serial port i, or NULL if none */ Chardev *serial_hd(int i); +/* return the number of serial ports defined by the user. serial_hd(i) + * will always return NULL for any i which is greater than or equal to this. + */ +int max_serial_hds(void); /* parallel ports */ diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index b0ecfaca9e..8d2d36a606 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2589,7 +2589,7 @@ static void spapr_machine_init(MachineState *machine) /* Set up VIO bus */ spapr->vio_bus = spapr_vio_bus_init(); - for (i = 0; i < MAX_SERIAL_PORTS; i++) { + for (i = 0; i < max_serial_hds(); i++) { if (serial_hd(i)) { spapr_vty_create(spapr->vio_bus, serial_hd(i)); } diff --git a/vl.c b/vl.c index a8a98c5a37..b587187052 100644 --- a/vl.c +++ b/vl.c @@ -2524,6 +2524,11 @@ Chardev *serial_hd(int i) return NULL; } +int max_serial_hds(void) +{ + return num_serial_hds; +} + static int parallel_parse(const char *devname) { static int index = 0;
Create a new function max_serial_hds() which returns the number of serial ports defined by the user. This is needed only by spapr. This allows us to remove the MAX_SERIAL_PORTS define. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> --- include/sysemu/sysemu.h | 6 ++++-- hw/ppc/spapr.c | 2 +- vl.c | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-)