Message ID | 20190124111634.4727-2-alexandru.elisei@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | arm/arm64: Add support for running under kvmtool | expand |
On Thu, 24 Jan 2019 11:16:28 +0000 Alexandru Elisei <alexandru.elisei@arm.com> wrote: > Add support for discovering the ns16550a UART from the device tree. > This particular UART model is emulated by kvmtool. Maybe we should mention that this happens to work because both UARTs have their TX data register at offset 0, because they are by no means "compatible" otherwise. But that just a documentation issue, so: > Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> Reviewed-by: Andre Przywara <andre.przywara@arm.com> Cheers, Andre. > --- > lib/arm/io.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/lib/arm/io.c b/lib/arm/io.c > index d2c1a07c19ee..35fc05aeb4db 100644 > --- a/lib/arm/io.c > +++ b/lib/arm/io.c > @@ -32,22 +32,26 @@ static volatile u8 *uart0_base = (u8 > *)UART_EARLY_BASE; > static void uart0_init(void) > { > - const char *compatible = "arm,pl011"; > + const char *compatible[] = {"arm,pl011", "ns16550a"}; > struct dt_pbus_reg base; > - int ret; > + int i, ret; > > ret = dt_get_default_console_node(); > assert(ret >= 0 || ret == -FDT_ERR_NOTFOUND); > > if (ret == -FDT_ERR_NOTFOUND) { > > - ret = dt_pbus_get_base_compatible(compatible, &base); > - assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); > + for (i = 0; i < ARRAY_SIZE(compatible); i++) { > + ret = > dt_pbus_get_base_compatible(compatible[i], &base); > + assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); > + > + if (ret == 0) > + break; > + } > > if (ret) { > - printf("%s: %s not found in the device tree, > " > - "aborting...\n", > - __func__, compatible); > + printf("%s: Compatible UART not found in the > device tree, " > + "aborting...\n", __func__); > abort(); > } >
On Thu, Jan 24, 2019 at 11:16:28AM +0000, Alexandru Elisei wrote: > Add support for discovering the ns16550a UART from the device tree. This > particular UART model is emulated by kvmtool. > > Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> > --- > lib/arm/io.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/lib/arm/io.c b/lib/arm/io.c > index d2c1a07c19ee..35fc05aeb4db 100644 > --- a/lib/arm/io.c > +++ b/lib/arm/io.c > @@ -32,22 +32,26 @@ static volatile u8 *uart0_base = (u8 *)UART_EARLY_BASE; > > static void uart0_init(void) > { > - const char *compatible = "arm,pl011"; > + const char *compatible[] = {"arm,pl011", "ns16550a"}; > struct dt_pbus_reg base; > - int ret; > + int i, ret; > > ret = dt_get_default_console_node(); > assert(ret >= 0 || ret == -FDT_ERR_NOTFOUND); > > if (ret == -FDT_ERR_NOTFOUND) { > > - ret = dt_pbus_get_base_compatible(compatible, &base); > - assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); > + for (i = 0; i < ARRAY_SIZE(compatible); i++) { > + ret = dt_pbus_get_base_compatible(compatible[i], &base); > + assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); > + > + if (ret == 0) > + break; > + } > > if (ret) { > - printf("%s: %s not found in the device tree, " > - "aborting...\n", > - __func__, compatible); > + printf("%s: Compatible UART not found in the device tree, " > + "aborting...\n", __func__); > abort(); > } > > -- > 2.17.0 > I agree with Andre that we should document this UART "driver" only ever writes to the TX register. And that it assumes that TX register is at the 0th offset. Thanks, drew
On 1/24/19 1:11 PM, Andrew Jones wrote: > On Thu, Jan 24, 2019 at 11:16:28AM +0000, Alexandru Elisei wrote: >> Add support for discovering the ns16550a UART from the device tree. This >> particular UART model is emulated by kvmtool. >> >> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> >> --- >> lib/arm/io.c | 18 +++++++++++------- >> 1 file changed, 11 insertions(+), 7 deletions(-) >> >> diff --git a/lib/arm/io.c b/lib/arm/io.c >> index d2c1a07c19ee..35fc05aeb4db 100644 >> --- a/lib/arm/io.c >> +++ b/lib/arm/io.c >> @@ -32,22 +32,26 @@ static volatile u8 *uart0_base = (u8 *)UART_EARLY_BASE; >> >> static void uart0_init(void) >> { >> - const char *compatible = "arm,pl011"; >> + const char *compatible[] = {"arm,pl011", "ns16550a"}; >> struct dt_pbus_reg base; >> - int ret; >> + int i, ret; >> >> ret = dt_get_default_console_node(); >> assert(ret >= 0 || ret == -FDT_ERR_NOTFOUND); >> >> if (ret == -FDT_ERR_NOTFOUND) { >> >> - ret = dt_pbus_get_base_compatible(compatible, &base); >> - assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); >> + for (i = 0; i < ARRAY_SIZE(compatible); i++) { >> + ret = dt_pbus_get_base_compatible(compatible[i], &base); >> + assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); >> + >> + if (ret == 0) >> + break; >> + } >> >> if (ret) { >> - printf("%s: %s not found in the device tree, " >> - "aborting...\n", >> - __func__, compatible); >> + printf("%s: Compatible UART not found in the device tree, " >> + "aborting...\n", __func__); >> abort(); >> } >> >> -- >> 2.17.0 >> > I agree with Andre that we should document this UART "driver" only ever > writes to the TX register. And that it assumes that TX register is at > the 0th offset. > > Thanks, > drew Sure, I'll write a comment documenting this behavior in the next version of the patches.
diff --git a/lib/arm/io.c b/lib/arm/io.c index d2c1a07c19ee..35fc05aeb4db 100644 --- a/lib/arm/io.c +++ b/lib/arm/io.c @@ -32,22 +32,26 @@ static volatile u8 *uart0_base = (u8 *)UART_EARLY_BASE; static void uart0_init(void) { - const char *compatible = "arm,pl011"; + const char *compatible[] = {"arm,pl011", "ns16550a"}; struct dt_pbus_reg base; - int ret; + int i, ret; ret = dt_get_default_console_node(); assert(ret >= 0 || ret == -FDT_ERR_NOTFOUND); if (ret == -FDT_ERR_NOTFOUND) { - ret = dt_pbus_get_base_compatible(compatible, &base); - assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); + for (i = 0; i < ARRAY_SIZE(compatible); i++) { + ret = dt_pbus_get_base_compatible(compatible[i], &base); + assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); + + if (ret == 0) + break; + } if (ret) { - printf("%s: %s not found in the device tree, " - "aborting...\n", - __func__, compatible); + printf("%s: Compatible UART not found in the device tree, " + "aborting...\n", __func__); abort(); }
Add support for discovering the ns16550a UART from the device tree. This particular UART model is emulated by kvmtool. Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> --- lib/arm/io.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)