Support multiple ARM platforms in Xen
Subsystems (2)
v2 cover Support multiple ARM platforms in Xen
Hi,
This is the second version of the patch series. It's rebased on Xen 4.3 rc-1 with Stefano's SMP patch series.
The majors changes:
- Add platform_poweroff and platform_quirks
- Rework early assembly printk to use macro instead of function
- Use defines where it's possible in exynos UART code
- Missing Signed-off-by from Anthony exynos UART code
- Introduce request_dt_irq and setup_dt_irq. request_irq and setup_irq are deprecated for ARM. This part is divided in small patches (one to introduce new function and one to remove the old function) to avoid compilation breakage.
For all changes see in each patch.
Xen can boot on both Arndale Board and the Versatile Express without recompilation. But there is still some hardcoded part, mainly in assembly.
Things to do:
- Move secondary CPUs bring up code in platform specific
- Move out of Xen the switch between secure mode and hypervisor mode
- Rework dom0 device tree creation
- Use everywhere the new device tree API
- Add a support for SYS MMU
- Convert vtimer to use non-hardcoded IRQ
For the moment the known bugs are:
- Bash can sometimes crash with: segfault, memory corruption. It's seems it's due to a lack of VPF save/restore in Xen.
If you want to try this patch series you can clone:
git clone -b arm-v2 git://xenbits.xen.org/people/julieng/xen-unstable.git
The command line to compile Xen is the same as before. You just need to specify on Xen command line, via the device tree, which UART will be used for the console.
Feel free to test this branch during Xen test day. The wiki has been updated for the arndale board:
http://wiki.xen.org/wiki/Xen_ARM_with_Virtualization_Extensions/Arndale
It's now based on:
- this patch series for Xen
- linux 3.9
Feel free to test this branch during the Xen test day on both the versatile express and the arndale board.
Cheers,
Anthony PERARD (2):
xen/arm: Add exynos 4210 UART support xen/arm: Add Exynos 4210 UART support for early printk
Julien Grall (31):
xen/arm: lr must be included in range [0-nr_lr(
xen/arm: don't allow dom0 to access to vpl011 UART0 memory range xen/arm: Remove duplicated GICD_ICPIDR2 definition xen/arm: Bump early printk internal buffer to 512
xen/arm: Fix early_panic when EARLY_PRINTK is disabled xen/arm: Load dtb after dom0 kernel
xen/arm: Create a hierarchical device tree
xen/arm: Add helpers to use the device tree
xen/arm: Add helpers to retrieve an address from the device tree xen/arm: Add helpers to retrieve an interrupt description from the
device tree
xen/arm: Introduce gic_route_dt_irq
xen/arm: Introduce gic_irq_xlate
xen/arm: Introduce setup_dt_irq
xen/arm: Introduce request_dt_irq
xen/arm: Use hierarchical device tree to retrieve GIC information xen/arm: Retrieve timer interrupts from the device tree xen/arm: Don't hardcode VGIC informations
xen/arm: Introduce a generic way to use a device from the device tree xen/arm: New callback in uart_driver to get device tree interrupt
structure
xen/arm: Add generic UART to get the device in the device tree xen/arm: Use device tree API in pl011 UART driver
xen/arm: Use the device tree to map the address range and IRQ to dom0 xen/arm: Allow Xen to run on multiple platform without recompilation xen/arm: WORKAROUND 1:1 memory mapping for dom0
xen/arm: Add versatile express platform
xen/arm: remove request_irq
xen/arm: remove setup_irq
xen/arm: Don't use pl011 UART by default for early printk xen/arm: Add platform specific code for the exynos5 xen/arm: WORKAROUND Support kick cpus and switch to hypervisor for
the exynos5
xen/arm64: Remove hardcoded value for gic in assembly code
config/arm32.mk | 1 + docs/misc/arm/early-printk.txt | 15 + xen/arch/arm/Makefile | 4 +- xen/arch/arm/Rules.mk | 19 + xen/arch/arm/arm32/Makefile | 4 +- xen/arch/arm/arm32/debug-exynos4210.inc | 77 ++ xen/arch/arm/arm32/debug-pl011.inc | 58 ++ xen/arch/arm/arm32/debug.S | 33 + xen/arch/arm/arm32/head.S | 84 +- xen/arch/arm/arm32/mode_switch.S | 75 +- xen/arch/arm/arm64/Makefile | 2 + xen/arch/arm/arm64/debug-pl011.inc | 59 ++ xen/arch/arm/arm64/debug.S | 33 + xen/arch/arm/arm64/head.S | 71 +- xen/arch/arm/arm64/mode_switch.S | 7 +- xen/arch/arm/device.c | 74 ++ xen/arch/arm/domain_build.c | 192 ++++- xen/arch/arm/early_printk.c | 19 +- xen/arch/arm/gic.c | 160 +++- xen/arch/arm/irq.c | 8 +- xen/arch/arm/platform.c | 137 +++ xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/exynos5.c | 86 ++ xen/arch/arm/platforms/vexpress.c | 30 + xen/arch/arm/setup.c | 14 +- xen/arch/arm/shutdown.c | 16 +- xen/arch/arm/time.c | 65 +- xen/arch/arm/vgic.c | 20 +- xen/arch/arm/vpl011.c | 4 +- xen/arch/arm/xen.lds.S | 14 + xen/common/device_tree.c | 1326 ++++++++++++++++++++++++++++-- xen/drivers/char/Makefile | 2 + xen/drivers/char/arm-uart.c | 81 ++ xen/drivers/char/exynos4210-uart.c | 357 ++++++++ xen/drivers/char/pl011.c | 64 +- xen/drivers/char/serial.c | 16 + xen/include/asm-arm/config.h | 15 +- xen/include/asm-arm/device.h | 52 ++ xen/include/asm-arm/domain.h | 5 +- xen/include/asm-arm/early_printk.h | 4 +- xen/include/asm-arm/exynos4210-uart.h | 111 +++ xen/include/asm-arm/gic.h | 16 +- xen/include/asm-arm/irq.h | 8 + xen/include/asm-arm/platform.h | 87 ++ xen/include/asm-arm/platforms/exynos5.h | 40 + xen/include/asm-arm/platforms/vexpress.h | 14 + xen/include/asm-arm/time.h | 3 + xen/include/xen/device_tree.h | 378 ++++++++- xen/include/xen/serial.h | 13 +- 49 files changed, 3682 insertions(+), 292 deletions(-) create mode 100644 docs/misc/arm/early-printk.txt create mode 100644 xen/arch/arm/arm32/debug-exynos4210.inc create mode 100644 xen/arch/arm/arm32/debug-pl011.inc create mode 100644 xen/arch/arm/arm32/debug.S create mode 100644 xen/arch/arm/arm64/debug-pl011.inc create mode 100644 xen/arch/arm/arm64/debug.S create mode 100644 xen/arch/arm/device.c create mode 100644 xen/arch/arm/platform.c create mode 100644 xen/arch/arm/platforms/exynos5.c create mode 100644 xen/drivers/char/arm-uart.c create mode 100644 xen/drivers/char/exynos4210-uart.c create mode 100644 xen/include/asm-arm/device.h create mode 100644 xen/include/asm-arm/exynos4210-uart.h create mode 100644 xen/include/asm-arm/platform.h create mode 100644 xen/include/asm-arm/platforms/exynos5.h
Signature · 1 line
Julien Grall
PATCH v2 1/33 xen/arm: lr must be included in range [0-nr_lr(
Changes in v2:
- Typo in the commit message
--- xen/arch/arm/gic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/arm/gic.c +3 -1
@@ -512,7 +512,9 @@ static inline void gic_set_lr(int lr, unsigned int virtual_irq, {int maintenance_int =GICH_LR_MAINTENANCE_IRQ ; -BUG_ON (lr > nr_lrs); +BUG_ON (lr >= nr_lrs); +BUG_ON (lr <0 ); +BUG_ON (state & ~(GICH_LR_STATE_MASK <<GICH_LR_STATE_SHIFT ));GICH [GICH_LR + lr] = state | maintenance_int |
Signature · 1 line
Julien Grall
PATCH v2 2/33 xen/arm: don't allow dom0 to access to vpl011 UART0 memory range
In reply to Julien GrallAs vpl011 UART is not initialized for dom 0, when the domain tries to access to this range, a segfault will occur in Xen. The right behaviour should be a data abort for the guest.
--- xen/arch/arm/vpl011.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/arm/vpl011.c +3 -1
@@ -85,7 +85,9 @@ static void uart0_print_char(char c)static int uart0_mmio_check (struct vcpu *v,paddr_t addr) { -return addr >=UART0_START && addr <UART0_END ; +struct domain *d = v->domain; + +return d->domain_id !=0 && addr >=UART0_START && addr <UART0_END ; }static int uart0_mmio_read (struct vcpu *v,mmio_info_t *info)
Signature · 1 line
Julien Grall
PATCH v2 3/33 xen/arm: Remove duplicated GICD_ICPIDR2 definition
In reply to Julien Grall--- xen/include/asm-arm/gic.h | 1 - 1 file changed, 1 deletion(-)
xen/include/asm-arm/gic.h +0 -1
@@ -43,7 +43,6 @@#define GICD_ICFGRN (0xCFC/4)#define GICD_NSACR (0xE00/4)#define GICD_NSACRN (0xEFC/4) -#define GICD_ICPIDR2 (0xFE8/4)#define GICD_SGIR (0xF00/4)#define GICD_CPENDSGIR (0xF10/4)#define GICD_CPENDSGIRN (0xF1C/4)
Signature · 1 line
Julien Grall
PATCH v2 4/33 xen/arm: Bump early printk internal buffer to 512
In reply to Julien GrallWhen debug is enabled in device tree code, some lines are bigger than 80 characters.
Changes in v2:
- Move buffer to a static variable
--- xen/arch/arm/early_printk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
xen/arch/arm/early_printk.c +3 -2
@@ -29,6 +29,9 @@ void __init early_putch(char c) *r = c; } +/* Early printk buffer */ +static char __initdata buf[512 ]; +static void __init early_puts (const char *s) {while (*s !='\0' ) {
@@ -41,8 +44,6 @@ static void __init early_puts(const char *s)static void __init early_vprintk (const char *fmt,va_list args) { -char buf[80 ]; -vsnprintf (buf,sizeof (buf), fmt, args);early_puts (buf); }
Signature · 1 line
Julien Grall
Re: [PATCH V2 04/33] xen/arm: Bump early printk internal buffer to 512
Quoted 4 lines · Julien Grall
When debug is enabled in device tree code, some lines are bigger than 80 characters.
Signed-off-by Julien Grall <[email protected]>
Although if we can also take steps to not let the line length get too long that would be valuable, I can see 80-100 being tolerable but if we are actually seeing lines with 512 characters that is an issue in its own right. I appreciate you've just picked a "big enough" number and we hopefully aren't seeing anything like 512 in practice.
Quoted 29 lines
Changes in v2:
- Move buffer to a static variable--- xen/arch/arm/early_printk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)xen/arch/arm/early_printk.c +3
-2@@ -29,6 +29,9 @@ void __init early_putch(char c) *r = c; } +/* Early printk buffer */ +static char __initdata buf[512 ]; +static void __init early_puts (const char *s) {while (*s !='\0' ) {@@ -41,8 +44,6 @@ static void __init early_puts(const char *s)static void __init early_vprintk (const char *fmt,va_list args) { -char buf[80 ]; -vsnprintf (buf,sizeof (buf), fmt, args);early_puts (buf); }
Re: [PATCH V2 04/33] xen/arm: Bump early printk internal buffer to 512
Quoted 6 lines · Ian Campbell
Quoted 4 lines · Julien Grall
When debug is enabled in device tree code, some lines are bigger than 80 characters.
Signed-off-by Julien Grall <[email protected]>
Quoted 7 lines
Acked-by Ian Campbell <[email protected]>Although if we can also take steps to not let the line length get too long that would be valuable, I can see 80-100 being tolerable but if we are actually seeing lines with 512 characters that is an issue in its own right. I appreciate you've just picked a "big enough" number and we hopefully aren't seeing anything like 512 in practice.
It seems, the function printk uses a buffer of 10024. It's mainly when device tree prints full path on each node.
Quoted 31 lines
Quoted 29 lines
Changes in v2:
- Move buffer to a static variable--- xen/arch/arm/early_printk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)xen/arch/arm/early_printk.c +3
-2@@ -29,6 +29,9 @@ void __init early_putch(char c) *r = c; } +/* Early printk buffer */ +static char __initdata buf[512 ]; +static void __init early_puts (const char *s) {while (*s !='\0' ) {@@ -41,8 +44,6 @@ static void __init early_puts(const char *s)static void __init early_vprintk (const char *fmt,va_list args) { -char buf[80 ]; -vsnprintf (buf,sizeof (buf), fmt, args);early_puts (buf); }
Re: [PATCH V2 04/33] xen/arm: Bump early printk internal buffer to 512
Quoted 10 lines · Julien Grall
Quoted 8 lines · Ian Campbell
Quoted 4 lines · Julien Grall
When debug is enabled in device tree code, some lines are bigger than 80 characters.
Signed-off-by Julien Grall <[email protected]>Acked-by Ian Campbell <[email protected]>
Quoted 8 lines
Quoted 5 lines
Although if we can also take steps to not let the line length get too long that would be valuable, I can see 80-100 being tolerable but if we are actually seeing lines with 512 characters that is an issue in its own right. I appreciate you've just picked a "big enough" number and we hopefully aren't seeing anything like 512 in practice.
It seems, the function printk uses a buffer of 10024.
I suppose the extra 0 is a typo, but even 1024 seems excessive!
Quoted 1 line
It's mainly when device tree prints full path on each node.
OK, lets leave it for now but maybe at some point think about ways of shortening these lines since even if we print them they are going to be wrapped and hard to read. Perhaps indenting children instead of printing the whole path.
PATCH v2 5/33 xen/arm: Fix early_panic when EARLY_PRINTK is disabled
In reply to Julien GrallEven if EARLY_PRINTK is not enabled, early_panic must never return.
--- xen/include/asm-arm/early_printk.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/asm-arm/early_printk.h +1 -1
@@ -20,7 +20,7 @@ void early_panic(const char *fmt, ...) __attribute__((noreturn));#else static inline void early_printk (const char *fmt, ...) {} -static inline void early_panic (const char *fmt, ...) {} +static inline void __attribute__((noreturn))early_panic (const char *fmt, ...) {while (1 );}#endif
Signature · 1 line
Julien Grall
PATCH v2 6/33 xen/arm: Load dtb after dom0 kernel
In reply to Julien GrallOn some setup, the first linux page table is at 0x40004000. Xen will load dom0 device tree at 0x4000100. In case of the device tree is big, linux will corrupt the device tree.
--- xen/arch/arm/domain_build.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/arm/domain_build.c +2 -1
@@ -407,8 +407,9 @@ int construct_dom0(struct domain *d)/* The following loads use the domain's p2m */ p2m_load_VTTBR (d); -dtb_load (&kinfo); + kinfo.dtb_paddr = kinfo.zimage.load_addr + kinfo.zimage.len;kernel_load (&kinfo); +dtb_load (&kinfo);discard_initial_modules ();
Signature · 1 line
Julien Grall
PATCH v2 7/33 xen/arm: Create a hierarchical device tree
In reply to Julien GrallAdd function to parse the device tree and create a hierarchical tree.
This code is based on drivers/of/base.c in linux source.
Changes in v2:
- s/dom0$/device/ in comment "By default dom0 owns the dom0"
- Use DOMID_XEN instead of DOMID_INVALID for DT_USED_BY_XEN
--- xen/arch/arm/setup.c | 5 + xen/common/device_tree.c | 452 ++++++++++++++++++++++++++++++++++++++++- xen/include/xen/device_tree.h | 98 +++++++++ 3 files changed, 551 insertions(+), 4 deletions(-)
xen/arch/arm/setup.c +5 -0
@@ -429,12 +429,17 @@ void __init start_xen(unsigned long boot_phys_offset,setup_pagetables (boot_phys_offset,get_xen_paddr ());setup_mm (fdt_paddr, fdt_size); +dt_unflatten_host_device_tree (); +#ifdef EARLY_UART_ADDRESS /* TODO Need to get device tree or command line for UART address */ pl011_init (0 ,FIXMAP_ADDR (FIXMAP_CONSOLE ));console_init_preirq ();#endif +/* FIXME: Do something smarter */ +dt_switch_to_printk (); +processor_id ();init_xen_time ();
xen/common/device_tree.c +448 -4
494 lines not on this page · raw message
xen/include/xen/device_tree.h +98 -0
114 lines not on this page · raw message
Signature · 1 line
Julien Grall
Re: [PATCH V2 07/33] xen/arm: Create a hierarchical device tree
xen/include/xen/device_tree.h int device_tree_for_each_node(const void *fdt, · line 142
Quoted 6 lines · Julien Grall
xen/include/xen/device_tree.h +6
-0+/** +* Dump device tree message with printk +* TODO: Find another way to switch between early_printk and printk +* int the device tree code +*/ +void __init dt_switch_to_printk (void );
The issue here is that there is code which wants to log which can be called either via dt_unflatten_host_device_tree or later on?
There seems to be at least some calls to dt_dprintk which are only called via dt_unfla..., I think these can and should just use early_printk (or a macro to make them a debug thing). Likewise if there are functions which are only called later then they should just use printk direct (or a macro..)
Which only leaves ones which are both? How many are these? I'm inclined towards suggesting that if they are debug prints which are disabled by default and require a recompile to enable then the person doing the debugging can select whether they care about early or late messages by #define-ing DEBUG or EARLY_DEBUG or both as required.
Quoted 3 lines
+/**
+ * Host device tree
+ * DO NOT modify it!
Can it be const?
Quoted 35 lines
+ */
xen/include/xen/device_tree.h +30
-1+extern struct dt_device_node *dt_host; + +#define dt_node_cmp (s1, s2) strcmp((s1), (s2)) +#define dt_compat_cmp (s1, s2, l) strnicmp((s1), (s2), l) + +#define for_each_property_of_node (dn, pp) \ + for ( pp = dn->properties; pp != NULL; pp = pp->next ) + +#define for_each_device_node (dt, dn) \ + for ( dn = dt; dn != NULL; dn = dn->allnext ) + +static inline const char *dt_node_full_name (const struct dt_device_node *np) +{ +return (np && np->full_name) ? np->full_name :"<no-node>" ; +} + +/** +* Find a property with a given name for a given node +* and return the value. +*/ +const void *dt_get_property (const struct dt_device_node *np, +const char *name,u32 *lenp); + +/** +* dt_find_node_by_path - Find a node matching a full DT path +* @path: The full path to match +* +* Returns a node pointer. +*/ +struct dt_device_node *dt_find_node_by_path (const char *path);#endif --Julien Grall
Re: [PATCH V2 07/33] xen/arm: Create a hierarchical device tree
Quoted 11 lines · Ian Campbell
xen/include/xen/device_tree.h int device_tree_for_each_node(const void *fdt, · line 142
Quoted 6 lines · Julien Grall
xen/include/xen/device_tree.h +6
-0+/** +* Dump device tree message with printk +* TODO: Find another way to switch between early_printk and printk +* int the device tree code +*/ +void __init dt_switch_to_printk (void );The issue here is that there is code which wants to log which can be called either via
dt_unflatten_host_device_treeor later on?
Right.
Quoted 5 lines
There seems to be at least some calls to
dt_dprintkwhich are only called viadt_unfla..., I think these can and should just useearly_printk(or a macro to make them a debug thing). Likewise if there are functions which are only called later then they should just use printk direct (or a macro..)
There are lots of dt_dprintk in functions to retrieve an IRQ and an address.
Quoted 5 lines
Which only leaves ones which are both? How many are these? I'm inclined towards suggesting that if they are debug prints which are disabled by default and require a recompile to enable then the person doing the debugging can select whether they care about early or late messages by #define-ing DEBUG or
EARLY_DEBUGor both as required.
We can't choose at compile time. Early printk function is in init code section. So at the end of boot the function will disappear. Device tree function could be called after the end of the boot. For the moment it's not the case.
The best solution would be: early_printk is directly handled in console as linux does.
Quoted 5 lines
Quoted 3 lines
+/**
+ * Host device tree
+ * DO NOT modify it!Can it be const?
No :/. I choose to runtime information in the device tree. It's usefull to know if a device is used by Xen or someone else.
I have just notice that dt_host is only used in domain_build.c to browse all the nodes. I can either provide a helper which return the host DT or add a function to call a function and recurse on each node.
Signature · 1 line
Julien Grall
Re: [PATCH V2 07/33] xen/arm: Create a hierarchical device tree
Quoted 8 lines · Julien Grall
Quoted 5 lines
Which only leaves ones which are both? How many are these? I'm inclined towards suggesting that if they are debug prints which are disabled by default and require a recompile to enable then the person doing the debugging can select whether they care about early or late messages by #define-ing DEBUG or
EARLY_DEBUGor both as required.We can't choose at compile time. Early printk function is in init code section. So at the end of boot the function will disappear.
Oh, right.
Perhaps something could be conditional on system_state = SYS_STATE_active, this happens not long before we discard the initial sections.
Quoted 5 lines
Device tree function could be called after the end of the boot. For the moment it's not the case.
The best solution would be:
early_printkis directly handled in console as linux does.
That does sound best.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
+/**
+ * Host device tree
+ * DO NOT modify it!
Quoted 8 lines
Quoted 1 line
Can it be const?
No :/. I choose to runtime information in the device tree. It's usefull to know if a device is used by Xen or someone else.
I have just notice that
dt_hostis only used indomain_build.cto browse all the nodes. I can either provide a helper which return the host DT or add a function to call a function and recurse on each node.
I think it is OK, I was only wondering if it could be const.
Ian.
Re: [PATCH V2 07/33] xen/arm: Create a hierarchical device tree
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Julien Grall
Quoted 5 lines
Which only leaves ones which are both? How many are these? I'm inclined towards suggesting that if they are debug prints which are disabled by default and require a recompile to enable then the person doing the debugging can select whether they care about early or late messages by #define-ing DEBUG or
EARLY_DEBUGor both as required.
Quoted 8 lines
Quoted 2 lines
We can't choose at compile time. Early printk function is in init code section. So at the end of boot the function will disappear.
Oh, right.
Perhaps something could be conditional on
system_state=SYS_STATE_active, this happens not long before we discard the initial sections.
I think it's too late. If we use early_printk until this stage, we will lose some usefull debug when early printk is disabled (ie most of the time).
How about adding the missing system_state = SYS_STATE_boot just after console_init_preirq? Early printk will only be used when system_state == SYS_STATE_early_boot.
Quoted 7 lines
Quoted 5 lines
Device tree function could be called after the end of the boot. For the moment it's not the case.
The best solution would be:
early_printkis directly handled in console as linux does.That does sound best.
I will send a patch later for this.
Signature · 1 line
Julien
Re: [PATCH V2 07/33] xen/arm: Create a hierarchical device tree
Quoted 19 lines · Julien Grall
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Julien Grall
Quoted 5 lines
Which only leaves ones which are both? How many are these? I'm inclined towards suggesting that if they are debug prints which are disabled by default and require a recompile to enable then the person doing the debugging can select whether they care about early or late messages by #define-ing DEBUG or
EARLY_DEBUGor both as required.Quoted 8 lines
Quoted 2 lines
We can't choose at compile time. Early printk function is in init code section. So at the end of boot the function will disappear.
Oh, right.
Perhaps something could be conditional on
system_state=SYS_STATE_active, this happens not long before we discard the initial sections.
Quoted 6 lines
I think it's too late. If we use
early_printkuntil this stage, we will lose some usefull debug when early printk is disabled (ie most of the time).How about adding the missing
system_state=SYS_STATE_bootjust afterconsole_init_preirq? Early printk will only be used whensystem_state==SYS_STATE_early_boot.
I think this is a common thing so it'd need wider discussion.
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Device tree function could be called after the end of the boot. For the moment it's not the case.
The best solution would be:
early_printkis directly handled in console as linux does.That does sound best.
I will send a patch later for this.
Does that make the above moot?
Ian.
Re: [PATCH V2 07/33] xen/arm: Create a hierarchical device tree
Quoted 20 lines · Ian Campbell
Quoted 19 lines · Julien Grall
Quoted 15 lines · Ian Campbell
Quoted 8 lines · Julien Grall
Quoted 5 lines
Which only leaves ones which are both? How many are these? I'm inclined towards suggesting that if they are debug prints which are disabled by default and require a recompile to enable then the person doing the debugging can select whether they care about early or late messages by #define-ing DEBUG or
EARLY_DEBUGor both as required.We can't choose at compile time. Early printk function is in init code section. So at the end of boot the function will disappear.
Oh, right.
Perhaps something could be conditional on
system_state=SYS_STATE_active, this happens not long before we discard the initial sections.
Quoted 8 lines
Quoted 6 lines
I think it's too late. If we use
early_printkuntil this stage, we will lose some usefull debug when early printk is disabled (ie most of the time).How about adding the missing
system_state=SYS_STATE_bootjust afterconsole_init_preirq? Early printk will only be used whensystem_state==SYS_STATE_early_boot.I think this is a common thing so it'd need wider discussion.
SYS_STATE_boot already exists for x86. We forgot to use it on Xen Arm. So all ARM boot is done with system_state equals to SYS_STATE_early_boot.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Device tree function could be called after the end of the boot. For the moment it's not the case.
The best solution would be:
early_printkis directly handled in console as linux does.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
That does sound best.
I will send a patch later for this.
Does that make the above moot?
Yes. I think this will avoid lots of headache to know if we need to use early_printk or printk in the code. It's really annoying when Xen is stucked with no log because an assert, which uses printk, is raised when console is not setup. But this changes will impact x86.
Signature · 1 line
Julien
Re: [PATCH V2 07/33] xen/arm: Create a hierarchical device tree
Quoted 29 lines · Julien Grall
Quoted 27 lines · Ian Campbell
Quoted 25 lines · Julien Grall
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Julien Grall
Quoted 5 lines
Which only leaves ones which are both? How many are these? I'm inclined towards suggesting that if they are debug prints which are disabled by default and require a recompile to enable then the person doing the debugging can select whether they care about early or late messages by #define-ing DEBUG or
EARLY_DEBUGor both as required.Quoted 8 lines
Quoted 2 lines
We can't choose at compile time. Early printk function is in init code section. So at the end of boot the function will disappear.
Oh, right.
Perhaps something could be conditional on
system_state=SYS_STATE_active, this happens not long before we discard the initial sections.I think it's too late. If we use
early_printkuntil this stage, we will lose some usefull debug when early printk is disabled (ie most of the time).How about adding the missing
system_state=SYS_STATE_bootjust afterconsole_init_preirq? Early printk will only be used whensystem_state==SYS_STATE_early_boot.
Quoted 5 lines
Quoted 1 line
I think this is a common thing so it'd need wider discussion.
SYS_STATE_bootalready exists for x86. We forgot to use it on Xen Arm. So all ARM boot is done withsystem_stateequals toSYS_STATE_early_boot.
Oh, then great lets use that ;-)
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Device tree function could be called after the end of the boot. For the moment it's not the case.
The best solution would be:
early_printkis directly handled in console as linux does.That does sound best.
I will send a patch later for this.
Quoted 7 lines
Quoted 1 line
Does that make the above moot?
Yes. I think this will avoid lots of headache to know if we need to use
early_printkor printk in the code. It's really annoying when Xen is stucked with no log because an assert, which uses printk, is raised when console is not setup. But this changes will impact x86.
Yes, this is probably 4.4 material then?
Re: [PATCH V2 07/33] xen/arm: Create a hierarchical device tree
Quoted 52 lines · Ian Campbell
Quoted 29 lines · Julien Grall
Quoted 27 lines · Ian Campbell
Quoted 25 lines · Julien Grall
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Julien Grall
Quoted 5 lines
Which only leaves ones which are both? How many are these? I'm inclined towards suggesting that if they are debug prints which are disabled by default and require a recompile to enable then the person doing the debugging can select whether they care about early or late messages by #define-ing DEBUG or
EARLY_DEBUGor both as required.Quoted 8 lines
Quoted 2 lines
We can't choose at compile time. Early printk function is in init code section. So at the end of boot the function will disappear.
Oh, right.
Perhaps something could be conditional on
system_state=SYS_STATE_active, this happens not long before we discard the initial sections.I think it's too late. If we use
early_printkuntil this stage, we will lose some usefull debug when early printk is disabled (ie most of the time).How about adding the missing
system_state=SYS_STATE_bootjust afterconsole_init_preirq? Early printk will only be used whensystem_state==SYS_STATE_early_boot.Quoted 5 lines
Quoted 1 line
I think this is a common thing so it'd need wider discussion.
SYS_STATE_bootalready exists for x86. We forgot to use it on Xen Arm. So all ARM boot is done withsystem_stateequals toSYS_STATE_early_boot.Oh, then great lets use that ;-)
Quoted 14 lines
Quoted 12 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Device tree function could be called after the end of the boot. For the moment it's not the case.
The best solution would be:
early_printkis directly handled in console as linux does.That does sound best.
I will send a patch later for this.
Does that make the above moot?
Quoted 6 lines
Quoted 4 lines
Yes. I think this will avoid lots of headache to know if we need to use
early_printkor printk in the code. It's really annoying when Xen is stucked with no log because an assert, which uses printk, is raised when console is not setup. But this changes will impact x86.Yes, this is probably 4.4 material then?
Yes, I will write a line on this issue with ASSERT on the wiki.
Signature · 1 line
Julien
Re: [PATCH V2 07/33] xen/arm: Create a hierarchical device tree
In reply to Julien GrallOn Wed, 2013-05-08 at 03:33 +0100, Julien Grall wrote:
...
xen/include/xen/device_tree.h struct dt_early_info { · line 93
Quoted 9 lines
- Use
DOMID_XENinstead ofDOMID_INVALIDforDT_USED_BY_XEN
[...]xen/include/xen/device_tree.h +6
-0+struct dt_device_node { +const char *name; +const char *type; +dt_phandle phandle; +char *full_name; +domid_t used_by;/* By default it's used by dom0 */
It occurred to me as I reviewed the rest of the series that since this actually a DOMID there is no reason not to use DOMID_XEN directly and remove DT_USED_BY_XEN.
Ian.
Re: [PATCH V2 07/33] xen/arm: Create a hierarchical device tree
Quoted 12 lines · Ian Campbell
On Wed, 2013-05-08 at 03:33 +0100, Julien Grall wrote:
...xen/include/xen/device_tree.h struct dt_early_info { · line 93
Quoted 9 lines
- Use
DOMID_XENinstead ofDOMID_INVALIDforDT_USED_BY_XEN
[...]xen/include/xen/device_tree.h +6
-0+struct dt_device_node { +const char *name; +const char *type; +dt_phandle phandle; +char *full_name; +domid_t used_by;/* By default it's used by dom0 */
Quoted 3 lines
It occurred to me as I reviewed the rest of the series that since this actually a DOMID there is no reason not to use
DOMID_XENdirectly and removeDT_USED_BY_XEN.
Will be fix on the next patch series.
Signature · 1 line
Julien
PATCH v2 8/33 xen/arm: Add helpers to use the device tree
In reply to Julien GrallChanges in v2:
- use dt_node_cmp and dt_compat_cmp in early device tree code
--- xen/common/device_tree.c | 127 ++++++++++++++++++++++++++++++++++++++++- xen/include/xen/device_tree.h | 120 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 245 insertions(+), 2 deletions(-)
xen/common/device_tree.c +125 -2
@@ -88,20 +88,23 @@ bool_t device_tree_type_matches(const void *fdt, int node, const char *match)if ( prop ==NULL )return 0 ; -return !strcmp (prop, match); +return !dt_node_cmp (prop, match); }bool_t device_tree_node_compatible (const void *fdt,int node,const char *match) {int len, l; +int mlen;const void *prop; + mlen =strlen (match); + prop =fdt_getprop (fdt, node,"compatible" , &len);if ( prop ==NULL )return 0 ;while ( len >0 ) { -if ( !strcmp (prop, match) ) +if ( !dt_compat_cmp (prop, match, mlen) )return 1 ; l =strlen (prop) +1 ; prop += l;
@@ -573,6 +576,54 @@ const void *dt_get_property(const struct dt_device_node *np,return pp ? pp->value :NULL ; } +bool_t dt_device_is_compatible (const struct dt_device_node *device, +const char *compat) +{ +const char * cp; +u32 cplen, l; + + cp =dt_get_property (device,"compatible" , &cplen); +if ( cp ==NULL ) +return 0 ; +while ( cplen >0 ) + { +if (dt_compat_cmp (cp, compat,strlen (compat)) ==0 ) +return 1 ; + l =strlen (cp) +1 ; + cp += l; + cplen -= l; + } + +return 0 ; +} + +bool_t dt_machine_is_compatible (const char *compat) +{ +const struct dt_device_node *root; +bool_t rc =0 ; + + root =dt_find_node_by_path ("/" ); +if ( root ) + { + rc =dt_device_is_compatible (root, compat); + } +return rc; +} + +struct dt_device_node *dt_find_node_by_name (struct dt_device_node *from, +const char *name) +{ +struct dt_device_node *np; +struct dt_device_node *dt; + + dt = from ? from->allnext : dt_host; +for_each_device_node (dt, np) +if ( np->name && (dt_node_cmp (np->name, name) ==0 ) ) +break ; + +return np; +} +struct dt_device_node *dt_find_node_by_path (const char *path) {struct dt_device_node *np;
@@ -584,6 +635,78 @@ struct dt_device_node *dt_find_node_by_path(const char *path)return np; } +struct dt_device_node *dt_find_node_by_alias (const char *alias) +{ +const struct dt_alias_prop *app; + +list_for_each_entry ( app, &aliases_lookup, link ) + { +if ( !strcmp (app->alias, alias) ) +return app->np; + } + +return NULL ; +} + +const struct dt_device_node *dt_get_parent (const struct dt_device_node *node) +{ +if ( !node ) +return NULL ; + +return node->parent; +} + +struct dt_device_node * +dt_find_compatible_node (struct dt_device_node *from, +const char *type, +const char *compatible) +{ +struct dt_device_node *np; +struct dt_device_node *dt; + + dt = from ? from->allnext : dt_host; +for_each_device_node (dt, np) + { +if ( type + && !(np->type && (dt_node_cmp (np->type, type) ==0 )) ) +continue ; +if (dt_device_is_compatible (np, compatible) ) +break ; + } + +return np; +} + +int dt_n_addr_cells (const struct dt_device_node *np) +{ +const __be32 *ip; + +do { +if ( np->parent ) + np = np->parent; + ip =dt_get_property (np,"#address-cells" ,NULL ); +if ( ip ) +return be32_to_cpup (ip); + }while ( np->parent ); +/* No #address-cells property for the root node */ +return DT_ROOT_NODE_ADDR_CELLS_DEFAULT ; +} + +int dt_n_size_cells (const struct dt_device_node *np) +{ +const __be32 *ip; + +do { +if ( np->parent ) + np = np->parent; + ip =dt_get_property (np,"#size-cells" ,NULL ); +if ( ip ) +return be32_to_cpup (ip); + }while ( np->parent ); +/* No #address-cells property for the root node */ +return DT_ROOT_NODE_SIZE_CELLS_DEFAULT ; +} +/** * unflatten_dt_node - Alloc and populate a device_node from the flat tree * @fdt: The parent device tree blob
xen/include/xen/device_tree.h +120 -0
147 lines not on this page · raw message
Signature · 1 line
Julien Grall
Re: [PATCH V2 08/33] xen/arm: Add helpers to use the device tree
Quoted 14 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>Changes in v2:
- usedt_node_cmpanddt_compat_cmpin early device tree code--- xen/common/device_tree.c | 127 ++++++++++++++++++++++++++++++++++++++++- xen/include/xen/device_tree.h | 120 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 245 insertions(+), 2 deletions(-)xen/common/device_tree.c +0
-0
xen/common/device_tree.c bool_t device_tree_type_matches(const void *fdt, int node, const char *match) · line 94
Quoted 8 lines
xen/common/device_tree.c +1
-1@@ -88,20 +88,23 @@ bool_t device_tree_type_matches(const void *fdt, int node, const char *match)if ( prop ==NULL )return 0 ; -return !strcmp (prop, match); +return !dt_node_cmp (prop, match); }bool_t device_tree_node_compatible (const void *fdt,int node,const char *match)
Aside: I wonder if any of these should be __init...
Quoted 4 lines
xen/common/device_tree.c +1
-0{int len, l; +int mlen;const void *prop;
xen/common/device_tree.c bool_t device_tree_type_matches(const void *fdt, int node, const char *match) · line 107
Quoted 10 lines
xen/common/device_tree.c +3
-1+ mlen =strlen (match); + prop =fdt_getprop (fdt, node,"compatible" , &len);if ( prop ==NULL )return 0 ;while ( len >0 ) { -if ( !strcmp (prop, match) ) +if ( !dt_compat_cmp (prop, match, mlen) )
Is there a change in behaviour here where strlen(match) < strlen(prop)?
I may be mistaken but I think match=="foo" would be compatible with a node "foobar" now whereas it wasn't before.
On the otherhand this is the same behaviour as dt_device_is_compatible so maybe it is expected. I seem to recall some name matching code which explicitly wanted to handle foo@0 as matching foo and things, not sure that applies here though.
Quoted 58 lines
xen/common/device_tree.c +48
-0return 1 ; l =strlen (prop) +1 ; prop += l;@@ -573,6 +576,54 @@ const void *dt_get_property(const struct dt_device_node *np,return pp ? pp->value :NULL ; } +bool_t dt_device_is_compatible (const struct dt_device_node *device, +const char *compat) +{ +const char * cp; +u32 cplen, l; + + cp =dt_get_property (device,"compatible" , &cplen); +if ( cp ==NULL ) +return 0 ; +while ( cplen >0 ) + { +if (dt_compat_cmp (cp, compat,strlen (compat)) ==0 ) +return 1 ; + l =strlen (cp) +1 ; + cp += l; + cplen -= l; + } + +return 0 ; +} + +bool_t dt_machine_is_compatible (const char *compat) +{ +const struct dt_device_node *root; +bool_t rc =0 ; + + root =dt_find_node_by_path ("/" ); +if ( root ) + { + rc =dt_device_is_compatible (root, compat); + } +return rc; +} + +struct dt_device_node *dt_find_node_by_name (struct dt_device_node *from, +const char *name) +{ +struct dt_device_node *np; +struct dt_device_node *dt; + + dt = from ? from->allnext : dt_host; +for_each_device_node (dt, np) +if ( np->name && (dt_node_cmp (np->name, name) ==0 ) ) +break ; + +return np; +} +struct dt_device_node *dt_find_node_by_path (const char *path) {struct dt_device_node *np;
Re: [PATCH V2 08/33] xen/arm: Add helpers to use the device tree
Quoted 18 lines · Ian Campbell
Quoted 17 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>Changes in v2:
- usedt_node_cmpanddt_compat_cmpin early device tree code--- xen/common/device_tree.c | 127 ++++++++++++++++++++++++++++++++++++++++- xen/include/xen/device_tree.h | 120 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 245 insertions(+), 2 deletions(-)xen/common/device_tree.c +0
-0@@ -88,20 +88,23 @@ bool_t device_tree_type_matches(const void *fdt, int node, const char *match)if ( prop ==NULL )return 0 ;
Quoted 7 lines
xen/common/device_tree.c bool_t device_tree_type_matches(const void *fdt, int node, const char *match) · line 94
Quoted 5 lines
xen/common/device_tree.c +1
-1-return !strcmp (prop, match); +return !dt_node_cmp (prop, match); }bool_t device_tree_node_compatible (const void *fdt,int node,const char *match)Aside: I wonder if any of these should be
__init...
I think yes.
Quoted 12 lines
Quoted 12 lines
xen/common/device_tree.c +3
-0{int len, l; +int mlen;const void *prop; + mlen =strlen (match); + prop =fdt_getprop (fdt, node,"compatible" , &len);if ( prop ==NULL )return 0 ;
Quoted 8 lines
xen/common/device_tree.c bool_t device_tree_type_matches(const void *fdt, int node, const char *match) · line 107
Quoted 3 lines
xen/common/device_tree.c +1
-1while ( len >0 ) { -if ( !strcmp (prop, match) ) +if ( !dt_compat_cmp (prop, match, mlen) )Is there a change in behaviour here where strlen(match) < strlen(prop)?
I may be mistaken but I think match=="foo" would be compatible with a node "foobar" now whereas it wasn't before.
I have checked the linux code and the also use strncmp with the length of "match"/"compatible".
Quoted 4 lines
On the otherhand this is the same behaviour as
dt_device_is_compatibleso maybe it is expected. I seem to recall some name matching code which explicitly wanted to handle foo@0 as matching foo and things, not sure that applies here though.
This behaviour only happens for the compatible node.
Signature · 1 line
Julien Grall
PATCH v2 9/33 xen/arm: Add helpers to retrieve an address from the device tree
In reply to Julien Grall--- xen/common/device_tree.c | 343 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 22 +++ 2 files changed, 365 insertions(+)
xen/common/device_tree.c +343 -0
@@ -62,10 +62,38 @@ static void (*dt_printk)(const char *fmt, ...) = early_printk;#ifdef DEBUG_DT # define dt_dprintk(fmt, args...) dt_printk(XENLOG_DEBUG fmt, ##args) +static void dt_dump_addr (const char *s,const __be32 *addr,int na) +{ +dt_dprintk ("%s" , s); +while ( na-- ) +dt_dprintk (" %08x" ,be32_to_cpu (*(addr++))); +dt_dprintk ("\n" ); +}#else # define dt_dprintk(fmt, args...) do {} while ( 0 ) +static void dt_dump_addr (const char *s,const __be32 *addr,int na) { }#endif +#define DT_BAD_ADDR ((u64)-1) + +/* Max address size we deal with */ +#define DT_MAX_ADDR_CELLS 4 +#define DT_CHECK_ADDR_COUNT (na) ((na) > 0 && (na) <= DT_MAX_ADDR_CELLS) +#define DT_CHECK_COUNTS (na, ns) (DT_CHECK_ADDR_COUNT(na) && (ns) > 0) + +/* Callbacks for bus specific translators */ +struct dt_bus +{ +const char *name; +const char *addresses; +int (*match)(const struct dt_device_node *parent); +void (*count_cells)(const struct dt_device_node *child, +int *addrc,int *sizec); +u64 (*map)(__be32 *addr,const __be32 *range,int na,int ns,int pna); +int (*translate)(__be32 *addr,u64 offset,int na); +unsigned int (*get_flags)(const __be32 *addr); +}; +bool_t device_tree_node_matches (const void *fdt,int node,const char *match) {const char *name;
@@ -707,6 +735,321 @@ int dt_n_size_cells(const struct dt_device_node *np)return DT_ROOT_NODE_SIZE_CELLS_DEFAULT ; } +/* +* Default translator (generic bus) +*/ +static void dt_bus_default_count_cells (const struct dt_device_node *dev, +int *addrc,int *sizec) +{ +if ( addrc ) + *addrc =dt_n_addr_cells (dev); +if ( sizec ) + *sizec =dt_n_size_cells (dev); +} + +static u64 dt_bus_default_map (__be32 *addr,const __be32 *range, +int na,int ns,int pna) +{ +u64 cp, s, da; + + cp =dt_read_number (range, na); + s =dt_read_number (range + na + pna, ns); + da =dt_read_number (addr, na); + +dt_dprintk ("DT: default map, cp=%llx, s=%llx, da=%llx\n" , + (unsigned long long )cp, (unsigned long long )s, + (unsigned long long )da); + +/* +* If the number of address cells is larger than 2 we assume the +* mapping doesn't specify a physical address. Rather, the address +* specifies an identifier that must match exactly. +*/ +if ( na >2 &&memcmp (range, addr, na *4 ) !=0 ) +return DT_BAD_ADDR ; + +if ( da < cp || da >= (cp + s) ) +return DT_BAD_ADDR ; +return da - cp; +} + +static int dt_bus_default_translate (__be32 *addr,u64 offset,int na) +{ +u64 a =dt_read_number (addr, na); + +memset (addr,0 , na *4 ); + a += offset; +if ( na >1 ) + addr[na -2 ] =cpu_to_be32 (a >>32 ); + addr[na -1 ] =cpu_to_be32 (a &0xffffffffu ); + +return 0 ; +} +static unsigned int dt_bus_default_get_flags (const __be32 *addr) +{ +/* TODO: Return the type of memory (device, ...) for caching +* attribute during mapping */ +return 0 ; +} + +/* +* Array of bus specific translators +*/ +static const struct dt_bus dt_busses[] = +{ +/* Default */ + { + .name ="default" , + .addresses ="reg" , + .match =NULL , + .count_cells = dt_bus_default_count_cells, + .map = dt_bus_default_map, + .translate = dt_bus_default_translate, + .get_flags = dt_bus_default_get_flags, + }, +}; + +static const struct dt_bus *dt_match_bus (const struct dt_device_node *np) +{ +int i; + +for ( i =0 ; i <ARRAY_SIZE (dt_busses); i++ ) +if ( !dt_busses[i].match || dt_busses[i].match (np) ) +return &dt_busses[i]; +BUG (); + +return NULL ; +} + +static const __be32 *dt_get_address (const struct dt_device_node *dev, +int index,u64 *size, +unsigned int *flags) +{ +const __be32 *prop; +u32 psize; +const struct dt_device_node *parent; +const struct dt_bus *bus; +int onesize, i, na, ns; + +/* Get parent & match bus type */ + parent =dt_get_parent (dev); +if ( parent ==NULL ) +return NULL ; + bus =dt_match_bus (parent); + bus->count_cells (dev, &na, &ns); + +if ( !DT_CHECK_ADDR_COUNT (na) ) +return NULL ; + +/* Get "reg" or "assigned-addresses" property */ + prop =dt_get_property (dev, bus->addresses, &psize); +if ( prop ==NULL ) +return NULL ; + psize /=4 ; + + onesize = na + ns; +for ( i =0 ; psize >= onesize; psize -= onesize, prop += onesize, i++ ) + { +if ( i == index ) + { +if ( size ) + *size =dt_read_number (prop + na, ns); +if ( flags ) + *flags = bus->get_flags (prop); +return prop; + } + } +return NULL ; +} + +static int dt_translate_one (const struct dt_device_node *parent, +const struct dt_bus *bus, +const struct dt_bus *pbus, +__be32 *addr,int na,int ns, +int pna,const char *rprop) +{ +const __be32 *ranges; +unsigned int rlen; +int rone; +u64 offset =DT_BAD_ADDR ; + + ranges =dt_get_property (parent, rprop, &rlen); +if ( ranges ==NULL ) + { +dt_printk (XENLOG_ERR "DT: no ranges; cannot translate\n" ); +return 1 ; + } +if ( ranges ==NULL || rlen ==0 ) + { + offset =dt_read_number (addr, na); +memset (addr,0 , pna *4 ); +dt_dprintk ("DT: empty ranges; 1:1 translation\n" ); + goto finish; + } + +dt_dprintk ("DT: walking ranges...\n" ); + +/* Now walk through the ranges */ + rlen /=4 ; + rone = na + pna + ns; +for ( ; rlen >= rone; rlen -= rone, ranges += rone ) + { + offset = bus->map (addr, ranges, na, ns, pna); +if ( offset !=DT_BAD_ADDR ) +break ; + } +if ( offset ==DT_BAD_ADDR ) + { +dt_dprintk ("DT: not found !\n" ); +return 1 ; + } +memcpy (addr, ranges + na,4 * pna); + +finish: +dt_dump_addr ("DT: parent translation for:" , addr, pna); +dt_dprintk ("DT: with offset: %llx\n" , (unsigned long long )offset); + +/* Translate it into parent bus space */ +return pbus->translate (addr, offset, pna); +} + +/* +* Translate an address from the device-tree into a CPU physical address, +* this walks up the tree and applies the various bus mappings on the +* way. +* +* Note: We consider that crossing any level with #size-cells == 0 to mean +* that translation is impossible (that is we are not dealing with a value +* that can be mapped to a cpu physical address). This is not really specified +* that way, but this is traditionally the way IBM at least do things +*/ +static u64 __dt_translate_address (const struct dt_device_node *dev, +const __be32 *in_addr,const char *rprop) +{ +const struct dt_device_node *parent =NULL ; +const struct dt_bus *bus, *pbus; +__be32 addr[DT_MAX_ADDR_CELLS ]; +int na, ns, pna, pns; +u64 result =DT_BAD_ADDR ; + +dt_dprintk ("DT: ** translation for device %s **\n" , dev->full_name); + +/* Get parent & match bus type */ + parent =dt_get_parent (dev); +if ( parent ==NULL ) + goto bail; + bus =dt_match_bus (parent); + +/* Count address cells & copy address locally */ + bus->count_cells (dev, &na, &ns); +if ( !DT_CHECK_COUNTS (na, ns) ) + { +dt_printk (XENLOG_ERR "dt_parse: Bad cell count for %s\n" , + dev->full_name); + goto bail; + } +memcpy (addr, in_addr, na *4 ); + +dt_dprintk ("DT: bus is %s (na=%d, ns=%d) on %s\n" , + bus->name, na, ns, parent->full_name); +dt_dump_addr ("DT: translating address:" , addr, na); + +/* Translate */ +for ( ;; ) + { +/* Switch to parent bus */ + dev = parent; + parent =dt_get_parent (dev); + +/* If root, we have finished */ +if ( parent ==NULL ) + { +dt_dprintk ("DT: reached root node\n" ); + result =dt_read_number (addr, na); +break ; + } + +/* Get new parent bus and counts */ + pbus =dt_match_bus (parent); + pbus->count_cells (dev, &pna, &pns); +if ( !DT_CHECK_COUNTS (pna, pns) ) + { +printk (XENLOG_ERR "dt_parse: Bad cell count for %s\n" , + dev->full_name); +break ; + } + +dt_dprintk ("DT: parent bus is %s (na=%d, ns=%d) on %s\n" , + pbus->name, pna, pns, parent->full_name); + +/* Apply bus translation */ +if (dt_translate_one (dev, bus, pbus, addr, na, ns, pna, rprop) ) +break ; + +/* Complete the move up one level */ + na = pna; + ns = pns; + bus = pbus; + +dt_dump_addr ("DT: one level translation:" , addr, na); + } + +bail: +return result; +} + +/* dt_device_address - Translate device tree address and return it */ +int dt_device_get_address (const struct dt_device_node *dev,int index, +u64 *addr,u64 *size) +{ +const __be32 *addrp; +unsigned int flags; + + addrp =dt_get_address (dev, index, size, &flags); +if ( addrp ==NULL ) +return -EINVAL ; + +if ( !addr ) +return -EINVAL ; + + *addr =__dt_translate_address (dev, addrp,"ranges" ); + +if ( *addr ==DT_BAD_ADDR ) +return -EINVAL ; + +return 0 ; +} + +unsigned int dt_number_of_address (const struct dt_device_node *dev) +{ +const __be32 *prop; +u32 psize; +const struct dt_device_node *parent; +const struct dt_bus *bus; +int onesize, na, ns; + +/* Get parent & match bus type */ + parent =dt_get_parent (dev); +if ( parent ==NULL ) +return 0 ; + + bus =dt_match_bus (parent); + bus->count_cells (dev, &na, &ns); + +if ( !DT_CHECK_COUNTS (na, ns) ) +return 0 ; + +/* Get "reg" or "assigned-addresses" property */ + prop =dt_get_property (dev, bus->addresses, &psize); +if ( prop ==NULL ) +return 0 ; + + psize /=4 ; + onesize = na + ns; + +return (psize / onesize); +} +/** * unflatten_dt_node - Alloc and populate a device_node from the flat tree * @fdt: The parent device tree blob
xen/include/xen/device_tree.h +22 -0
@@ -278,6 +278,28 @@ struct dt_device_node *dt_find_node_by_path(const char *path);const struct dt_device_node *dt_get_parent (const struct dt_device_node *node);/** +* dt_device_get_address - Resolve an address for a device +* @device: the device whose address is to be resolved +* @index: index of the addres to resolve +* @addr: address filled by this function +* @size: size filled by this function +* +* This function resolves an address, walking the tree, for a give +* device-tree node. It returns 0 on success. +*/ +int dt_device_get_address (const struct dt_device_node *dev,int index, +u64 *addr,u64 *size); + +/** +* dt_number_of_address - Get the number of addresse for a device +* @device: the device whose number of address is to be retrieved +* +* Return the number of address for this device or 0 if there is no +* address or an error occured/ +*/ +unsigned int dt_number_of_address (const struct dt_device_node *device); + +/** * dt_n_size_cells - Helper to retrieve the number of cell for the size * @np: node to get the value *
Signature · 1 line
Julien Grall
Re: [PATCH V2 09/33] xen/arm: Add helpers to retrieve an address from the device tree
Quoted 34 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>--- xen/common/device_tree.c | 343 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 22 +++ 2 files changed, 365 insertions(+)xen/common/device_tree.c +16
-0@@ -62,10 +62,38 @@ static void (*dt_printk)(const char *fmt, ...) = early_printk;#ifdef DEBUG_DT # define dt_dprintk(fmt, args...) dt_printk(XENLOG_DEBUG fmt, ##args) +static void dt_dump_addr (const char *s,const __be32 *addr,int na) +{ +dt_dprintk ("%s" , s); +while ( na-- ) +dt_dprintk (" %08x" ,be32_to_cpu (*(addr++))); +dt_dprintk ("\n" ); +}#else # define dt_dprintk(fmt, args...) do {} while ( 0 ) +static void dt_dump_addr (const char *s,const __be32 *addr,int na) { }#endif +#define DT_BAD_ADDR ((u64)-1) + +/* Max address size we deal with */ +#define DT_MAX_ADDR_CELLS 4 +#define DT_CHECK_ADDR_COUNT (na) ((na) > 0 && (na) <= DT_MAX_ADDR_CELLS) +#define DT_CHECK_COUNTS (na, ns) (DT_CHECK_ADDR_COUNT(na) && (ns) > 0) + +/* Callbacks for bus specific translators */
xen/common/device_tree.c static void (*dt_printk)(const char *fmt, ...) = early_printk; · line 94
Quoted 10 lines
xen/common/device_tree.c +10
-0+struct dt_bus +{ +const char *name; +const char *addresses; +int (*match)(const struct dt_device_node *parent); +void (*count_cells)(const struct dt_device_node *child, +int *addrc,int *sizec); +u64 (*map)(__be32 *addr,const __be32 *range,int na,int ns,int pna); +int (*translate)(__be32 *addr,u64 offset,int na); +unsigned int (*get_flags)(const __be32 *addr);
Spacing is weird here. Hard tabs perhaps?
Quoted 7 lines
xen/common/device_tree.c +7
-0+static int dt_translate_one (const struct dt_device_node *parent, +const struct dt_bus *bus, +const struct dt_bus *pbus, +__be32 *addr,int na,int ns, +int pna,const char *rprop) +{ +const __be32 *ranges;
xen/common/device_tree.c int dt_n_size_cells(const struct dt_device_node *np) · line 881
Quoted 10 lines
xen/common/device_tree.c +10
-0+unsigned int rlen; +int rone; +u64 offset =DT_BAD_ADDR ; + + ranges =dt_get_property (parent, rprop, &rlen); +if ( ranges ==NULL ) + { +dt_printk (XENLOG_ERR "DT: no ranges; cannot translate\n" ); +return 1 ; + }
Indentation.
Quoted 9 lines
xen/common/device_tree.c +9
-0+if ( ranges ==NULL || rlen ==0 ) + { + offset =dt_read_number (addr, na); +memset (addr,0 , pna *4 ); +dt_dprintk ("DT: empty ranges; 1:1 translation\n" ); + goto finish; + } + +dt_dprintk ("DT: walking ranges...\n" );
xen/common/device_tree.c int dt_n_size_cells(const struct dt_device_node *np) · line 900
Quoted 10 lines
xen/common/device_tree.c +10
-0+ +/* Now walk through the ranges */ + rlen /=4 ; + rone = na + pna + ns; +for ( ; rlen >= rone; rlen -= rone, ranges += rone ) + { + offset = bus->map (addr, ranges, na, ns, pna); +if ( offset !=DT_BAD_ADDR ) +break ; + }
Indentation.
Quoted 25 lines
xen/common/device_tree.c +25
-0+if ( offset ==DT_BAD_ADDR ) + { +dt_dprintk ("DT: not found !\n" ); +return 1 ; + } +memcpy (addr, ranges + na,4 * pna); + +finish: +dt_dump_addr ("DT: parent translation for:" , addr, pna); +dt_dprintk ("DT: with offset: %llx\n" , (unsigned long long )offset); + +/* Translate it into parent bus space */ +return pbus->translate (addr, offset, pna); +} + +/* +* Translate an address from the device-tree into a CPU physical address, +* this walks up the tree and applies the various bus mappings on the +* way. +* +* Note: We consider that crossing any level with #size-cells == 0 to mean +* that translation is impossible (that is we are not dealing with a value +* that can be mapped to a cpu physical address). This is not really specified +* that way, but this is traditionally the way IBM at least do things +*/
xen/common/device_tree.c int dt_n_size_cells(const struct dt_device_node *np) · line 935
Quoted 10 lines
xen/common/device_tree.c +10
-0+static u64 __dt_translate_address (const struct dt_device_node *dev, +const __be32 *in_addr,const char *rprop) +{ +const struct dt_device_node *parent =NULL ; +const struct dt_bus *bus, *pbus; +__be32 addr[DT_MAX_ADDR_CELLS ]; +int na, ns, pna, pns; +u64 result =DT_BAD_ADDR ; + +dt_dprintk ("DT: ** translation for device %s **\n" , dev->full_name);
Ide...
Quoted 10 lines
xen/common/device_tree.c +10
-0+ +/* Get parent & match bus type */ + parent =dt_get_parent (dev); +if ( parent ==NULL ) + goto bail; + bus =dt_match_bus (parent); + +/* Count address cells & copy address locally */ + bus->count_cells (dev, &na, &ns); +if ( !DT_CHECK_COUNTS (na, ns) )
xen/common/device_tree.c int dt_n_size_cells(const struct dt_device_node *np) · line 955
Quoted 10 lines
xen/common/device_tree.c +10
-0+ { +dt_printk (XENLOG_ERR "dt_parse: Bad cell count for %s\n" , + dev->full_name); + goto bail; + } +memcpy (addr, in_addr, na *4 ); + +dt_dprintk ("DT: bus is %s (na=%d, ns=%d) on %s\n" , + bus->name, na, ns, parent->full_name); +dt_dump_addr ("DT: translating address:" , addr, na);
Inde...
xen/include/xen/device_tree.h struct dt_device_node *dt_find_node_by_path(const char *path); · line 283
Quoted 11 lines
xen/include/xen/device_tree.h +3
-0@@ -278,6 +278,28 @@ struct dt_device_node *dt_find_node_by_path(const char *path);const struct dt_device_node *dt_get_parent (const struct dt_device_node *node);/** +* dt_device_get_address - Resolve an address for a device +* @device: the device whose address is to be resolved +* @index: index of the addres to resolve
address
xen/include/xen/device_tree.h struct dt_device_node *dt_find_node_by_path(const char *path); · line 294
Quoted 11 lines
xen/include/xen/device_tree.h +11
-0+* @addr: address filled by this function +* @size: size filled by this function +* +* This function resolves an address, walking the tree, for a give +* device-tree node. It returns 0 on success. +*/ +int dt_device_get_address (const struct dt_device_node *dev,int index, +u64 *addr,u64 *size); + +/** +* dt_number_of_address - Get the number of addresse for a device
addresses
xen/include/xen/device_tree.h struct dt_device_node *dt_find_node_by_path(const char *path); · line 298
Quoted 4 lines
xen/include/xen/device_tree.h +4
-0+* @device: the device whose number of address is to be retrieved +* +* Return the number of address for this device or 0 if there is no +* address or an error occured/
occurred
Apart from the indentation and the spelling errors I'm inclined to trust that the actual logic is ok. So if you fix the above (and any indentation I missed):
Quoted 10 lines
xen/include/xen/device_tree.h +4
-1+*/ +unsigned int dt_number_of_address (const struct dt_device_node *device); + +/** * dt_n_size_cells - Helper to retrieve the number of cell for the size * @np: node to get the value * -- Julien Grall
Re: [PATCH V2 09/33] xen/arm: Add helpers to retrieve an address from the device tree
Quoted 39 lines · Ian Campbell
Quoted 38 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>--- xen/common/device_tree.c | 343 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 22 +++ 2 files changed, 365 insertions(+)xen/common/device_tree.c +20
-0@@ -62,10 +62,38 @@ static void (*dt_printk)(const char *fmt, ...) = early_printk;#ifdef DEBUG_DT # define dt_dprintk(fmt, args...) dt_printk(XENLOG_DEBUG fmt, ##args) +static void dt_dump_addr (const char *s,const __be32 *addr,int na) +{ +dt_dprintk ("%s" , s); +while ( na-- ) +dt_dprintk (" %08x" ,be32_to_cpu (*(addr++))); +dt_dprintk ("\n" ); +}#else # define dt_dprintk(fmt, args...) do {} while ( 0 ) +static void dt_dump_addr (const char *s,const __be32 *addr,int na) { }#endif +#define DT_BAD_ADDR ((u64)-1) + +/* Max address size we deal with */ +#define DT_MAX_ADDR_CELLS 4 +#define DT_CHECK_ADDR_COUNT (na) ((na) > 0 && (na) <= DT_MAX_ADDR_CELLS) +#define DT_CHECK_COUNTS (na, ns) (DT_CHECK_ADDR_COUNT(na) && (ns) > 0) + +/* Callbacks for bus specific translators */ +struct dt_bus +{ +const char *name; +const char *addresses;
Quoted 8 lines
xen/common/device_tree.c static void (*dt_printk)(const char *fmt, ...) = early_printk; · line 94
Quoted 6 lines
xen/common/device_tree.c +6
-0+int (*match)(const struct dt_device_node *parent); +void (*count_cells)(const struct dt_device_node *child, +int *addrc,int *sizec); +u64 (*map)(__be32 *addr,const __be32 *range,int na,int ns,int pna); +int (*translate)(__be32 *addr,u64 offset,int na); +unsigned int (*get_flags)(const __be32 *addr);Spacing is weird here. Hard tabs perhaps?
Right. I will fix all the errors on the next patch series.
Signature · 1 line
Julien
PATCH v2 10/33 xen/arm: Add helpers to retrieve an interrupt description from the device tree
In reply to Julien GrallChanges in v2:
- Move interrupt type from xen/irq.h to xen/device_tree.h
- Prefix all defines by DT_
--- xen/common/device_tree.c | 362 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 130 +++++++++++++++ 2 files changed, 492 insertions(+)
xen/common/device_tree.c +362 -0
@@ -27,8 +27,11 @@struct dt_early_info __initdata early_info;void *device_tree_flattened; +dt_irq_xlate_func dt_irq_xlate;/* Host device tree */ struct dt_device_node *dt_host; +/* Interrupt controller node*/ +const struct dt_device_node *dt_interrupt_controller;/** * struct dt_alias_prop - Alias property in 'aliases' node
@@ -1020,6 +1023,81 @@ int dt_device_get_address(const struct dt_device_node *dev, int index,return 0 ; } +/** +* dt_find_node_by_phandle - Find a node given a phandle +* @handle: phandle of the node to find +* +* Returns a node pointer. +*/ +static const struct dt_device_node *dt_find_node_by_phandle (dt_phandle handle) +{ +const struct dt_device_node *np; + +for_each_device_node (dt_host, np) +if ( np->phandle == handle ) +break ; + +return np; +} + +/** +* dt_irq_find_parent - Given a device node, find its interrupt parent node +* @child: pointer to device node +* +* Returns a pointer to the interrupt parent node, or NULL if the interrupt +* parent could not be determined. +*/ +static const struct dt_device_node * +dt_irq_find_parent (const struct dt_device_node *child) +{ +const struct dt_device_node *p; +const __be32 *parp; + +do + { + parp =dt_get_property (child,"interrupt-parent" ,NULL ); +if ( parp ==NULL ) + p =dt_get_parent (child); +else + p =dt_find_node_by_phandle (be32_to_cpup (parp)); + child = p; + }while ( p &&dt_get_property (p,"#interrupt-cells" ,NULL ) ==NULL ); + +return p; +} + +unsigned int dt_number_of_irq (const struct dt_device_node *device) +{ +const struct dt_device_node *p; +const __be32 *intspec, *tmp; +u32 intsize, intlen; + +dt_dprintk ("dt_irq_number: dev=%s\n" , device->full_name); + +/* Get the interrupts property */ + intspec =dt_get_property (device,"interrupts" , &intlen); +if ( intspec ==NULL ) +return 0 ; + intlen /=sizeof (*intspec); + +dt_dprintk (" intspec=%d intlen=%d\n" ,be32_to_cpup (intspec), intlen); + +/* Look for the interrupt parent. */ + p =dt_irq_find_parent (device); +if ( p ==NULL ) +return 0 ; + +/* Get size of interrupt specifier */ + tmp =dt_get_property (p,"#interrupt-cells" ,NULL ); +if ( tmp ==NULL ) +return 0 ; + intsize =be32_to_cpu (*tmp); + +dt_dprintk (" intsize=%d intlen=%d\n" , intsize, intlen); + +return (intlen / intsize); +} +unsigned int dt_number_of_address (const struct dt_device_node *dev) {const __be32 *prop;
@@ -1051,6 +1129,274 @@ unsigned int dt_number_of_address(const struct dt_device_node *dev) }/** +* dt_irq_map_raw - Low level interrupt tree parsing +* @parent: the device interrupt parent +* @intspec: interrupt specifier ("interrupts" property of the device) +* @ointsize: size of the passed in interrupt specifier +* @addr: address specifier (start of "reg" property of the device) +* @oirq: structure dt_raw_irq filled by this function +* +* Returns 0 on success and a negative number on error +* +* This function is a low-level interrupt tree walking function. It +* can be used to do a partial walk with synthetized reg and interrupts +* properties, for example when resolving PCI interrupts when no device +* node exist for the parent. +*/ +static int dt_irq_map_raw (const struct dt_device_node *parent, +const __be32 *intspec,u32 ointsize, +const __be32 *addr, +struct dt_raw_irq *oirq) +{ +const struct dt_device_node *ipar, *tnode, *old =NULL , *newpar =NULL ; +const __be32 *tmp, *imap, *imask; +u32 intsize =1 , addrsize, newintsize =0 , newaddrsize =0 ; +u32 imaplen; +int match, i; + +dt_dprintk ("dt_irq_map_raw: par=%s,intspec=[0x%08x 0x%08x...],ointsize=%d\n" , + parent->full_name,be32_to_cpup (intspec), +be32_to_cpup (intspec +1 ), ointsize); + + ipar = parent; + +/* First get the #interrupt-cells property of the current cursor +* that tells us how to interpret the passed-in intspec. If there +* is none, we are nice and just walk up the tree +*/ +do { + tmp =dt_get_property (ipar,"#interrupt-cells" ,NULL ); +if ( tmp !=NULL ) + { + intsize =be32_to_cpu (*tmp); +break ; + } + tnode = ipar; + ipar =dt_irq_find_parent (ipar); + }while ( ipar ); +if ( ipar ==NULL ) + { +dt_dprintk (" -> no parent found !\n" ); + goto fail; + } + +dt_dprintk ("dt_irq_map_raw: ipar=%s, size=%d\n" , ipar->full_name, intsize); + +if ( ointsize != intsize ) +return -EINVAL ; + +/* Look for this #address-cells. We have to implement the old linux +* trick of looking for the parent here as some device-trees rely on it +*/ + old = ipar; +do { + tmp =dt_get_property (old,"#address-cells" ,NULL ); + tnode =dt_get_parent (old); + old = tnode; + }while ( old && tmp ==NULL ); + + old =NULL ; + addrsize = (tmp ==NULL ) ?2 :be32_to_cpu (*tmp); + +dt_dprintk (" -> addrsize=%d\n" , addrsize); + +/* Now start the actual "proper" walk of the interrupt tree */ +while ( ipar !=NULL ) + { +/* Now check if cursor is an interrupt-controller and if it is +* then we are done +*/ +if (dt_get_property (ipar,"interrupt-controller" ,NULL ) !=NULL ) + { +dt_dprintk (" -> got it !\n" ); +if ( intsize >DT_MAX_IRQ_SPEC ) + { +dt_dprintk (" -> intsize(%u) greater than DT_MAX_IRQ_SPEC(%u)\n" , + intsize,DT_MAX_IRQ_SPEC ); + goto fail; + } +for ( i =0 ; i < intsize; i++ ) + oirq->specifier[i] =dt_read_number (intspec + i,1 ); + oirq->size = intsize; + oirq->controller = ipar; +return 0 ; + } + +/* Now look for an interrupt-map */ + imap =dt_get_property (ipar,"interrupt-map" , &imaplen); +/* No interrupt map, check for an interrupt parent */ +if ( imap ==NULL ) + { +dt_dprintk (" -> no map, getting parent\n" ); + newpar =dt_irq_find_parent (ipar); + goto skiplevel; + } + imaplen /=sizeof (u32); + +/* Look for a mask */ + imask =dt_get_property (ipar,"interrupt-map-mask" ,NULL ); + +/* If we were passed no "reg" property and we attempt to parse +* an interrupt-map, then #address-cells must be 0. +* Fail if it's not. +*/ +if ( addr ==NULL && addrsize !=0 ) + { +dt_dprintk (" -> no reg passed in when needed !\n" ); + goto fail; + } + +/* Parse interrupt-map */ + match =0 ; +while ( imaplen > (addrsize + intsize +1 ) && !match ) + { +/* Compare specifiers */ + match =1 ; +for ( i =0 ; i < addrsize && match; ++i ) + { +__be32 mask = imask ? imask[i] :cpu_to_be32 (0xffffffffu ); + match = ((addr[i] ^ imap[i]) & mask) ==0 ; + } +for ( ; i < (addrsize + intsize) && match; ++i ) + { +__be32 mask = imask ? imask[i] :cpu_to_be32 (0xffffffffu ); + match = ((intspec[i-addrsize] ^ imap[i]) & mask) ==0 ; + } + imap += addrsize + intsize; + imaplen -= addrsize + intsize; + +dt_dprintk (" -> match=%d (imaplen=%d)\n" , match, imaplen); + +/* Get the interrupt parent */ + newpar =dt_find_node_by_phandle (be32_to_cpup (imap)); + imap++; + --imaplen; + +/* Check if not found */ +if ( newpar ==NULL ) + { +dt_dprintk (" -> imap parent not found !\n" ); + goto fail; + } + +/* Get #interrupt-cells and #address-cells of new +* parent +*/ + tmp =dt_get_property (newpar,"#interrupt-cells" ,NULL ); +if ( tmp ==NULL ) + { +dt_dprintk (" -> parent lacks #interrupt-cells!\n" ); + goto fail; + } + newintsize =be32_to_cpu (*tmp); + tmp =dt_get_property (newpar,"#address-cells" ,NULL ); + newaddrsize = (tmp ==NULL ) ?0 :be32_to_cpu (*tmp); + +dt_dprintk (" -> newintsize=%d, newaddrsize=%d\n" , + newintsize, newaddrsize); + +/* Check for malformed properties */ +if ( imaplen < (newaddrsize + newintsize) ) + goto fail; + + imap += newaddrsize + newintsize; + imaplen -= newaddrsize + newintsize; + +dt_dprintk (" -> imaplen=%d\n" , imaplen); + } +if ( !match ) + goto fail; + + old = newpar; + addrsize = newaddrsize; + intsize = newintsize; + intspec = imap - intsize; + addr = intspec - addrsize; + + skiplevel: +/* Iterate again with new parent */ +dt_dprintk (" -> new parent: %s\n" ,dt_node_full_name (newpar)); + ipar = newpar; + newpar =NULL ; + } +fail: +return -EINVAL ; +} + +int dt_device_get_raw_irq (const struct dt_device_node *device,int index, +struct dt_raw_irq *out_irq) +{ +const struct dt_device_node *p; +const __be32 *intspec, *tmp, *addr; +u32 intsize, intlen; +int res = -EINVAL ; + +dt_dprintk ("dt_device_get_raw_irq: dev=%s, index=%d\n" , + device->full_name, index); + +/* Get the interrupts property */ + intspec =dt_get_property (device,"interrupts" , &intlen); +if ( intspec ==NULL ) +return -EINVAL ; + intlen /=sizeof (*intspec); + +dt_dprintk (" intspec=%d intlen=%d\n" ,be32_to_cpup (intspec), intlen); + +/* Get the reg property (if any) */ + addr =dt_get_property (device,"reg" ,NULL ); + +/* Look for the interrupt parent. */ + p =dt_irq_find_parent (device); +if ( p ==NULL ) +return -EINVAL ; + +/* Get size of interrupt specifier */ + tmp =dt_get_property (p,"#interrupt-cells" ,NULL ); +if ( tmp ==NULL ) + goto out; + intsize =be32_to_cpu (*tmp); + +dt_dprintk (" intsize=%d intlen=%d\n" , intsize, intlen); + +/* Check index */ +if ( (index +1 ) * intsize > intlen ) + goto out; + +/* Get new specifier and map it */ + res =dt_irq_map_raw (p, intspec + index * intsize, intsize, + addr, out_irq); +if ( res ) + goto out; +out: +return res; +} + +int dt_irq_translate (const struct dt_raw_irq *raw, +struct dt_irq *out_irq) +{ +ASSERT (dt_irq_xlate !=NULL ); + +/* TODO: Retrieve the right irq_xlate. This is only work for the gic */ + +return dt_irq_xlate (raw->specifier, raw->size, + &out_irq->irq, &out_irq->type); +} + +int dt_device_get_irq (const struct dt_device_node *device,int index, +struct dt_irq *out_irq) +{ +struct dt_raw_irq raw; +int res; + + res =dt_device_get_raw_irq (device, index, &raw); + +if ( res ) +return res; + +return dt_irq_translate (&raw, out_irq); +} + +/** * unflatten_dt_node - Alloc and populate a device_node from the flat tree * @fdt: The parent device tree blob * @mem: Memory chunk to use for allocating device nodes and properties
@@ -1392,6 +1738,22 @@ static void __init dt_alias_scan(void) } } +struct dt_device_node *__init dt_find_interrupt_controller (const char *compat) +{ +struct dt_device_node *np =NULL ; + +while ( (np =dt_find_compatible_node (np,NULL , compat)) ) + { +if ( !dt_find_property (np,"interrupt-controller" ,NULL ) ) +continue ; + +if (dt_get_parent (np) ) +break ; + } + +return np; +} +void __init dt_unflatten_host_device_tree (void ) {__unflatten_device_tree (device_tree_flattened, &dt_host);
xen/include/xen/device_tree.h +130 -0
159 lines not on this page · raw message
Signature · 1 line
Julien Grall
Re: [PATCH V2 10/33] xen/arm: Add helpers to retrieve an interrupt description from the device tree
Quoted 113 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>Changes in v2:
- Move interrupt type fromxen/irq.htoxen/device_tree.h
- Prefix all defines byDT_--- xen/common/device_tree.c | 362 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 130 +++++++++++++++ 2 files changed, 492 insertions(+)xen/common/device_tree.c +79
-0@@ -27,8 +27,11 @@struct dt_early_info __initdata early_info;void *device_tree_flattened; +dt_irq_xlate_func dt_irq_xlate;/* Host device tree */ struct dt_device_node *dt_host; +/* Interrupt controller node*/ +const struct dt_device_node *dt_interrupt_controller;/** * struct dt_alias_prop - Alias property in 'aliases' node @@ -1020,6 +1023,81 @@ int dt_device_get_address(const struct dt_device_node *dev, int index,return 0 ; } +/** +* dt_find_node_by_phandle - Find a node given a phandle +* @handle: phandle of the node to find +* +* Returns a node pointer. +*/ +static const struct dt_device_node *dt_find_node_by_phandle (dt_phandle handle) +{ +const struct dt_device_node *np; + +for_each_device_node (dt_host, np) +if ( np->phandle == handle ) +break ; + +return np; +} + +/** +* dt_irq_find_parent - Given a device node, find its interrupt parent node +* @child: pointer to device node +* +* Returns a pointer to the interrupt parent node, or NULL if the interrupt +* parent could not be determined. +*/ +static const struct dt_device_node * +dt_irq_find_parent (const struct dt_device_node *child) +{ +const struct dt_device_node *p; +const __be32 *parp; + +do + { + parp =dt_get_property (child,"interrupt-parent" ,NULL ); +if ( parp ==NULL ) + p =dt_get_parent (child); +else + p =dt_find_node_by_phandle (be32_to_cpup (parp)); + child = p; + }while ( p &&dt_get_property (p,"#interrupt-cells" ,NULL ) ==NULL ); + +return p; +} + +unsigned int dt_number_of_irq (const struct dt_device_node *device) +{ +const struct dt_device_node *p; +const __be32 *intspec, *tmp; +u32 intsize, intlen; + +dt_dprintk ("dt_irq_number: dev=%s\n" , device->full_name); + +/* Get the interrupts property */ + intspec =dt_get_property (device,"interrupts" , &intlen); +if ( intspec ==NULL ) +return 0 ; + intlen /=sizeof (*intspec); + +dt_dprintk (" intspec=%d intlen=%d\n" ,be32_to_cpup (intspec), intlen); + +/* Look for the interrupt parent. */ + p =dt_irq_find_parent (device); +if ( p ==NULL ) +return 0 ; + +/* Get size of interrupt specifier */ + tmp =dt_get_property (p,"#interrupt-cells" ,NULL ); +if ( tmp ==NULL ) +return 0 ; + intsize =be32_to_cpu (*tmp); + +dt_dprintk (" intsize=%d intlen=%d\n" , intsize, intlen); + +return (intlen / intsize); +} +unsigned int dt_number_of_address (const struct dt_device_node *dev) {const __be32 *prop;@@ -1051,6 +1129,274 @@ unsigned int dt_number_of_address(const struct dt_device_node *dev) }/** +* dt_irq_map_raw - Low level interrupt tree parsing
xen/common/device_tree.c unsigned int dt_number_of_address(const struct dt_device_node *dev) · line 1142
Quoted 10 lines
xen/common/device_tree.c +10
-0+* @parent: the device interrupt parent +* @intspec: interrupt specifier ("interrupts" property of the device) +* @ointsize: size of the passed in interrupt specifier +* @addr: address specifier (start of "reg" property of the device) +* @oirq: structure dt_raw_irq filled by this function +* +* Returns 0 on success and a negative number on error +* +* This function is a low-level interrupt tree walking function. It +* can be used to do a partial walk with synthetized reg and interrupts
synthesized
xen/common/device_tree.c unsigned int dt_number_of_address(const struct dt_device_node *dev) · line 1147
Quoted 5 lines
xen/common/device_tree.c +5
-0+/** +* dt_raw_irq - container for device_node/irq_specifier for an irq controller +* @controller: pointer to interrupt controller deivce tree node +* @size: size of interrupt specifier +* @specifier: array of cells @size long specifing the specific interrupt
specifying
xen/common/device_tree.c unsigned int dt_number_of_address(const struct dt_device_node *dev)
Quoted 7 lines
xen/common/device_tree.c +3
-0* DO NOT modify it! */ extern struct dt_device_node *dt_host; +/** +* Primary interrupt controller +* Exynos SOC has an interrupt combiner, interrupt has no physical
^an
xen/common/device_tree.c
Quoted 11 lines
+ * meaning when it's not connected to the primary controller.
+ * We will only map interrupt whose parent controller is
+ *dt_interrupt_controller. It should always be a GIC.
+ * TODO: Handle multiple GIC
+ */xen/common/device_tree.c +6
-0+extern const struct dt_device_node *dt_interrupt_controller; + +/** +* Find the interrupt controller +* For the moment we handle only one interrupt controller: the first +* one without parent and is compatible with the string "compat".
... parent which is ...
Quoted 2 lines
+/**
*dt_number_of_address- Get the number of addresse for a device
addresses
Quoted 21 lines
* @device: the device whose number of address is to be retrieved *
xen/common/device_tree.c +15
-0@@ -300,6 +399,37 @@ int dt_device_get_address(const struct dt_device_node *dev, int index,unsigned int dt_number_of_address (const struct dt_device_node *device);/** +* dt_device_get_irq - Resolve an interrupt for a device +* @device: the device whose interrupt is to be resolved +* @index: index of the interrupt to resolve +* @out_irq: structure dt_irq filled by this function +* +* This function resolves an interrupt, walking the tree, for a given +* device-tree node. It's the high level pendant to dt_device_get_raw_irq(). +*/ +int dt_device_get_irq (const struct dt_device_node *device,int index, +struct dt_irq *irq); + +/** +* dt_device_get_raw_irq - Resolve an interrupt for a device without translation +* @device: the device whose interrupt is to be resolved +* @index: index of the interrupt to resolve
xen/common/device_tree.c int dt_device_get_address(const struct dt_device_node *dev, int index, · line 426
Quoted 10 lines
xen/common/device_tree.c +10
-0+* @out_irq: structure dt_raw_irq filled by this function +* +* This function resolves an interrupt for a device, no translation is +* made. dt_irq_translate can be called after. +*/ +int dt_device_get_raw_irq (const struct dt_device_node *device,int index, +struct dt_raw_irq *irq); + +/** +* dt_irq_transalte - Translate an irq
translate
Like with the previous patch I'm inclined to trust the logic is correct. So if you fix the typoes:
Ian.
PATCH v2 11/33 xen/arm: Introduce gic_route_dt_irq
In reply to Julien GrallThis function routes an IRQ to a specific cpu. The IRQ is retrieved via the device tree.
Changes in v2:
- Use dt_irq_is_level_trigger instead of the old name irq_is_level_trigger
--- xen/arch/arm/gic.c | 11 +++++++++++ xen/include/asm-arm/gic.h | 5 +++++ 2 files changed, 16 insertions(+)
xen/arch/arm/gic.c +11 -0
@@ -238,6 +238,17 @@ static int gic_route_irq(unsigned int irq, bool_t level,return 0 ; } +/* Program the GIC to route an interrupt with a dt_irq */ +void gic_route_dt_irq (const struct dt_irq *irq,unsigned int cpu_mask, +unsigned int priority) +{ +bool_t level; + + level =dt_irq_is_level_trigger (irq); + +gic_route_irq (irq->irq, level, cpu_mask, priority); +} +static void __init gic_dist_init (void ) {uint32_t type;
xen/include/asm-arm/gic.h +5 -0
@@ -133,6 +133,8 @@#define VGIC_IRQ_EVTCHN_CALLBACK 31#ifndef __ASSEMBLY__ +#include <xen/device_tree.h> +extern int domain_vgic_init (struct domain *d);extern void domain_vgic_free (struct domain *d);
@@ -142,6 +144,9 @@ extern void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq,int virtual);extern void vgic_clear_pending_irqs (struct vcpu *v);extern struct pending_irq *irq_to_pending (struct vcpu *v,unsigned int irq); +/* Program the GIC to route an interrupt with a dt_irq */ +extern void gic_route_dt_irq (const struct dt_irq *irq,unsigned int cpu_mask, +unsigned int priority);extern void gic_route_ppis (void );extern void gic_route_spis (void );
Signature · 1 line
Julien Grall
Re: [PATCH V2 11/33] xen/arm: Introduce gic_route_dt_irq
Quoted 7 lines · Julien Grall
This function routes an IRQ to a specific cpu. The IRQ is retrieved via the device tree.
Signed-off-by Julien Grall <[email protected]>Changes in v2:
- Usedt_irq_is_level_triggerinstead of the old nameirq_is_level_trigger
Should be ...is_level_triggered().
Other than that:
Ian.
PATCH v2 12/33 xen/arm: Introduce gic_irq_xlate
In reply to Julien GrallThis function translates an interrupt specifier to an IRQ number and IRQ type (ie: level trigger, edge trigger,...). It's GIC specific.
Changes in v2:
- Use DT_IRQ_TYPE_SENSE_MASK instead of IRQ_TYPE_SENSE_MASK
--- xen/arch/arm/gic.c | 20 ++++++++++++++++++++ xen/arch/arm/setup.c | 1 + xen/include/asm-arm/gic.h | 4 ++++ 3 files changed, 25 insertions(+)
xen/arch/arm/gic.c +20 -0
@@ -329,6 +329,26 @@ static void __cpuinit gic_hyp_disable(void)GICH [GICH_HCR ] =0 ; } +int gic_irq_xlate (const u32 *intspec,unsigned int intsize, +unsigned int *out_hwirq, +unsigned int *out_type) +{ +if ( intsize <3 ) +return -EINVAL ; + +/* Get the interrupt number and add 16 to skip over SGIs */ + *out_hwirq = intspec[1 ] +16 ; + +/* For SPIs, we need to add 16 more to get the GIC irq ID number */ +if ( !intspec[0 ] ) + *out_hwirq +=16 ; + +if ( out_type ) + *out_type = intspec[2 ] &DT_IRQ_TYPE_SENSE_MASK ; + +return 0 ; +} +/* Set up the GIC */ void __init gic_init (void ) {
xen/arch/arm/setup.c +1 -0
@@ -430,6 +430,7 @@ void __init start_xen(unsigned long boot_phys_offset,setup_mm (fdt_paddr, fdt_size);dt_unflatten_host_device_tree (); + dt_irq_xlate = gic_irq_xlate;#ifdef EARLY_UART_ADDRESS /* TODO Need to get device tree or command line for UART address */
xen/include/asm-arm/gic.h +4 -0
@@ -189,6 +189,10 @@ extern void send_SGI_allbutself(enum gic_sgi sgi);/* print useful debug info */ extern void gic_dump_info (struct vcpu *v); +/* IRQ translation function for the device tree */ +int gic_irq_xlate (const u32 *intspec,unsigned int intsize, +unsigned int *out_hwirq,unsigned int *out_type); +#endif /* __ASSEMBLY__ */ #endif
Signature · 1 line
Julien Grall
Re: [PATCH V2 12/33] xen/arm: Introduce gic_irq_xlate
Quoted 4 lines · Julien Grall
This function translates an interrupt specifier to an IRQ number and IRQ type (ie: level trigger, edge trigger,...). It's GIC specific.
Signed-off-by Julien Grall <[email protected]>
PATCH v2 13/33 xen/arm: Introduce setup_dt_irq
In reply to Julien GrallThis function will replace setup_irq in later patch. It takes a dt_irq as first argument instead of an unsigned int.
--- xen/arch/arm/gic.c | 5 +++++ xen/include/asm-arm/irq.h | 4 ++++ 2 files changed, 9 insertions(+)
xen/arch/arm/gic.c +5 -0
@@ -521,6 +521,11 @@ static int __setup_irq(struct irq_desc *desc, unsigned int irq,return 0 ; } +int __init setup_dt_irq (const struct dt_irq *irq,struct irqaction *new) +{ +return setup_irq (irq->irq, new); +} +int __init setup_irq (unsigned int irq,struct irqaction *new) {int rc;
xen/include/asm-arm/irq.h +4 -0
@@ -2,6 +2,7 @@#define _ASM_HW_IRQ_H#include <xen/config.h> +#include <xen/device_tree.h> #define NR_VECTORS 256/* XXX */
@@ -25,6 +26,7 @@ struct irq_cfg {#define nr_static_irqs NR_IRQSstruct irq_desc ; +struct irqaction ;struct irq_desc *__irq_to_desc (int irq);
@@ -37,6 +39,8 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq);void init_IRQ (void );void init_secondary_IRQ (void ); +int __init setup_dt_irq (const struct dt_irq *irq,struct irqaction *new); +#endif /* _ASM_HW_IRQ_H */ /* * Local variables:
Signature · 1 line
Julien Grall
Re: [PATCH V2 13/33] xen/arm: Introduce setup_dt_irq
Quoted 4 lines · Julien Grall
This function will replace
setup_irqin later patch. It takes adt_irqas first argument instead of an unsigned int.Signed-off-by Julien Grall <[email protected]>
PATCH v2 14/33 xen/arm: Introduce request_dt_irq
In reply to Julien GrallThis function will replace request_irq in a later patch. It takes a dt_irq as first argument instead of an unsigned int.
--- xen/arch/arm/irq.c | 7 +++++++ xen/include/asm-arm/irq.h | 4 ++++ 2 files changed, 11 insertions(+)
xen/arch/arm/irq.c +7 -0
@@ -93,6 +93,13 @@ void __cpuinit init_secondary_IRQ(void)BUG_ON (init_local_irq_data () <0 ); } +int __init request_dt_irq (const struct dt_irq *irq, +void (*handler)(int ,void *,struct cpu_user_regs *), +unsigned long irqflags,const char *devname,void *dev_id) +{ +return request_irq (irq->irq, handler, irqflags, devname, dev_id); +} +int __init request_irq (unsigned int irq,void (*handler)(int ,void *,struct cpu_user_regs *),unsigned long irqflags,const char * devname,void *dev_id)
xen/include/asm-arm/irq.h +4 -0
@@ -39,6 +39,10 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq);void init_IRQ (void );void init_secondary_IRQ (void ); +int __init request_dt_irq (const struct dt_irq *irq, +void (*handler)(int ,void *,struct cpu_user_regs *), +unsigned long irqflags,const char *devname, +void *dev_id);int __init setup_dt_irq (const struct dt_irq *irq,struct irqaction *new);#endif /* _ASM_HW_IRQ_H */
Signature · 1 line
Julien Grall
Re: [PATCH V2 14/33] xen/arm: Introduce request_dt_irq
Quoted 4 lines · Julien Grall
This function will replace
request_irqin a later patch. It takes adt_irqas first argument instead of an unsigned int.Signed-off-by Julien Grall <[email protected]>
PATCH v2 15/33 xen/arm: Use hierarchical device tree to retrieve GIC information
In reply to Julien Grall- Remove early parsing for GIC addresses
- Remove hard coded maintenance IRQ number
Changes in v2:
- use the new function request_dt_irq
--- xen/arch/arm/gic.c | 63 ++++++++++++++++++++++++++++------------- xen/common/device_tree.c | 42 --------------------------- xen/include/xen/device_tree.h | 8 ------ 3 files changed, 43 insertions(+), 70 deletions(-)
xen/arch/arm/gic.c +43 -20
@@ -45,6 +45,7 @@ static struct {paddr_t hbase;/* Address of virtual interface registers */ paddr_t vbase;/* Address of virtual cpu interface registers */ unsigned int lines;/* Number of interrupts (SPIs + PPIs + SGIs) */ +struct dt_irq maintenance;/* IRQ maintenance */ unsigned int cpus;spinlock_t lock; } gic;
@@ -352,28 +353,49 @@ int gic_irq_xlate(const u32 *intspec, unsigned int intsize,/* Set up the GIC */ void __init gic_init (void ) { +struct dt_device_node *node; +int res; + + node =dt_find_interrupt_controller ("arm,cortex-a15-gic" ); +if ( !node ) +panic ("Unable to find compatible GIC in the device tree\n" ); + +dt_device_set_used_by (node,DT_USED_BY_XEN ); + + res =dt_device_get_address (node,0 , &gic.dbase,NULL ); +if ( res || !gic.dbase || (gic.dbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the distributor\n" ); + + res =dt_device_get_address (node,1 , &gic.cbase,NULL ); +if ( res || !gic.cbase || (gic.cbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the CPU\n" ); + + res =dt_device_get_address (node,2 , &gic.hbase,NULL ); +if ( res || !gic.hbase || (gic.hbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the hypervisor\n" ); + + res =dt_device_get_address (node,3 , &gic.vbase,NULL ); +if ( res || !gic.vbase || (gic.vbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the virtual CPU\n" ); + + res =dt_device_get_irq (node,0 , &gic.maintenance); +if ( res ) +panic ("GIC: Cannot find the maintenance IRQ\n" ); + +/* Set the GIC as the primary interrupt controller */ + dt_interrupt_controller = node; + +/* TODO: Add check on distributor, cpu size */ +printk ("GIC initialization:\n" " gic_dist_addr=%" PRIpaddr"\n" " gic_cpu_addr=%" PRIpaddr"\n" " gic_hyp_addr=%" PRIpaddr"\n" -" gic_vcpu_addr=%" PRIpaddr"\n" , - early_info.gic.gic_dist_addr, early_info.gic.gic_cpu_addr, - early_info.gic.gic_hyp_addr, early_info.gic.gic_vcpu_addr); -if ( !early_info.gic.gic_dist_addr || - !early_info.gic.gic_cpu_addr || - !early_info.gic.gic_hyp_addr || - !early_info.gic.gic_vcpu_addr ) -panic ("the physical address of one of the GIC interfaces is missing\n" ); -if ( (early_info.gic.gic_dist_addr & ~PAGE_MASK ) || - (early_info.gic.gic_cpu_addr & ~PAGE_MASK ) || - (early_info.gic.gic_hyp_addr & ~PAGE_MASK ) || - (early_info.gic.gic_vcpu_addr & ~PAGE_MASK ) ) -panic ("GIC interfaces not page aligned.\n" ); - - gic.dbase = early_info.gic.gic_dist_addr; - gic.cbase = early_info.gic.gic_cpu_addr; - gic.hbase = early_info.gic.gic_hyp_addr; - gic.vbase = early_info.gic.gic_vcpu_addr; +" gic_vcpu_addr=%" PRIpaddr"\n" +" gic_maintenance_irq=%u\n" , + gic.dbase, gic.cbase, gic.hbase, gic.vbase, + gic.maintenance.irq); +set_fixmap (FIXMAP_GICD , gic.dbase >>PAGE_SHIFT ,DEV_SHARED );BUILD_BUG_ON (FIXMAP_ADDR (FIXMAP_GICC1 ) !=FIXMAP_ADDR (FIXMAP_GICC2 )-PAGE_SIZE );
@@ -464,7 +486,7 @@ void gic_route_ppis(void) {/* XXX should get these from DT */ /* GIC maintenance */ -gic_route_irq (25 ,1 ,1u <<smp_processor_id (),0xa0 ); +gic_route_dt_irq (&gic.maintenance,1u <<smp_processor_id (),0xa0 );/* Hypervisor Timer */ gic_route_irq (26 ,1 ,1u <<smp_processor_id (),0xa0 );/* Virtual Timer */
@@ -830,7 +852,8 @@ void gic_dump_info(struct vcpu *v)void __cpuinit init_maintenance_interrupt (void ) { -request_irq (25 , maintenance_interrupt,0 ,"irq-maintenance" ,NULL ); +request_dt_irq (&gic.maintenance, maintenance_interrupt, +0 ,"irq-maintenance" ,NULL ); }/*
xen/common/device_tree.c +0 -42
54 lines not on this page · raw message
xen/include/xen/device_tree.h +0 -8
@@ -31,13 +31,6 @@ struct dt_mem_info {struct membank bank[NR_MEM_BANKS ]; }; -struct dt_gic_info { -paddr_t gic_dist_addr; -paddr_t gic_cpu_addr; -paddr_t gic_hyp_addr; -paddr_t gic_vcpu_addr; -}; -struct dt_mb_module {paddr_t start;paddr_t size;
@@ -52,7 +45,6 @@ struct dt_module_info {struct dt_early_info {struct dt_mem_info mem; -struct dt_gic_info gic;struct dt_module_info modules; };
Signature · 1 line
Julien Grall
Re: [PATCH V2 15/33] xen/arm: Use hierarchical device tree to retrieve GIC information
Quoted 70 lines · Julien Grall
- Remove early parsing for GIC addresses
- Remove hard coded maintenance IRQ numberSigned-off-by Julien Grall <[email protected]>Changes in v2:
- use the new functionrequest_dt_irq--- xen/arch/arm/gic.c | 63 ++++++++++++++++++++++++++++------------- xen/common/device_tree.c | 42 --------------------------- xen/include/xen/device_tree.h | 8 ------ 3 files changed, 43 insertions(+), 70 deletions(-)xen/arch/arm/gic.c +35
-3@@ -45,6 +45,7 @@ static struct {paddr_t hbase;/* Address of virtual interface registers */ paddr_t vbase;/* Address of virtual cpu interface registers */ unsigned int lines;/* Number of interrupts (SPIs + PPIs + SGIs) */ +struct dt_irq maintenance;/* IRQ maintenance */ unsigned int cpus;spinlock_t lock; } gic;@@ -352,28 +353,49 @@ int gic_irq_xlate(const u32 *intspec, unsigned int intsize,/* Set up the GIC */ void __init gic_init (void ) { +struct dt_device_node *node; +int res; + + node =dt_find_interrupt_controller ("arm,cortex-a15-gic" ); +if ( !node ) +panic ("Unable to find compatible GIC in the device tree\n" ); + +dt_device_set_used_by (node,DT_USED_BY_XEN ); + + res =dt_device_get_address (node,0 , &gic.dbase,NULL ); +if ( res || !gic.dbase || (gic.dbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the distributor\n" ); + + res =dt_device_get_address (node,1 , &gic.cbase,NULL ); +if ( res || !gic.cbase || (gic.cbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the CPU\n" ); + + res =dt_device_get_address (node,2 , &gic.hbase,NULL ); +if ( res || !gic.hbase || (gic.hbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the hypervisor\n" ); + + res =dt_device_get_address (node,3 , &gic.vbase,NULL ); +if ( res || !gic.vbase || (gic.vbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the virtual CPU\n" ); + + res =dt_device_get_irq (node,0 , &gic.maintenance); +if ( res ) +panic ("GIC: Cannot find the maintenance IRQ\n" ); + +/* Set the GIC as the primary interrupt controller */ + dt_interrupt_controller = node; + +/* TODO: Add check on distributor, cpu size */ +printk ("GIC initialization:\n" " gic_dist_addr=%" PRIpaddr"\n" " gic_cpu_addr=%" PRIpaddr"\n" " gic_hyp_addr=%"PRIpaddr"\n" -" gic_vcpu_addr=%" PRIpaddr"\n" , - early_info.gic.gic_dist_addr, early_info.gic.gic_cpu_addr, - early_info.gic.gic_hyp_addr, early_info.gic.gic_vcpu_addr);
xen/arch/arm/gic.c int gic_irq_xlate(const u32 *intspec, unsigned int intsize, · line 371
Quoted 10 lines
xen/arch/arm/gic.c +0
-10-if ( !early_info.gic.gic_dist_addr || - !early_info.gic.gic_cpu_addr || - !early_info.gic.gic_hyp_addr || - !early_info.gic.gic_vcpu_addr ) -panic ("the physical address of one of the GIC interfaces is missing\n" ); -if ( (early_info.gic.gic_dist_addr & ~PAGE_MASK ) || - (early_info.gic.gic_cpu_addr & ~PAGE_MASK ) || - (early_info.gic.gic_hyp_addr & ~PAGE_MASK ) || - (early_info.gic.gic_vcpu_addr & ~PAGE_MASK ) ) -panic ("GIC interfaces not page aligned.\n" );
Please can we keep this last check separate and after the print, this way we get to see why it failed (not present vs invalid).
I'm ambivalent about keeping the !gic.Xbase separate or including it in the res check.
Ian.
Re: [PATCH V2 15/33] xen/arm: Use hierarchical device tree to retrieve GIC information
Quoted 76 lines · Ian Campbell
Quoted 75 lines · Julien Grall
- Remove early parsing for GIC addresses
- Remove hard coded maintenance IRQ numberSigned-off-by Julien Grall <[email protected]>Changes in v2:
- use the new functionrequest_dt_irq--- xen/arch/arm/gic.c | 63 ++++++++++++++++++++++++++++------------- xen/common/device_tree.c | 42 --------------------------- xen/include/xen/device_tree.h | 8 ------ 3 files changed, 43 insertions(+), 70 deletions(-)xen/arch/arm/gic.c +35
-8@@ -45,6 +45,7 @@ static struct {paddr_t hbase;/* Address of virtual interface registers */ paddr_t vbase;/* Address of virtual cpu interface registers */ unsigned int lines;/* Number of interrupts (SPIs + PPIs + SGIs) */ +struct dt_irq maintenance;/* IRQ maintenance */ unsigned int cpus;spinlock_t lock; } gic;@@ -352,28 +353,49 @@ int gic_irq_xlate(const u32 *intspec, unsigned int intsize,/* Set up the GIC */ void __init gic_init (void ) { +struct dt_device_node *node; +int res; + + node =dt_find_interrupt_controller ("arm,cortex-a15-gic" ); +if ( !node ) +panic ("Unable to find compatible GIC in the device tree\n" ); + +dt_device_set_used_by (node,DT_USED_BY_XEN ); + + res =dt_device_get_address (node,0 , &gic.dbase,NULL ); +if ( res || !gic.dbase || (gic.dbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the distributor\n" ); + + res =dt_device_get_address (node,1 , &gic.cbase,NULL ); +if ( res || !gic.cbase || (gic.cbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the CPU\n" ); + + res =dt_device_get_address (node,2 , &gic.hbase,NULL ); +if ( res || !gic.hbase || (gic.hbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the hypervisor\n" ); + + res =dt_device_get_address (node,3 , &gic.vbase,NULL ); +if ( res || !gic.vbase || (gic.vbase & ~PAGE_MASK ) ) +panic ("GIC: Cannot find a valid address for the virtual CPU\n" ); + + res =dt_device_get_irq (node,0 , &gic.maintenance); +if ( res ) +panic ("GIC: Cannot find the maintenance IRQ\n" ); + +/* Set the GIC as the primary interrupt controller */ + dt_interrupt_controller = node; + +/* TODO: Add check on distributor, cpu size */ +printk ("GIC initialization:\n" " gic_dist_addr=%" PRIpaddr"\n" " gic_cpu_addr=%" PRIpaddr"\n" " gic_hyp_addr=%"PRIpaddr"\n" -" gic_vcpu_addr=%" PRIpaddr"\n" , - early_info.gic.gic_dist_addr, early_info.gic.gic_cpu_addr, - early_info.gic.gic_hyp_addr, early_info.gic.gic_vcpu_addr); -if ( !early_info.gic.gic_dist_addr || - !early_info.gic.gic_cpu_addr || - !early_info.gic.gic_hyp_addr || - !early_info.gic.gic_vcpu_addr ) -panic ("the physical address of one of the GIC interfaces is missing\n" );
Quoted 8 lines
xen/arch/arm/gic.c int gic_irq_xlate(const u32 *intspec, unsigned int intsize, · line 371
Quoted 5 lines
xen/arch/arm/gic.c +0
-5-if ( (early_info.gic.gic_dist_addr & ~PAGE_MASK ) || - (early_info.gic.gic_cpu_addr & ~PAGE_MASK ) || - (early_info.gic.gic_hyp_addr & ~PAGE_MASK ) || - (early_info.gic.gic_vcpu_addr & ~PAGE_MASK ) ) -panic ("GIC interfaces not page aligned.\n" );Please can we keep this last check separate and after the print, this way we get to see why it failed (not present vs invalid).
I will fix it on the next patch series.
Quoted 3 lines
I'm ambivalent about keeping the !gic.Xbase separate or including it in the res check.
I don't see a good reason why the gic base address could not be 0. I prefer to remove this check.
Signature · 1 line
Julien
Re: [PATCH V2 15/33] xen/arm: Use hierarchical device tree to retrieve GIC information
Quoted 7 lines · Julien Grall
Quoted 2 lines · Ian Campbell
Please can we keep this last check separate and after the print, this way we get to see why it failed (not present vs invalid).
I will fix it on the next patch series.
Thanks.
Quoted 7 lines
Quoted 3 lines
I'm ambivalent about keeping the !gic.Xbase separate or including it in the res check.
I don't see a good reason why the gic base address could not be 0. I prefer to remove this check.
True, agreed.
Ian.
PATCH v2 16/33 xen/arm: Retrieve timer interrupts from the device tree
In reply to Julien GrallChanges in v2:
- Hardcode ppi_nr value
- Use the new function request_dt_irq
--- xen/arch/arm/gic.c | 9 ++----- xen/arch/arm/time.c | 59 +++++++++++++++++++++++++++++++++++++++----- xen/include/asm-arm/time.h | 3 +++ 3 files changed, 58 insertions(+), 13 deletions(-)
xen/arch/arm/gic.c +2 -7
@@ -484,15 +484,10 @@ void gic_disable_cpu(void)void gic_route_ppis (void ) { -/* XXX should get these from DT */ /* GIC maintenance */ gic_route_dt_irq (&gic.maintenance,1u <<smp_processor_id (),0xa0 ); -/* Hypervisor Timer */ -gic_route_irq (26 ,1 ,1u <<smp_processor_id (),0xa0 ); -/* Virtual Timer */ -gic_route_irq (27 ,1 ,1u <<smp_processor_id (),0xa0 ); -/* Physical Timer */ -gic_route_irq (30 ,1 ,1u <<smp_processor_id (),0xa0 ); +/* Route timer interrupt */ +route_timer_interrupt (); }void gic_route_spis (void )
xen/arch/arm/time.c +53 -6
101 lines not on this page · raw message
xen/include/asm-arm/time.h +3 -0
@@ -12,6 +12,9 @@ struct tm;struct tm wallclock_time (void ); +/* Route timer's IRQ on this CPU */ +extern void __cpuinit route_timer_interrupt (void ); +/* Set up the timer interrupt on this CPU */ extern void __cpuinit init_timer_interrupt (void );
Signature · 1 line
Julien Grall
Re: [PATCH V2 16/33] xen/arm: Retrieve timer interrupts from the device tree
xen/arch/arm/time.c static void vtimer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs) · line 213
Quoted 11 lines
xen/arch/arm/time.c +7
-0@@ -167,6 +204,15 @@ static void vtimer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)vgic_vcpu_inject_irq (current, irq,1 ); } +/* Route timer's IRQ on this CPU */ +void __cpuinit route_timer_interrupt (void ) +{ +gic_route_dt_irq (&timer_irq[PHYS_NONSECURE_PPI ], +1u <<smp_processor_id (),0xa0 ); +gic_route_dt_irq (&timer_irq[HYP_PPI ],1u <<smp_processor_id (),0xa0 ); +gic_route_dt_irq (&timer_irq[VIRT_PPI ],1u <<smp_processor_id (),0xa0 );
It occurs to me that this guy (and the underlying function) should probably take a cpumask_t. Not now though.
Quoted 8 lines
xen/arch/arm/time.c +2
-0+} +/* Set up the timer interrupt on this CPU */ void __cpuinit init_timer_interrupt (void ) {@@ -184,10 +230,11 @@ void __cpuinit init_timer_interrupt(void)WRITE_SYSREG32 (0 ,CNTHP_CTL_EL2 );/* Hypervisor's timer disabled */ isb ();
xen/arch/arm/time.c void __cpuinit init_timer_interrupt(void) · line 237
Quoted 10 lines
xen/arch/arm/time.c +5
-4-/* XXX Need to find this IRQ number from devicetree? */ -request_irq (26 , timer_interrupt,0 ,"hyptimer" ,NULL ); -request_irq (27 , vtimer_interrupt,0 ,"virtimer" ,NULL ); -request_irq (30 , timer_interrupt,0 ,"phytimer" ,NULL ); +request_dt_irq (&timer_irq[HYP_PPI ], timer_interrupt,0 ,"hyptimer" ,NULL ); +request_dt_irq (&timer_irq[VIRT_PPI ], vtimer_interrupt,0 , +"virtimer" ,NULL ); +request_dt_irq (&timer_irq[PHYS_NONSECURE_PPI ], timer_interrupt,2 , +"phytimer" ,NULL );
Why the change to flags == 2 here?
Ian.
Re: [PATCH V2 16/33] xen/arm: Retrieve timer interrupts from the device tree
Quoted 24 lines · Ian Campbell
xen/arch/arm/time.c static void vtimer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs) · line 213
Quoted 11 lines
xen/arch/arm/time.c +7
-0@@ -167,6 +204,15 @@ static void vtimer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)vgic_vcpu_inject_irq (current, irq,1 ); } +/* Route timer's IRQ on this CPU */ +void __cpuinit route_timer_interrupt (void ) +{ +gic_route_dt_irq (&timer_irq[PHYS_NONSECURE_PPI ], +1u <<smp_processor_id (),0xa0 ); +gic_route_dt_irq (&timer_irq[HYP_PPI ],1u <<smp_processor_id (),0xa0 ); +gic_route_dt_irq (&timer_irq[VIRT_PPI ],1u <<smp_processor_id (),0xa0 );It occurs to me that this guy (and the underlying function) should probably take a
cpumask_t. Not now though.Quoted 9 lines
xen/arch/arm/time.c +2
-0+} +/* Set up the timer interrupt on this CPU */ void __cpuinit init_timer_interrupt (void ) {@@ -184,10 +230,11 @@ void __cpuinit init_timer_interrupt(void)WRITE_SYSREG32 (0 ,CNTHP_CTL_EL2 );/* Hypervisor's timer disabled */ isb ();
Quoted 11 lines
xen/arch/arm/time.c void __cpuinit init_timer_interrupt(void) · line 237
Quoted 9 lines
xen/arch/arm/time.c +5
-4-/* XXX Need to find this IRQ number from devicetree? */ -request_irq (26 , timer_interrupt,0 ,"hyptimer" ,NULL ); -request_irq (27 , vtimer_interrupt,0 ,"virtimer" ,NULL ); -request_irq (30 , timer_interrupt,0 ,"phytimer" ,NULL ); +request_dt_irq (&timer_irq[HYP_PPI ], timer_interrupt,0 ,"hyptimer" ,NULL ); +request_dt_irq (&timer_irq[VIRT_PPI ], vtimer_interrupt,0 , +"virtimer" ,NULL ); +request_dt_irq (&timer_irq[PHYS_NONSECURE_PPI ], timer_interrupt,2 , +"phytimer" ,NULL );Why the change to flags == 2 here?
It's a mistake. I will fix it on the next patch series.
Signature · 1 line
Julien
PATCH v2 17/33 xen/arm: Don't hardcode VGIC informations
In reply to Julien Grall- Define VGIC base address per domain. For the moment the base addresses to dom0 base addresses.
- The number of interrupt lines (ie number of SPIs) is equal to:
* 0 for guests
* number of host SPIs for dom0
Changes in v2:
- Don't use javadoc style
--- xen/arch/arm/gic.c | 21 ++++++++++++++++++--- xen/arch/arm/vgic.c | 20 ++++++++++++++------ xen/include/asm-arm/domain.h | 5 ++++- xen/include/asm-arm/gic.h | 3 +++ 4 files changed, 39 insertions(+), 10 deletions(-)
xen/arch/arm/gic.c +18 -3
@@ -56,6 +56,11 @@ static DEFINE_PER_CPU(uint64_t, lr_mask);static unsigned nr_lrs; +unsigned int gic_number_lines (void ) +{ +return gic.lines; +} +irq_desc_t *__irq_to_desc (int irq) {if (irq <NR_LOCAL_IRQS )return &this_cpu (local_irq_desc)[irq];
@@ -771,11 +776,21 @@ void gic_interrupt(struct cpu_user_regs *regs, int is_fiq)int gicv_setup (struct domain *d) { +/* TODO: Retrieve distributor and CPU guest base address from the +* guest DTS +* For the moment we use dom0 DTS +*/ + d->arch.vgic.dbase = gic.dbase; + d->arch.vgic.cbase = gic.cbase; + + + d->arch.vgic.nr_lines =0 ; +/* map the gic virtual cpu interface in the gic cpu interface region of * the guest */ -return map_mmio_regions (d, gic.cbase, - gic.cbase + (2 *PAGE_SIZE ) -1 , - gic.vbase); +return map_mmio_regions (d, d->arch.vgic.cbase, + d->arch.vgic.cbase + (2 *PAGE_SIZE ) -1 , + gic.vbase); }static void maintenance_interrupt (int irq,void *dev_id,struct cpu_user_regs *regs)
xen/arch/arm/vgic.c +14 -6
@@ -30,8 +30,6 @@#include "io.h" #include <asm/gic.h> -#define VGIC_DISTR_BASE_ADDRESS 0x000000002c001000 -#define REG (n) (n/4)/* Number of ranks of interrupt registers for a domain */
@@ -80,7 +78,15 @@ int domain_vgic_init(struct domain *d)int i; d->arch.vgic.ctlr =0 ; - d->arch.vgic.nr_lines =32 ; + +/* Currently nr_lines in vgic and gic doesn't have the same meanings +* Here nr_lines = number of SPIs +*/ +if ( d->domain_id ==0 ) + d->arch.vgic.nr_lines =gic_number_lines () -32 ; +else + d->arch.vgic.nr_lines =0 ;/* We don't need SPIs for the guest */ + d->arch.vgic.shared_irqs = xmalloc_array(struct vgic_irq_rank, DOMAIN_NR_RANKS(d)); d->arch.vgic.pending_irqs =
@@ -163,7 +169,7 @@ static int vgic_distr_mmio_read(struct vcpu *v, mmio_info_t *info)struct cpu_user_regs *regs =guest_cpu_user_regs ();register_t *r =select_user_reg (regs, dabt.reg);struct vgic_irq_rank *rank; -int offset = (int )(info->gpa -VGIC_DISTR_BASE_ADDRESS ); +int offset = (int )(info->gpa - v->domain->arch.vgic.dbase);int gicd_reg =REG (offset); switch ( gicd_reg )
@@ -440,7 +446,7 @@ static int vgic_distr_mmio_write(struct vcpu *v, mmio_info_t *info)struct cpu_user_regs *regs =guest_cpu_user_regs ();register_t *r =select_user_reg (regs, dabt.reg);struct vgic_irq_rank *rank; -int offset = (int )(info->gpa -VGIC_DISTR_BASE_ADDRESS ); +int offset = (int )(info->gpa - v->domain->arch.vgic.dbase);int gicd_reg =REG (offset);uint32_t tr;
@@ -620,7 +626,9 @@ write_ignore:static int vgic_distr_mmio_check (struct vcpu *v,paddr_t addr) { -return addr >=VGIC_DISTR_BASE_ADDRESS && addr < (VGIC_DISTR_BASE_ADDRESS +PAGE_SIZE ); +struct domain *d = v->domain; + +return (addr >= (d->arch.vgic.dbase)) && (addr < (d->arch.vgic.dbase +PAGE_SIZE )); }const struct mmio_handler vgic_distr_mmio_handler = {
xen/include/asm-arm/domain.h +4 -1
@@ -88,13 +88,16 @@ struct arch_domain*/ spinlock_t lock;int ctlr; -int nr_lines; +int nr_lines;/* Number of SPIs */ struct vgic_irq_rank *shared_irqs;/* * SPIs are domain global, SGIs and PPIs are per-VCPU and stored in * struct arch_vcpu. */ struct pending_irq *pending_irqs; +/* Base address for guest GIC */ +paddr_t dbase;/* Distributor base address */ +paddr_t cbase;/* CPU base address */ } vgic;struct vpl011 {
xen/include/asm-arm/gic.h +3 -0
@@ -189,6 +189,9 @@ extern void send_SGI_allbutself(enum gic_sgi sgi);/* print useful debug info */ extern void gic_dump_info (struct vcpu *v); +/* Number of interrupt lines */ +extern unsigned int gic_number_lines (void ); +/* IRQ translation function for the device tree */ int gic_irq_xlate (const u32 *intspec,unsigned int intsize,unsigned int *out_hwirq,unsigned int *out_type);
Signature · 1 line
Julien Grall
PATCH v2 18/33 xen/arm: Introduce a generic way to use a device from the device tree
In reply to Julien GrallChanges in v2:
- Add missing ALIGN in xen.lds.S
--- xen/arch/arm/Makefile | 1 + xen/arch/arm/device.c | 74 ++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/xen.lds.S | 7 ++++ xen/include/asm-arm/device.h | 52 +++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 xen/arch/arm/device.c create mode 100644 xen/include/asm-arm/device.h
xen/arch/arm/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-y += vgic.o obj-y += vtimer.o obj-y += vpl011.o obj-y += hvm.o +obj-y += device.o #obj-bin-y += ....o
xen/arch/arm/device.c new file +74 -0
74 lines not on this page · raw message
xen/arch/arm/xen.lds.S +7 -0
@@ -76,6 +76,13 @@ SECTIONS __lock_profile_end = .; #endif + . = ALIGN(8); + .dev.info : { + _sdevice = .; + *(.dev.info) + _edevice = .; + } :text + . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; .init.text : {
xen/include/asm-arm/device.h new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
Julien Grall
Re: [PATCH V2 18/33] xen/arm: Introduce a generic way to use a device from the device tree
Quoted 1 line · Julien Grall
Signed-off-by Julien Grall <[email protected]>
PATCH v2 19/33 xen/arm: New callback in uart_driver to get device tree interrupt structure
In reply to Julien GrallThe existing function serial_irq doesn't allow to retrieve if the interrupt is edge or level trigger.
Use this function to routes IRQs for all serial ports which Xen is using to Xen.
Changes in v2:
- Improve commit message
--- xen/arch/arm/gic.c | 12 ++++++++++++ xen/drivers/char/serial.c | 10 ++++++++++ xen/include/xen/serial.h | 5 +++++ 3 files changed, 27 insertions(+)
xen/arch/arm/gic.c +12 -0
@@ -24,6 +24,7 @@#include <xen/irq.h> #include <xen/sched.h> #include <xen/errno.h> +#include <xen/serial.h> #include <xen/softirq.h> #include <xen/list.h> #include <xen/device_tree.h>
@@ -497,9 +498,20 @@ void gic_route_ppis(void)void gic_route_spis (void ) { +int seridx; +const struct dt_irq *irq; +/* XXX should get these from DT */ /* UART */ gic_route_irq (37 ,0 ,1u <<smp_processor_id (),0xa0 ); + +for ( seridx =0 ; seridx <=SERHND_IDX ; seridx++ ) + { +if ( (irq =serial_dt_irq (seridx)) ==NULL ) +continue ; + +gic_route_dt_irq (irq,1u <<smp_processor_id (),0xa0 ); + } }void __init release_irq (unsigned int irq)
xen/drivers/char/serial.c +10 -0
@@ -482,6 +482,16 @@ int __init serial_irq(int idx)return -1 ; } +const struct dt_irq __init *serial_dt_irq (int idx) +{ +if ( (idx >=0 ) && (idx <ARRAY_SIZE (com)) && + com[idx].driver && com[idx].driver->dt_irq_get ) +return com[idx].driver->dt_irq_get (&com[idx]); + +return NULL ; +} + +void serial_suspend (void ) {int i;
xen/include/xen/serial.h +5 -0
@@ -71,6 +71,8 @@ struct uart_driver {int (*getc)(struct serial_port *,char *);/* Get IRQ number for this port's serial line: returns -1 if none. */ int (*irq)(struct serial_port *); +/* Get IRQ device node for this port's serial line: returns NULL if none. */ +const struct dt_irq *(*dt_irq_get)(struct serial_port *); };/* 'Serial handles' are composed from the following fields. */
@@ -120,6 +122,9 @@ void serial_end_log_everything(int handle);/* Return irq number for specified serial port (identified by index). */ int serial_irq (int idx); +/* Return irq device node for specified serial port (identified by index). */ +const struct dt_irq *serial_dt_irq (int idx); +/* Serial suspend/resume. */ void serial_suspend (void );void serial_resume (void );
Signature · 1 line
Julien Grall
PATCH v2 20/33 xen/arm: Add generic UART to get the device in the device tree
In reply to Julien GrallThis generic UART will find the right UART via xen command line with dtuart=myserial.
"myserial" is the alias of the UART in the device tree. Xen will retrieve the information via the device tree and call the initialization function for this specific UART thanks to the device API.
Changes in v2:
- Use dtuart parameter instead of com1. The first one is more arm while the latter is more x86
--- xen/arch/arm/setup.c | 3 +- xen/drivers/char/Makefile | 1 + xen/drivers/char/arm-uart.c | 81 ++++++++++++++++++++++++++++++++++++++++++ xen/drivers/char/serial.c | 6 ++++ xen/include/asm-arm/config.h | 2 +- xen/include/xen/serial.h | 7 ++++ 6 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 xen/drivers/char/arm-uart.c
xen/arch/arm/setup.c +2 -1
@@ -435,8 +435,9 @@ void __init start_xen(unsigned long boot_phys_offset,#ifdef EARLY_UART_ADDRESS /* TODO Need to get device tree or command line for UART address */ pl011_init (0 ,FIXMAP_ADDR (FIXMAP_CONSOLE )); -console_init_preirq ();#endif +arm_uart_init (); +console_init_preirq ();/* FIXME: Do something smarter */ dt_switch_to_printk ();
xen/drivers/char/Makefile +1 -0
@@ -2,4 +2,5 @@ obj-y += console.o obj-$(HAS_NS16550) += ns16550.o obj-$(HAS_PL011) += pl011.o obj-$(HAS_EHCI) += ehci-dbgp.o +obj-$(CONFIG_ARM) += arm-uart.o obj-y += serial.o
xen/drivers/char/arm-uart.c new file +81 -0
81 lines not on this page · raw message
xen/drivers/char/serial.c +6 -0
@@ -271,6 +271,12 @@ int __init serial_parse_handle(char *conf) goto common; } +if ( !strncmp (conf,"dtuart" ,5 ) ) + { + handle =SERHND_COM1 ; + goto common; + } +if (strncmp (conf,"com" ,3 ) ) goto fail;
xen/include/asm-arm/config.h +1 -1
@@ -39,7 +39,7 @@#define CONFIG_VIDEO 1 -#define OPT_CONSOLE_STR "com1" +#define OPT_CONSOLE_STR "dtuart"#ifdef MAX_PHYS_CPUS #define NR_CPUS MAX_PHYS_CPUS
xen/include/xen/serial.h +7 -0
@@ -9,6 +9,7 @@#ifndef __XEN_SERIAL_H__#define __XEN_SERIAL_H__ +#include <xen/init.h> #include <xen/spinlock.h> struct cpu_user_regs ;
@@ -156,6 +157,12 @@ void ns16550_init(int index, struct ns16550_defaults *defaults);void ehci_dbgp_init (void );void pl011_init (int index,unsigned long register_base_address); +/* Default value for UART on ARM boards */ +struct serial_arm_defaults { +int index;/* Serial index */ +unsigned long register_base_address;/* Virtual base address */ +}; +void __init arm_uart_init (void );struct physdev_dbgp_op ;int dbgp_op (const struct physdev_dbgp_op *);
Signature · 1 line
Julien Grall
Re: [PATCH V2 20/33] xen/arm: Add generic UART to get the device in the device tree
Quoted 2 lines · Julien Grall
This generic UART will find the right UART via xen command line with dtuart=myserial.
I suppose there way to determine sensible default, since it differs on every platform?
Quoted 5 lines
"myserial" is the alias of the UART in the device tree. Xen will retrieve the information via the device tree and call the initialization function for this specific UART thanks to the device API.
Signed-off-by Julien Grall <[email protected]>
You need to CC code code maintainers when you change core code. Keir added.
Quoted 73 lines
Changes in v2:
- Use dtuart parameter instead of com1. The first one is more arm while the latter is more x86--- xen/arch/arm/setup.c | 3 +- xen/drivers/char/Makefile | 1 + xen/drivers/char/arm-uart.c | 81 ++++++++++++++++++++++++++++++++++++++++++ xen/drivers/char/serial.c | 6 ++++ xen/include/asm-arm/config.h | 2 +- xen/include/xen/serial.h | 7 ++++ 6 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 xen/drivers/char/arm-uart.cxen/arch/arm/setup.c +2
-1@@ -435,8 +435,9 @@ void __init start_xen(unsigned long boot_phys_offset,#ifdef EARLY_UART_ADDRESS /* TODO Need to get device tree or command line for UART address */ pl011_init (0 ,FIXMAP_ADDR (FIXMAP_CONSOLE )); -console_init_preirq ();#endif +arm_uart_init (); +console_init_preirq ();/* FIXME: Do something smarter */ dt_switch_to_printk ();xen/drivers/char/Makefile +1
-0@@ -2,4 +2,5 @@ obj-y += console.o obj-$(HAS_NS16550) += ns16550.o obj-$(HAS_PL011) += pl011.o obj-$(HAS_EHCI) += ehci-dbgp.o +obj-$(CONFIG_ARM) += arm-uart.o obj-y += serial.oxen/drivers/char/arm-uart.c new file +28
-0@@ -0,0 +1,81 @@ +/* +* xen/drivers/char/arm-uart.c +* +* Generic ARM uart retrieved via the device tree +* +* Julien Grall <[email protected]> +* Copyright (c) 2013 Linaro Limited. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/device.h> +#include <asm/early_printk.h> +#include <asm/types.h> +#include <xen/console.h> +#include <xen/device_tree.h> +#include <xen/mm.h> +#include <xen/serial.h> + +/*
xen/drivers/char/arm-uart.c line 38
Quoted 10 lines
xen/drivers/char/arm-uart.c new file +10
-0+* Configure UART port with a string: +* alias +* +* @alias: alias used in the device tree for the UART +* TODO: Implement config in each UART driver. +*/ +static char __initdata opt_dtuart[30 ] ="" ; +string_param ("dtuart" , opt_dtuart); + +void __init arm_uart_init (void )
This (and the file and struct serial_arm_defaults etc) could perhaps be better called dt_uart_init etc? There's nothing inherently ARM specific here.
Quoted 48 lines
xen/drivers/char/arm-uart.c new file +43
-0+{ +struct dt_device_node *dev; +int ret; +u64 addr, size; +struct serial_arm_defaults defaults; +const char *devalias = opt_dtuart; + +if ( !console_has ("dtuart" ) || !strcmp (opt_dtuart,"" ) ) + { +early_printk ("No console\n" ); +return ; + } + +early_printk ("Looking for UART console %s\n" , devalias); + dev =dt_find_node_by_alias (devalias); + +if ( !dev ) + { +early_printk ("Unable to find device \"%s\"\n" , devalias); +return ; + } + +/* TODO: Handle UART with 0 or multiple base address */ + ret =dt_device_get_address (dev,0 , &addr, &size); +if ( ret ) + { +early_printk ("Unable to retrieve the base address of the serial\n" ); +return ; + } + +clear_fixmap (FIXMAP_CONSOLE ); +set_fixmap (FIXMAP_CONSOLE , addr >>PAGE_SHIFT ,DEV_SHARED ); + + addr =FIXMAP_ADDR (FIXMAP_CONSOLE ) + (addr & (PAGE_SIZE -1 )); + + defaults.index =0 ; + defaults.register_base_address = addr; + + ret =device_init (dev,DEVICE_SERIAL , &defaults); + +if ( ret ) +early_printk ("Unable to initialize serial: %d\n" , ret); +}xen/drivers/char/serial.c +0
-0
xen/drivers/char/serial.c int __init serial_parse_handle(char *conf) · line 276
Quoted 6 lines
xen/drivers/char/serial.c +3
-0@@ -271,6 +271,12 @@ int __init serial_parse_handle(char *conf) goto common; } +if ( !strncmp (conf,"dtuart" ,5 ) ) + { + handle =SERHND_COM1 ;
Do you mean COM1 here? Or did you intend to add SERHND_DT?
Quoted 44 lines
xen/drivers/char/serial.c +3
-0+ goto common; + } +if (strncmp (conf,"com" ,3 ) ) goto fail;xen/include/asm-arm/config.h +1
-1@@ -39,7 +39,7 @@#define CONFIG_VIDEO 1 -#define OPT_CONSOLE_STR "com1" +#define OPT_CONSOLE_STR "dtuart"#ifdef MAX_PHYS_CPUS #define NR_CPUS MAX_PHYS_CPUSxen/include/xen/serial.h +7
-0@@ -9,6 +9,7 @@#ifndef __XEN_SERIAL_H__#define __XEN_SERIAL_H__ +#include <xen/init.h> #include <xen/spinlock.h> struct cpu_user_regs ;@@ -156,6 +157,12 @@ void ns16550_init(int index, struct ns16550_defaults *defaults);void ehci_dbgp_init (void );void pl011_init (int index,unsigned long register_base_address); +/* Default value for UART on ARM boards */ +struct serial_arm_defaults { +int index;/* Serial index */ +unsigned long register_base_address;/* Virtual base address */ +}; +void __init arm_uart_init (void );struct physdev_dbgp_op ;int dbgp_op (const struct physdev_dbgp_op *);
Re: [PATCH V2 20/33] xen/arm: Add generic UART to get the device in the device tree
Quoted 94 lines · Ian Campbell
Quoted 2 lines · Julien Grall
This generic UART will find the right UART via xen command line with dtuart=myserial.
I suppose there way to determine sensible default, since it differs on every platform?
Quoted 5 lines
"myserial" is the alias of the UART in the device tree. Xen will retrieve the information via the device tree and call the initialization function for this specific UART thanks to the device API.
Signed-off-by Julien Grall <[email protected]>You need to CC code code maintainers when you change core code. Keir added.
Quoted 79 lines
Changes in v2:
- Use dtuart parameter instead of com1. The first one is more arm while the latter is more x86--- xen/arch/arm/setup.c | 3 +- xen/drivers/char/Makefile | 1 + xen/drivers/char/arm-uart.c | 81 ++++++++++++++++++++++++++++++++++++++++++ xen/drivers/char/serial.c | 6 ++++ xen/include/asm-arm/config.h | 2 +- xen/include/xen/serial.h | 7 ++++ 6 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 xen/drivers/char/arm-uart.cxen/arch/arm/setup.c +2
-1@@ -435,8 +435,9 @@ void __init start_xen(unsigned long boot_phys_offset,#ifdef EARLY_UART_ADDRESS /* TODO Need to get device tree or command line for UART address */ pl011_init (0 ,FIXMAP_ADDR (FIXMAP_CONSOLE )); -console_init_preirq ();#endif +arm_uart_init (); +console_init_preirq ();/* FIXME: Do something smarter */ dt_switch_to_printk ();xen/drivers/char/Makefile +1
-0@@ -2,4 +2,5 @@ obj-y += console.o obj-$(HAS_NS16550) += ns16550.o obj-$(HAS_PL011) += pl011.o obj-$(HAS_EHCI) += ehci-dbgp.o +obj-$(CONFIG_ARM) += arm-uart.o obj-y += serial.oxen/drivers/char/arm-uart.c new file +34
-0@@ -0,0 +1,81 @@ +/* +* xen/drivers/char/arm-uart.c +* +* Generic ARM uart retrieved via the device tree +* +* Julien Grall <[email protected]> +* Copyright (c) 2013 Linaro Limited. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/device.h> +#include <asm/early_printk.h> +#include <asm/types.h> +#include <xen/console.h> +#include <xen/device_tree.h> +#include <xen/mm.h> +#include <xen/serial.h> + +/* +* Configure UART port with a string: +* alias +* +* @alias: alias used in the device tree for the UART +* TODO: Implement config in each UART driver. +*/
Quoted 8 lines
xen/drivers/char/arm-uart.c line 38
Quoted 4 lines
xen/drivers/char/arm-uart.c new file +4
-0+static char __initdata opt_dtuart[30 ] ="" ; +string_param ("dtuart" , opt_dtuart); + +void __init arm_uart_init (void )This (and the file and struct
serial_arm_defaultsetc) could perhaps be better calleddt_uart_initetc? There's nothing inherently ARM specific here.
The FIXMAP_CONSOLE is ARM specific it can not works on x86. I'm wondering if it's usefull to move FIXMAP_CONSOLE on each UART driver.
Quoted 51 lines
Quoted 51 lines
xen/drivers/char/arm-uart.c new file +43
-0+{ +struct dt_device_node *dev; +int ret; +u64 addr, size; +struct serial_arm_defaults defaults; +const char *devalias = opt_dtuart; + +if ( !console_has ("dtuart" ) || !strcmp (opt_dtuart,"" ) ) + { +early_printk ("No console\n" ); +return ; + } + +early_printk ("Looking for UART console %s\n" , devalias); + dev =dt_find_node_by_alias (devalias); + +if ( !dev ) + { +early_printk ("Unable to find device \"%s\"\n" , devalias); +return ; + } + +/* TODO: Handle UART with 0 or multiple base address */ + ret =dt_device_get_address (dev,0 , &addr, &size); +if ( ret ) + { +early_printk ("Unable to retrieve the base address of the serial\n" ); +return ; + } + +clear_fixmap (FIXMAP_CONSOLE ); +set_fixmap (FIXMAP_CONSOLE , addr >>PAGE_SHIFT ,DEV_SHARED ); + + addr =FIXMAP_ADDR (FIXMAP_CONSOLE ) + (addr & (PAGE_SIZE -1 )); + + defaults.index =0 ; + defaults.register_base_address = addr; + + ret =device_init (dev,DEVICE_SERIAL , &defaults); + +if ( ret ) +early_printk ("Unable to initialize serial: %d\n" , ret); +}xen/drivers/char/serial.c +0
-0@@ -271,6 +271,12 @@ int __init serial_parse_handle(char *conf) goto common; }
Quoted 5 lines
xen/drivers/char/serial.c int __init serial_parse_handle(char *conf) · line 276
Quoted 3 lines
xen/drivers/char/serial.c +3
-0+if ( !strncmp (conf,"dtuart" ,5 ) ) + { + handle =SERHND_COM1 ;Do you mean COM1 here? Or did you intend to add
SERHND_DT?
I mean COM1, I use the first serial slot for dtuart. I don't really see why we need to extend the number of serial slot.
Signature · 1 line
Julien
Re: [PATCH V2 20/33] xen/arm: Add generic UART to get the device in the device tree
Quoted 105 lines · Julien Grall
Quoted 94 lines · Ian Campbell
Quoted 2 lines · Julien Grall
This generic UART will find the right UART via xen command line with dtuart=myserial.
I suppose there way to determine sensible default, since it differs on every platform?
Quoted 5 lines
"myserial" is the alias of the UART in the device tree. Xen will retrieve the information via the device tree and call the initialization function for this specific UART thanks to the device API.
Signed-off-by Julien Grall <[email protected]>You need to CC code code maintainers when you change core code. Keir added.
Quoted 79 lines
Changes in v2:
- Use dtuart parameter instead of com1. The first one is more arm while the latter is more x86--- xen/arch/arm/setup.c | 3 +- xen/drivers/char/Makefile | 1 + xen/drivers/char/arm-uart.c | 81 ++++++++++++++++++++++++++++++++++++++++++ xen/drivers/char/serial.c | 6 ++++ xen/include/asm-arm/config.h | 2 +- xen/include/xen/serial.h | 7 ++++ 6 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 xen/drivers/char/arm-uart.cxen/arch/arm/setup.c +2
-1@@ -435,8 +435,9 @@ void __init start_xen(unsigned long boot_phys_offset,#ifdef EARLY_UART_ADDRESS /* TODO Need to get device tree or command line for UART address */ pl011_init (0 ,FIXMAP_ADDR (FIXMAP_CONSOLE )); -console_init_preirq ();#endif +arm_uart_init (); +console_init_preirq ();/* FIXME: Do something smarter */ dt_switch_to_printk ();xen/drivers/char/Makefile +1
-0@@ -2,4 +2,5 @@ obj-y += console.o obj-$(HAS_NS16550) += ns16550.o obj-$(HAS_PL011) += pl011.o obj-$(HAS_EHCI) += ehci-dbgp.o +obj-$(CONFIG_ARM) += arm-uart.o obj-y += serial.oxen/drivers/char/arm-uart.c new file +34
-0@@ -0,0 +1,81 @@ +/* +* xen/drivers/char/arm-uart.c +* +* Generic ARM uart retrieved via the device tree +* +* Julien Grall <[email protected]> +* Copyright (c) 2013 Linaro Limited. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/device.h> +#include <asm/early_printk.h> +#include <asm/types.h> +#include <xen/console.h> +#include <xen/device_tree.h> +#include <xen/mm.h> +#include <xen/serial.h> + +/* +* Configure UART port with a string: +* alias +* +* @alias: alias used in the device tree for the UART +* TODO: Implement config in each UART driver. +*/ Quoted 8 lines
xen/drivers/char/arm-uart.c line 38
Quoted 4 lines
xen/drivers/char/arm-uart.c new file +4
-0+static char __initdata opt_dtuart[30 ] ="" ; +string_param ("dtuart" , opt_dtuart); + +void __init arm_uart_init (void )This (and the file and struct
serial_arm_defaultsetc) could perhaps be better calleddt_uart_initetc? There's nothing inherently ARM specific here.
Quoted 2 lines
The
FIXMAP_CONSOLEis ARM specific it can not works on x86. I'm wondering if it's usefull to moveFIXMAP_CONSOLEon each UART driver.
I think I came to the same conclusion later in the series too, or more likely the uart drivers should use ioremap.
Quoted 8 lines
Quoted 5 lines
xen/drivers/char/arm-uart.c line 41
Quoted 3 lines
xen/drivers/char/arm-uart.c new file +3
-0+if ( !strncmp (conf,"dtuart" ,5 ) ) + { + handle =SERHND_COM1 ;Do you mean COM1 here? Or did you intend to add
SERHND_DT?I mean COM1, I use the first serial slot for dtuart. I don't really see why we need to extend the number of serial slot.
I just dislike using things with one name for another purpose.
Ultimately this bit is up to Keir though.
Ian.
PATCH v2 21/33 xen/arm: Use device tree API in pl011 UART driver
In reply to Julien GrallAllow UART driver to retrieve all its information in the device tree. It's possible to choose the pl011 driver via the Xen command line.
Changes in v2:
- Rework TODO
- Use the new function setup_dt_irq
--- xen/arch/arm/gic.c | 4 --- xen/arch/arm/setup.c | 4 --- xen/drivers/char/pl011.c | 64 ++++++++++++++++++++++++++++++++++++---------- xen/include/xen/serial.h | 1 - 4 files changed, 50 insertions(+), 23 deletions(-)
xen/arch/arm/gic.c +0 -4
@@ -501,10 +501,6 @@ void gic_route_spis(void)int seridx;const struct dt_irq *irq; -/* XXX should get these from DT */ -/* UART */ -gic_route_irq (37 ,0 ,1u <<smp_processor_id (),0xa0 ); -for ( seridx =0 ; seridx <=SERHND_IDX ; seridx++ ) {if ( (irq =serial_dt_irq (seridx)) ==NULL )
xen/arch/arm/setup.c +0 -4
@@ -432,10 +432,6 @@ void __init start_xen(unsigned long boot_phys_offset,dt_unflatten_host_device_tree (); dt_irq_xlate = gic_irq_xlate; -#ifdef EARLY_UART_ADDRESS -/* TODO Need to get device tree or command line for UART address */ -pl011_init (0 ,FIXMAP_ADDR (FIXMAP_CONSOLE )); -#endif arm_uart_init ();console_init_preirq ();
xen/drivers/char/pl011.c +50 -14
111 lines not on this page · raw message
xen/include/xen/serial.h +0 -1
@@ -156,7 +156,6 @@ struct ns16550_defaults {void ns16550_init (int index,struct ns16550_defaults *defaults);void ehci_dbgp_init (void ); -void pl011_init (int index,unsigned long register_base_address);/* Default value for UART on ARM boards */ struct serial_arm_defaults {int index;/* Serial index */
Signature · 1 line
Julien Grall
Re: [PATCH V2 21/33] xen/arm: Use device tree API in pl011 UART driver
Quoted 26 lines · Julien Grall
xen/drivers/char/pl011.c +9
-7@@ -227,32 +239,56 @@ static struct uart_driver __read_mostly pl011_driver = { .tx_ready = pl011_tx_ready, .putc = pl011_putc, .getc = pl011_getc, - .irq = pl011_irq + .irq = pl011_irq, + .dt_irq_get = pl011_dt_irq, }; -/* TODO: Parse UART config from device-tree or command-line */ - -void __init pl011_init (int index,unsigned long register_base_address) +/* TODO: Parse UART config from the command line */ +static int __init pl011_uart_init (struct dt_device_node *dev, +const void *data) { +const struct serial_arm_defaults *defaults = data;struct pl011 *uart; +int res; -if ( (index <0 ) || (index >1 ) ) -return ; +if ( (defaults->index <0 ) || (defaults->index >1 ) ) +return -EINVAL ; - uart = &pl011_com[index];
xen/drivers/char/pl011.c static struct uart_driver __read_mostly pl011_driver = { · line 264
Quoted 10 lines
xen/drivers/char/pl011.c +2
-2+ uart = &pl011_com[defaults->index]; uart->clock_hz =0x16e3600 ; uart->baud =38400 ; uart->data_bits =8 ; uart->parity =PARITY_NONE ; uart->stop_bits =1 ; - uart->irq =37 ;/* TODO Need to find this from devicetree */ - uart->regs = (uint32_t *) register_base_address; + uart->regs = (uint32_t *) defaults->register_base_address;
Should this not come from struct dt_device_node?
Perhaps the driver needs to be instantiating its own FIXMAP mapping instead of doing it in common code? In fact can we not get rid of the fixmap for the runtime (not early) console and use the ioremap stuff which Stefano just enabled with his vmap patches, or the early_ioremap stuff if necessary.
That does then call into question the whole serial_arm_defaults thing. Perhaps index should just be the order in which they are registered (and at the moment it is effectively hardcoded to 0 anyway)
Quoted 5 lines
xen/drivers/char/pl011.c +5
-0+ + res =dt_device_get_irq (dev,0 , &uart->irq); +if ( res ) + { +early_printk ("pl011: Unable to retrieve the IRQ\n" );
xen/drivers/char/pl011.c static struct uart_driver __read_mostly pl011_driver = { · line 279
Quoted 10 lines
xen/drivers/char/pl011.c +6
-0+return res; + }/* Register with generic serial driver. */ serial_register_uart (uart - pl011_com, &pl011_driver, uart); + +dt_device_set_used_by (dev,DT_USED_BY_XEN ); + +return 0 ; }
Ian.
Re: [PATCH V2 21/33] xen/arm: Use device tree API in pl011 UART driver
Quoted 40 lines · Ian Campbell
Quoted 26 lines · Julien Grall
xen/drivers/char/pl011.c +9
-7@@ -227,32 +239,56 @@ static struct uart_driver __read_mostly pl011_driver = { .tx_ready = pl011_tx_ready, .putc = pl011_putc, .getc = pl011_getc, - .irq = pl011_irq + .irq = pl011_irq, + .dt_irq_get = pl011_dt_irq, }; -/* TODO: Parse UART config from device-tree or command-line */ - -void __init pl011_init (int index,unsigned long register_base_address) +/* TODO: Parse UART config from the command line */ +static int __init pl011_uart_init (struct dt_device_node *dev, +const void *data) { +const struct serial_arm_defaults *defaults = data;struct pl011 *uart; +int res; -if ( (index <0 ) || (index >1 ) ) -return ; +if ( (defaults->index <0 ) || (defaults->index >1 ) ) +return -EINVAL ; - uart = &pl011_com[index];xen/drivers/char/pl011.c static struct uart_driver __read_mostly pl011_driver = { · line 264
Quoted 10 lines
xen/drivers/char/pl011.c +2
-2+ uart = &pl011_com[defaults->index]; uart->clock_hz =0x16e3600 ; uart->baud =38400 ; uart->data_bits =8 ; uart->parity =PARITY_NONE ; uart->stop_bits =1 ; - uart->irq =37 ;/* TODO Need to find this from devicetree */ - uart->regs = (uint32_t *) register_base_address; + uart->regs = (uint32_t *) defaults->register_base_address;Should this not come from struct
dt_device_node?
Quoted 5 lines
Perhaps the driver needs to be instantiating its own FIXMAP mapping instead of doing it in common code? In fact can we not get rid of the fixmap for the runtime (not early) console and use the ioremap stuff which Stefano just enabled with his vmap patches, or the
early_ioremapstuff if necessary.
Right. I will use ioremap in the next patch series.
Quoted 3 lines
That does then call into question the whole
serial_arm_defaultsthing. Perhaps index should just be the order in which they are registered (and at the moment it is effectively hardcoded to 0 anyway)
I'm thinking about using serial_arm_defaults for baud rate,... For the moment the different values are hardcoded.
{arm,dt}_init_uart will parse the dtuart parameters on the command line and then fill serial_arm_defaults.
Signature · 1 line
Julien
Re: [PATCH V2 21/33] xen/arm: Use device tree API in pl011 UART driver
Quoted 10 lines · Julien Grall
Quoted 3 lines
That does then call into question the whole
serial_arm_defaultsthing. Perhaps index should just be the order in which they are registered (and at the moment it is effectively hardcoded to 0 anyway)I'm thinking about using
serial_arm_defaultsfor baud rate,... For the moment the different values are hardcoded.{arm,dt}_init_uart will parse the dtuart parameters on the command line and then fill
serial_arm_defaults.
Perhaps instead of &serial_arm_defaults you should pass a char * pointer to opt_dtuart? This would allow for per-device settings and is consistent with the ns16550 driver.
Ian.
Re: [PATCH V2 21/33] xen/arm: Use device tree API in pl011 UART driver
Quoted 9 lines · Ian Campbell
Quoted 8 lines · Julien Grall
Quoted 3 lines
That does then call into question the whole
serial_arm_defaultsthing. Perhaps index should just be the order in which they are registered (and at the moment it is effectively hardcoded to 0 anyway)I'm thinking about using
serial_arm_defaultsfor baud rate,... For the moment the different values are hardcoded.
Quoted 6 lines
Quoted 2 lines
{arm,dt}_init_uart will parse the dtuart parameters on the command line and then fill
serial_arm_defaults.Perhaps instead of
&serial_arm_defaultsyou should pass a char * pointer toopt_dtuart? This would allow for per-device settings and is consistent with the ns16550 driver.
Ok. I will modify it in the next patch series.
Signature · 1 line
Julien
PATCH v2 22/33 xen/arm: Use the device tree to map the address range and IRQ to dom0
In reply to Julien Grall- gic_route_irq_to_guest takes a dt_irq instead of an IRQ number
- remove hardcoded address/IRQ
Changes in v2:
- Use the new function dt_irq_is_level_trigger
- Disable DEBUG_DT by default
- Rename parse_device_tree to map_device_from_device_tree
--- xen/arch/arm/domain_build.c | 144 +++++++++++++++++++++++++++++++++++++------ xen/arch/arm/gic.c | 12 ++-- xen/include/asm-arm/gic.h | 3 +- 3 files changed, 136 insertions(+), 23 deletions(-)
xen/arch/arm/domain_build.c +126 -18
@@ -14,6 +14,7 @@#include <asm/setup.h> #include <asm/gic.h> +#include <xen/irq.h> #include "kernel.h" static unsigned int __initdata opt_dom0_max_vcpus;
@@ -30,6 +31,14 @@ static void __init parse_dom0_mem(const char *s) }custom_param ("dom0_mem" , parse_dom0_mem); +//#define DEBUG_DT + +#ifdef DEBUG_DT +# define DPRINT(fmt, args...) printk(XENLOG_DEBUG fmt, ##args) +#else +# define DPRINT(fmt, args...) do {} while ( 0 ) +#endif +/* * Amount of extra space required to dom0's device tree. No new nodes * are added (yet) but one terminating reserve map entry (16 bytes) is
@@ -303,6 +312,122 @@ static int write_nodes(struct domain *d, struct kernel_info *kinfo,return 0 ; } +/* Map the device in the domain */ +static int map_device (struct domain *d,const struct dt_device_node *dev) +{ +unsigned int nirq; +unsigned int naddr; +unsigned int i; +int res; +struct dt_irq irq; +struct dt_raw_irq rirq; +u64 addr, size; + + nirq =dt_number_of_irq (dev); + naddr =dt_number_of_address (dev); + +DPRINT ("%s nirq = %d naddr = %u\n" ,dt_node_full_name (dev), nirq, naddr); + +/* Map IRQs */ +for ( i =0 ; i < nirq; i++ ) + { + res =dt_device_get_raw_irq (dev, i, &rirq); +if ( res ) + { +printk (XENLOG_ERR "Unable to retrieve irq %u for %s\n" , + i,dt_node_full_name (dev)); +return res; + } + +/** +* Don't map IRQ that have no physical meaning +* ie: IRQ whose controller is not the GIC +*/ +if ( rirq.controller != dt_interrupt_controller ) + { +DPRINT ("irq %u skipped it controller (%s)\n" , + i,dt_node_full_name (rirq.controller)); +continue ; + } + + res =dt_irq_translate (&rirq, &irq); +if ( res ) + { +printk (XENLOG_ERR "Unable to translate irq %u for %s\n" , + i,dt_node_full_name (dev)); +return res; + } + +DPRINT ("irq %u = %u type = %#x\n" , i, irq.irq, irq.type); +/* Don't check return because the IRQ can be use by multiple device */ +gic_route_irq_to_guest (d, &irq,dt_node_name (dev)); + } + +/* Map the address ranges */ +for ( i =0 ; i < naddr; i++ ) + { + res =dt_device_get_address (dev, i, &addr, &size); +if ( res ) + { +printk (XENLOG_ERR "Unable to retrieve address %u for %s\n" , + i,dt_node_full_name (dev)); +return res; + } + +DPRINT ("addr %u = %#" PRIx64" - %#" PRIx64"\n" , i, addr, addr + size -1 ); + + res =map_mmio_regions (d, addr &PAGE_MASK , +PAGE_ALIGN (addr + size) -1 , + addr &PAGE_MASK ); +if ( res ) + { +printk (XENLOG_ERR "Unable to map %#" PRIx64" - %#" PRIx64" in dom0\n" , + addr &PAGE_MASK ,PAGE_ALIGN (addr + size) -1 ); +return res; + } + } + +return 0 ; +} + +static int handle_node (struct domain *d,const struct dt_device_node *np) +{ +const struct dt_device_node *child; +int res; + +DPRINT ("handle %s\n" ,dt_node_full_name (np)); + +/* Skip theses nodes and the sub-nodes */ +if (dt_device_is_compatible (np,"xen,xen" ) || +dt_device_type_is_equal (np,"memory" ) || + !strcmp ("/chosen" ,dt_node_full_name (np)) ) +return 0 ; + +if (dt_device_used_by (np) !=DT_USED_BY_XEN ) + { + res =map_device (d, np); + +if ( res ) +return res; + } + +for ( child = np->child; child !=NULL ; child = child->sibling ) + { + res =handle_node (d, child); +if ( res ) +return res; + } + +return 0 ; +} + +static int map_device_from_device_tree (struct domain *d) +{ +ASSERT (dt_host && (dt_host->sibling ==NULL )); + +return handle_node (d, dt_host); +} +static int prepare_dtb (struct domain *d,struct kernel_info *kinfo) {void *fdt;
@@ -385,24 +510,7 @@ int construct_dom0(struct domain *d)if ( rc <0 )return rc; -printk ("Map CS2 MMIO regions 1:1 in the P2M %#llx->%#llx\n" ,0x18000000ULL ,0x1BFFFFFFULL ); -map_mmio_regions (d,0x18000000 ,0x1BFFFFFF ,0x18000000 ); -printk ("Map CS3 MMIO regions 1:1 in the P2M %#llx->%#llx\n" ,0x1C000000ULL ,0x1FFFFFFFULL ); -map_mmio_regions (d,0x1C000000 ,0x1FFFFFFF ,0x1C000000 ); - -printk ("Routing peripheral interrupts to guest\n" ); -/* TODO Get from device tree */ -gic_route_irq_to_guest (d,34 ,"timer0" ); -/*gic_route_irq_to_guest(d, 37, "uart0"); -- XXX used by Xen*/ -gic_route_irq_to_guest (d,38 ,"uart1" ); -gic_route_irq_to_guest (d,39 ,"uart2" ); -gic_route_irq_to_guest (d,40 ,"uart3" ); -gic_route_irq_to_guest (d,41 ,"mmc0-1" ); -gic_route_irq_to_guest (d,42 ,"mmc0-2" ); -gic_route_irq_to_guest (d,44 ,"keyboard" ); -gic_route_irq_to_guest (d,45 ,"mouse" ); -gic_route_irq_to_guest (d,46 ,"lcd" ); -gic_route_irq_to_guest (d,47 ,"eth" ); +map_device_from_device_tree (d);/* The following loads use the domain's p2m */ p2m_load_VTTBR (d);
xen/arch/arm/gic.c +8 -4
@@ -692,13 +692,14 @@ void gic_inject(void)gic_inject_irq_start (); } -int gic_route_irq_to_guest (struct domain *d,unsigned int irq, +int gic_route_irq_to_guest (struct domain *d,const struct dt_irq *irq,const char * devname) {struct irqaction *action; -struct irq_desc *desc =irq_to_desc (irq); +struct irq_desc *desc =irq_to_desc (irq->irq);unsigned long flags;int retval; +bool_t level; action = xmalloc(struct irqaction);if (!action)
@@ -706,6 +707,7 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int irq, action->dev_id = d; action->name = devname; + action->free_on_release =1 ;spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock);
@@ -713,9 +715,11 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int irq, desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ; -gic_set_irq_properties (irq,1 ,1u <<smp_processor_id (),0xa0 ); + level =dt_irq_is_level_trigger (irq); + +gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 ); - retval =__setup_irq (desc, irq, action); + retval =__setup_irq (desc, irq->irq, action);if (retval) {xfree (action); goto out;
xen/include/asm-arm/gic.h +2 -1
@@ -157,7 +157,8 @@ extern int gic_events_need_delivery(void);extern void __cpuinit init_maintenance_interrupt (void );extern void gic_set_guest_irq (struct vcpu *v,unsigned int irq,unsigned int state,unsigned int priority); -extern int gic_route_irq_to_guest (struct domain *d,unsigned int irq, +extern int gic_route_irq_to_guest (struct domain *d, +const struct dt_irq *irq,const char * devname);/* Accept an interrupt from the GIC and dispatch its handler */
Signature · 1 line
Julien Grall
Re: [PATCH V2 22/33] xen/arm: Use the device tree to map the address range and IRQ to dom0
Quoted 9 lines · Julien Grall
-
gic_route_irq_to_guesttakes adt_irqinstead of an IRQ number
- remove hardcoded address/IRQSigned-off-by Julien Grall <[email protected]>Changes in v2:
- Use the new functiondt_irq_is_level_trigger
- DisableDEBUG_DTby default
- Renameparse_device_treetomap_device_from_device_tree
Should be map_devices_...
Quoted 1 line
+ /**
Javadoc!
xen/arch/arm/domain_build.c static int write_nodes(struct domain *d, struct kernel_info *kinfo, · line 348
Quoted 6 lines
xen/arch/arm/domain_build.c +6
-0+* Don't map IRQ that have no physical meaning +* ie: IRQ whose controller is not the GIC +*/ +if ( rirq.controller != dt_interrupt_controller ) + { + DPRINT("irq %u skipped it controller (%s)\n",
you might mean "skipped its controller" ? But I think a clearer message would be "irq %u not connected to primary controller" or something.
xen/arch/arm/domain_build.c static int write_nodes(struct domain *d, struct kernel_info *kinfo, · line 361
Quoted 13 lines
xen/arch/arm/domain_build.c +13
-0+ i, dt_node_full_name(rirq.controller)); +continue ; + } + + res =dt_irq_translate (&rirq, &irq); +if ( res ) + { +printk (XENLOG_ERR "Unable to translate irq %u for %s\n" , + i,dt_node_full_name (dev)); +return res; + } + +DPRINT ("irq %u = %u type = %#x\n" , i, irq.irq, irq.type);
The # format specifier is required by $STANDARD to not be all that sensible and/or consistent when when the value is 0, i.e.
printf("%#x\n", 0) => "0"
printf("%#x\n", 1) => "0x1"
Worse if you use widths then:
printf("%#02x\n", 0); => "00"
printf("%#02x\n", 1); => "0x1"
printf("%#04x\n", 0); => "0000"
printf("%#04x\n", 1); => "0x01"For this reason we tend to avoid # and just use "0x%...", assuming irq==0 is a possibility, and likewise below addr==0 it's probably better to avoid #.
Quoted 1 line
+ /* Don't check return because the IRQ can be use by multiple device */
"used by"
Quoted 30 lines
xen/arch/arm/gic.c +4
-2@@ -692,13 +692,14 @@ void gic_inject(void)gic_inject_irq_start (); } -int gic_route_irq_to_guest (struct domain *d,unsigned int irq, +int gic_route_irq_to_guest (struct domain *d,const struct dt_irq *irq,const char * devname) {struct irqaction *action; -struct irq_desc *desc =irq_to_desc (irq); +struct irq_desc *desc =irq_to_desc (irq->irq);unsigned long flags;int retval; +bool_t level; action = xmalloc(struct irqaction);if (!action)@@ -706,6 +707,7 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int irq, action->dev_id = d; action->name = devname; + action->free_on_release =1 ;spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock);
xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d, unsigned int irq, · line 720
Quoted 7 lines
xen/arch/arm/gic.c +3
-1@@ -713,9 +715,11 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int irq, desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ; -gic_set_irq_properties (irq,1 ,1u <<smp_processor_id (),0xa0 ); + level =dt_irq_is_level_trigger (irq); + +gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 );
By the end of this series are all callers going through the above dance? git_set_irq_properties could take a dt_irq?
Ian.
Re: [PATCH V2 22/33] xen/arm: Use the device tree to map the address range and IRQ to dom0
Quoted 4 lines · Ian Campbell
Quoted 3 lines · Julien Grall
-
gic_route_irq_to_guesttakes adt_irqinstead of an IRQ number
- remove hardcoded address/IRQ
Quoted 8 lines
Quoted 6 lines
Signed-off-by Julien Grall <[email protected]>Changes in v2:
- Use the new functiondt_irq_is_level_trigger
- DisableDEBUG_DTby default
- Renameparse_device_treetomap_device_from_device_treeShould be
map_devices_...
Will be fix on the next patch series.
Quoted 38 lines
Quoted 1 line
+ /**
Javadoc!
xen/arch/arm/domain_build.c static int write_nodes(struct domain *d, struct kernel_info *kinfo, · line 348
Quoted 6 lines
xen/arch/arm/domain_build.c +6
-0+* Don't map IRQ that have no physical meaning +* ie: IRQ whose controller is not the GIC +*/ +if ( rirq.controller != dt_interrupt_controller ) + { + DPRINT("irq %u skipped it controller (%s)\n",you might mean "skipped its controller" ? But I think a clearer message would be "irq %u not connected to primary controller" or something.
xen/arch/arm/domain_build.c static int write_nodes(struct domain *d, struct kernel_info *kinfo, · line 361
Quoted 13 lines
xen/arch/arm/domain_build.c +13
-0+ i, dt_node_full_name(rirq.controller)); +continue ; + } + + res =dt_irq_translate (&rirq, &irq); +if ( res ) + { +printk (XENLOG_ERR "Unable to translate irq %u for %s\n" , + i,dt_node_full_name (dev)); +return res; + } + +DPRINT ("irq %u = %u type = %#x\n" , i, irq.irq, irq.type);The # format specifier is required by $STANDARD to not be all that sensible and/or consistent when when the value is 0, i.e.
printf("%#x\n", 0) => "0" printf("%#x\n", 1) => "0x1" Worse if you use widths then: printf("%#02x\n", 0); => "00" printf("%#02x\n", 1); => "0x1" printf("%#04x\n", 0); => "0000" printf("%#04x\n", 1); => "0x01"
Quoted 3 lines
For this reason we tend to avoid # and just use "0x%...", assuming irq==0 is a possibility, and likewise below addr==0 it's probably better to avoid #.
Thanks for this hint. I will replace all my %#x by 0x%x.
Quoted 37 lines
Quoted 1 line
+ /* Don't check return because the IRQ can be use by multiple device */
"used by"
Quoted 33 lines
xen/arch/arm/gic.c +4
-2@@ -692,13 +692,14 @@ void gic_inject(void)gic_inject_irq_start (); } -int gic_route_irq_to_guest (struct domain *d,unsigned int irq, +int gic_route_irq_to_guest (struct domain *d,const struct dt_irq *irq,const char * devname) {struct irqaction *action; -struct irq_desc *desc =irq_to_desc (irq); +struct irq_desc *desc =irq_to_desc (irq->irq);unsigned long flags;int retval; +bool_t level; action = xmalloc(struct irqaction);if (!action)@@ -706,6 +707,7 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int irq, action->dev_id = d; action->name = devname; + action->free_on_release =1 ;spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock);@@ -713,9 +715,11 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int irq, desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ;
Quoted 7 lines
xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d, unsigned int irq, · line 720
Quoted 4 lines
xen/arch/arm/gic.c +3
-1-gic_set_irq_properties (irq,1 ,1u <<smp_processor_id (),0xa0 ); + level =dt_irq_is_level_trigger (irq); + +gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 );By the end of this series are all callers going through the above dance?
git_set_irq_propertiescould take adt_irq?
No. I can add patch to use a dt_irq.
Signature · 1 line
Julien
PATCH v2 23/33 xen/arm: Allow Xen to run on multiple platform without recompilation
In reply to Julien GrallXen can include various platform support (ie: exynos5, versatile express...) and choose during boot time a set of callbacks for the current board. These callbacks will be called in places where each board can have specific code. For the moment the callbacks are:
- platform_init: additional initialization for the platform
- platform_init_time: some platform (ie: Exynos 5) needs to initialize the timer with an uncommon way
- platform_specific_mapping: add mapping to dom0 which are not specified in the device tree
- platform_reset: reset the platform
- platform_poweroff: poweroff the platform
- platform_quirks: list of quirks for a specific board.
Changes in v2:
- add platform_poweroff
- add platform_quirks
--- xen/arch/arm/Makefile | 1 + xen/arch/arm/domain_build.c | 4 ++ xen/arch/arm/platform.c | 137 ++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 3 + xen/arch/arm/shutdown.c | 2 + xen/arch/arm/time.c | 6 ++ xen/arch/arm/xen.lds.S | 7 ++ xen/include/asm-arm/platform.h | 81 ++++++++++++++++++++++++ 8 files changed, 241 insertions(+) create mode 100644 xen/arch/arm/platform.c create mode 100644 xen/include/asm-arm/platform.h
xen/arch/arm/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-y += p2m.o obj-y += percpu.o obj-y += guestcopy.o obj-y += physdev.o +obj-y += platform.o obj-y += setup.o obj-y += time.o obj-y += smpboot.o
xen/arch/arm/domain_build.c +4 -0
@@ -12,6 +12,7 @@#include <xen/libfdt/libfdt.h> #include <xen/guest_access.h> #include <asm/setup.h> +#include <asm/platform.h> #include <asm/gic.h> #include <xen/irq.h>
@@ -511,6 +512,9 @@ int construct_dom0(struct domain *d)return rc;map_device_from_device_tree (d); + rc =platform_specific_mapping (d); +if ( rc <0 ) +return rc;/* The following loads use the domain's p2m */ p2m_load_VTTBR (d);
xen/arch/arm/platform.c new file +137 -0
137 lines not on this page · raw message
xen/arch/arm/setup.c +3 -0
@@ -42,6 +42,7 @@#include <asm/early_printk.h> #include <asm/gic.h> #include <asm/cpufeature.h> +#include <asm/platform.h> struct cpuinfo_arm __read_mostly boot_cpu_data;
@@ -440,6 +441,8 @@ void __init start_xen(unsigned long boot_phys_offset,processor_id (); +platform_init (); +init_xen_time ();gic_init ();
xen/arch/arm/shutdown.c +2 -0
@@ -5,6 +5,7 @@#include <xen/lib.h> #include <xen/mm.h> #include <xen/smp.h> +#include <asm/platform.h> static void raw_machine_reset (void ) {
@@ -21,6 +22,7 @@ static void raw_machine_reset(void)dsb ();isb ();clear_fixmap (FIXMAP_MISC );#endif +platform_reset (); }static void halt_this_cpu (void *arg)
xen/arch/arm/time.c +6 -0
@@ -33,6 +33,7 @@#include <asm/time.h> #include <asm/gic.h> #include <asm/cpufeature.h> +#include <asm/platform.h> /* * Unfortunately the hypervisor timer interrupt appears to be buggy in
@@ -130,6 +131,11 @@ int __init init_xen_time(void)panic ("CPU does not support the Generic Timer v1 interface.\n" ); cpu_khz =READ_SYSREG32 (CNTFRQ_EL0 ) /1000 ; + + res =platform_init_time (); +if ( res ) +return res; + boot_count =READ_SYSREG64 (CNTPCT_EL0 );printk ("Using generic timer at %lu KHz\n" , cpu_khz);
xen/arch/arm/xen.lds.S +7 -0
@@ -77,6 +77,13 @@ SECTIONS #endif . = ALIGN(8); + .arch.info : { + _splatform = .; + *(.arch.info) + _eplatform = .; + } :text + + . = ALIGN(8); .dev.info : { _sdevice = .; *(.dev.info)
xen/include/asm-arm/platform.h new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
Julien Grall
Re: [PATCH V2 23/33] xen/arm: Allow Xen to run on multiple platform without recompilation
Quoted 13 lines · Julien Grall
xen/arch/arm/time.c +1
-0@@ -33,6 +33,7 @@#include <asm/time.h> #include <asm/gic.h> #include <asm/cpufeature.h> +#include <asm/platform.h> /* * Unfortunately the hypervisor timer interrupt appears to be buggy in
xen/arch/arm/time.c int __init init_xen_time(void) · line 133
Quoted 3 lines
xen/arch/arm/time.c +0
-0@@ -130,6 +131,11 @@ int __init init_xen_time(void)panic ("CPU does not support the Generic Timer v1 interface.\n" ); cpu_khz =READ_SYSREG32 (CNTFRQ_EL0 ) /1000 ;
Might be better to read this after platform_init_time, in case p_i_t does something "magic" on this platform?
xen/arch/arm/time.c int __init init_xen_time(void)
Quoted 11 lines
xen/arch/arm/time.c +11
-0+/* Helper to read/write a register */ +static inline uint32_t platform_read_register (uint32_t addr) +{ +volatile const uint32_t *reg; +uint32_t value; + +set_fixmap (FIXMAP_MISC , addr >>PAGE_SHIFT ,DEV_SHARED ); + reg = (uint32_t *)(FIXMAP_ADDR (FIXMAP_MISC ) + (addr & ~PAGE_MASK )); + value = *reg; +dsb ();isb (); +clear_fixmap (FIXMAP_MISC );
I don't think the fixmap is per-PCPU so you probably want some locking here.
FIXMAP_MISC is a bit of an awful thing, but this isn't especially new, so OK.
Quoted 4 lines
xen/arch/arm/time.c +4
-0+ +return value; +} +
xen/arch/arm/time.c
Quoted 10 lines
xen/arch/arm/time.c +10
-0+static inline void platform_write_register (uint32_t addr,uint32_t value) +{ +volatile uint32_t *reg; + +set_fixmap (FIXMAP_MISC , addr >>PAGE_SHIFT ,DEV_SHARED ); + reg = (uint32_t *)(FIXMAP_ADDR (FIXMAP_MISC ) + (addr & ~PAGE_MASK )); + *reg = value; +clear_fixmap (FIXMAP_MISC ); +} +
Ian.
Re: [PATCH V2 23/33] xen/arm: Allow Xen to run on multiple platform without recompilation
Quoted 15 lines · Ian Campbell
xen/include/asm-arm/platform.h line 49
Quoted 11 lines
xen/include/asm-arm/platform.h new file +11
-0+/* Helper to read/write a register */ +static inline uint32_t platform_read_register (uint32_t addr) +{ +volatile const uint32_t *reg; +uint32_t value; + +set_fixmap (FIXMAP_MISC , addr >>PAGE_SHIFT ,DEV_SHARED ); + reg = (uint32_t *)(FIXMAP_ADDR (FIXMAP_MISC ) + (addr & ~PAGE_MASK )); + value = *reg; +dsb ();isb (); +clear_fixmap (FIXMAP_MISC );I don't think the fixmap is per-PCPU so you probably want some locking here.
Quoted 2 lines
FIXMAP_MISCis a bit of an awful thing, but this isn't especially new, so OK.
In fact now I'm wondering if the platform specific code shouldn't establish its own permanent mapping with ioremap and use that.
Ian.
Re: [PATCH V2 23/33] xen/arm: Allow Xen to run on multiple platform without recompilation
Quoted 16 lines · Ian Campbell
Quoted 15 lines · Ian Campbell
xen/include/asm-arm/platform.h line 49
Quoted 11 lines
xen/include/asm-arm/platform.h new file +11
-0+/* Helper to read/write a register */ +static inline uint32_t platform_read_register (uint32_t addr) +{ +volatile const uint32_t *reg; +uint32_t value; + +set_fixmap (FIXMAP_MISC , addr >>PAGE_SHIFT ,DEV_SHARED ); + reg = (uint32_t *)(FIXMAP_ADDR (FIXMAP_MISC ) + (addr & ~PAGE_MASK )); + value = *reg; +dsb ();isb (); +clear_fixmap (FIXMAP_MISC );I don't think the fixmap is per-PCPU so you probably want some locking here.
Quoted 5 lines
Quoted 2 lines
FIXMAP_MISCis a bit of an awful thing, but this isn't especially new, so OK.In fact now I'm wondering if the platform specific code shouldn't establish its own permanent mapping with ioremap and use that.
I will rework this patch with ioremap
Signature · 1 line
Julien
Re: [PATCH V2 23/33] xen/arm: Allow Xen to run on multiple platform without recompilation
In reply to Ian CampbellQuoted 16 lines · Ian Campbell
Quoted 15 lines · Julien Grall
xen/arch/arm/time.c +1
-0@@ -33,6 +33,7 @@#include <asm/time.h> #include <asm/gic.h> #include <asm/cpufeature.h> +#include <asm/platform.h> /* * Unfortunately the hypervisor timer interrupt appears to be buggy in @@ -130,6 +131,11 @@ int __init init_xen_time(void)panic ("CPU does not support the Generic Timer v1 interface.\n" );
Quoted 4 lines
xen/arch/arm/time.c int __init init_xen_time(void) · line 133
Quoted 1 line
xen/arch/arm/time.c +0
-0cpu_khz =READ_SYSREG32 (CNTFRQ_EL0 ) /1000 ;Might be better to read this after
platform_init_time, in casep_i_tdoes something "magic" on this platform?
Ok. I will move the platform_init_time just before.
Signature · 1 line
Julien
PATCH v2 24/33 xen/arm: WORKAROUND 1:1 memory mapping for dom0
In reply to Julien GrallCurrently xen doesn't implement SYS MMU. When a device will talk with dom0 with DMA request the domain will use GFN instead of MFN.
For instance on the arndale board, without this patch the network doesn't work.
The 1:1 mapping is a workaround and MUST be remove as soon as a SYS MMU is implemented in XEN.
Changes in v2:
- Add quirk in platform code to only enable 1:1 mapping if the board really need it to run (ie: SYS MMU is not yet implemented in Xen).
--- xen/arch/arm/domain_build.c | 41 ++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/platform.h | 6 ++++++ 2 files changed, 47 insertions(+)
xen/arch/arm/domain_build.c +41 -0
@@ -62,6 +62,43 @@ struct vcpu *__init alloc_dom0_vcpu0(void)return alloc_vcpu (dom0,0 ,0 ); } +static int set_memory_reg_11 (struct domain *d,struct kernel_info *kinfo, +const void *fdt,const u32 *cell,int len, +int address_cells,int size_cells,u32 *new_cell) +{ +int reg_size = (address_cells + size_cells) *sizeof (*cell); +paddr_t start; +paddr_t size; +struct page_info *pg; +unsigned int order =get_order_from_bytes (dom0_mem); +int res; +paddr_t spfn; + + pg =alloc_domheap_pages (d, order,0 ); +if ( !pg ) +panic ("Failed to allocate contiguous memory for dom0\n" ); + + spfn =page_to_mfn (pg); + start = spfn <<PAGE_SHIFT ; + size = (1 << order) <<PAGE_SHIFT ; + +// 1:1 mapping +printk ("Populate P2M %#" PRIx64"->%#" PRIx64" (1:1 mapping for dom0)\n" , + start, start + size); + res =guest_physmap_add_page (d, spfn, spfn, order); + +if ( res ) +panic ("Unable to add pages in DOM0: %d\n" , res); + +device_tree_set_reg (&new_cell, address_cells, size_cells, start, size); + + kinfo->mem.bank[0 ].start = start; + kinfo->mem.bank[0 ].size = size; + kinfo->mem.nr_banks =1 ; + +return reg_size; +} +static int set_memory_reg (struct domain *d,struct kernel_info *kinfo,const void *fdt,const u32 *cell,int len,int address_cells,int size_cells,u32 *new_cell)
@@ -71,6 +108,10 @@ static int set_memory_reg(struct domain *d, struct kernel_info *kinfo,u64 start;u64 size; +if (platform_has_quirk (PLATFORM_QUIRK_DOM0_MAPPING_11 ) ) +return set_memory_reg_11 (d, kinfo, fdt, cell, len, address_cells, + size_cells, new_cell); +while ( kinfo->unassigned_mem >0 && l + reg_size <= len && kinfo->mem.nr_banks <NR_MEM_BANKS ) {
xen/include/asm-arm/platform.h +6 -0
@@ -28,6 +28,12 @@ struct platform_desc {uint32_t (*quirks)(void ); }; +/* +* Quirk to map dom0 memory in 1:1 +* Usefull on platform where System MMU is not yet implemented +*/ +#define PLATFORM_QUIRK_DOM0_MAPPING_11 (1 << 0) +int __init platform_init (void );int __init platform_init_time (void );int __init platform_specific_mapping (struct domain *d);
Signature · 1 line
Julien Grall
Re: [PATCH V2 24/33] xen/arm: WORKAROUND 1:1 memory mapping for dom0
Quoted 9 lines · Julien Grall
Currently xen doesn't implement SYS MMU. When a device will talk with dom0 with DMA request the domain will use GFN instead of MFN.
For instance on the arndale board, without this patch the network doesn't work.The 1:1 mapping is a workaround and MUST be remove as soon as a SYS MMU is implemented in XEN.
Signed-off-by Julien Grall <[email protected]>
(Somewhat reluctantly) Acked-by: Ian Campbell <[email protected]>
I consider this to be a temporary workaround and at some point (possibly even as soon as 4.4) I intend to push for its removal, even if this breaks some platforms which have not by then implemented SYS MMU support for whatever reason.
Vendors who care about support for their platform under Xen need to sort out SYS MMU support for them sooner rather than later (which probably means patches, but documentation would be at least a tolerable alternative).
Quoted 1 line
+ * Usefull on platform where System MMU is not yet implemented
"Useful"
Ian.
PATCH v2 25/33 xen/arm: Add versatile express platform
In reply to Julien GrallThis platform contains nearly nothing specific except the reset function.
Changes in v2:
- Add TODO to retrieve reset base address in the DT
--- xen/arch/arm/platforms/vexpress.c | 30 ++++++++++++++++++++++++++++++ xen/arch/arm/shutdown.c | 14 -------------- xen/include/asm-arm/config.h | 3 --- xen/include/asm-arm/platforms/vexpress.h | 3 +++ 4 files changed, 33 insertions(+), 17 deletions(-)
xen/arch/arm/platforms/vexpress.c +30 -0
@@ -18,6 +18,7 @@*/ #include <asm/platforms/vexpress.h> +#include <asm/platform.h> #include <xen/mm.h> #define DCC_SHIFT 26
@@ -91,6 +92,35 @@ out: }/* +* TODO: Get base address from the device tree +* See arm,vexpress-reset node +*/ +static void vexpress_reset (void ) +{ +/* Use the SP810 system controller to force a reset */ +volatile uint32_t *sp810; +set_fixmap (FIXMAP_MISC ,SP810_ADDRESS >>PAGE_SHIFT ,DEV_SHARED ); + sp810 = ((uint32_t *) + (FIXMAP_ADDR (FIXMAP_MISC ) + (SP810_ADDRESS & ~PAGE_MASK ))); + sp810[0 ] =0x3 ;/* switch to slow mode */ +dsb ();isb (); + sp810[1 ] =0x1 ;/* writing any value to SCSYSSTAT reg will reset system */ +dsb ();isb (); +clear_fixmap (FIXMAP_MISC ); +} + +static const char const *vexpress_dt_compat[]__initdata = +{ +"arm,vexpress" , +NULL +}; + +PLATFORM_START (vexpress,"VERSATILE EXPRESS" ) + .compatible = vexpress_dt_compat, + .reset = vexpress_reset, +PLATFORM_END + +/* * Local variables: * mode: C * c-file-style: "BSD"
xen/arch/arm/shutdown.c +0 -14
@@ -3,25 +3,11 @@#include <xen/cpu.h> #include <xen/delay.h> #include <xen/lib.h> -#include <xen/mm.h> #include <xen/smp.h> #include <asm/platform.h> static void raw_machine_reset (void ) { -/* XXX get this from device tree */ -#ifdef SP810_ADDRESS -/* Use the SP810 system controller to force a reset */ -volatile uint32_t *sp810; -set_fixmap (FIXMAP_MISC ,SP810_ADDRESS >>PAGE_SHIFT ,DEV_SHARED ); - sp810 = ((uint32_t *) - (FIXMAP_ADDR (FIXMAP_MISC ) + (SP810_ADDRESS & ~PAGE_MASK ))); - sp810[0 ] =0x3 ;/* switch to slow mode */ -dsb ();isb (); - sp810[1 ] =0x1 ;/* writing any value to SCSYSSTAT reg will reset system */ -dsb ();isb (); -clear_fixmap (FIXMAP_MISC ); -#endif platform_reset (); }
xen/include/asm-arm/config.h +0 -3
@@ -149,9 +149,6 @@ extern unsigned long frametable_virt_end;#define GIC_CR_OFFSET 0x2000#define GIC_HR_OFFSET 0x4000/* Guess work http://lists.infradead.org/pipermail/linux-arm-kernel/2011-September/064219.html */ #define GIC_VR_OFFSET 0x6000/* Virtual Machine CPU interface) */ -/* Board-specific: base address of system controller */ -#define SP810_ADDRESS 0x1C020000 -#endif /* __ARM_CONFIG_H__ */ /*
xen/include/asm-arm/platforms/vexpress.h +3 -0
@@ -23,6 +23,9 @@#define V2M_SYS_CFG_OSC4 4#define V2M_SYS_CFG_OSC5 5 +/* Board-specific: base address of system controller */ +#define SP810_ADDRESS 0x1C020000 +#ifndef __ASSEMBLY__#include <xen/inttypes.h>
Signature · 1 line
Julien Grall
PATCH v2 26/33 xen/arm: remove request_irq
In reply to Julien GrallAll calls to this function in ARM code have been removed. This function SHOULD not be used. If someone calls this function, a linking error will occur.
--- xen/arch/arm/irq.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
xen/arch/arm/irq.c +2 -9
@@ -97,13 +97,6 @@ int __init request_dt_irq(const struct dt_irq *irq,void (*handler)(int ,void *,struct cpu_user_regs *), unsigned long irqflags, const char *devname, void *dev_id) { - return request_irq(irq->irq, handler, irqflags, devname, dev_id); -} - -int __init request_irq (unsigned int irq, -void (*handler)(int ,void *,struct cpu_user_regs *), -unsigned long irqflags,const char * devname,void *dev_id) -{ struct irqaction *action;int retval;
@@ -113,7 +106,7 @@ int __init request_irq(unsigned int irq,* which interrupt is which (messes up the interrupt freeing * logic etc). */ -if (irq >= nr_irqs) +if (irq->irq >= nr_irqs)return -EINVAL ;if (!handler)return -EINVAL ;
@@ -127,7 +120,7 @@ int __init request_irq(unsigned int irq, action->dev_id = dev_id; action->free_on_release =1 ; - retval =setup_irq (irq, action); + retval =setup_dt_irq (irq, action);if (retval)xfree (action);
Signature · 1 line
Julien Grall
Re: [PATCH V2 26/33] xen/arm: remove request_irq
Quoted 4 lines · Julien Grall
All calls to this function in ARM code have been removed. This function SHOULD not be used. If someone calls this function, a linking error will occur.
Signed-off-by Julien Grall <[email protected]>
PATCH v2 27/33 xen/arm: remove setup_irq
In reply to Julien GrallAll calls to this function in ARM code have been removed. This function SHOULD not be used. If someone calls this function, a linking error will occur.
--- xen/arch/arm/gic.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
xen/arch/arm/gic.c +2 -7
@@ -553,20 +553,15 @@ static int __setup_irq(struct irq_desc *desc, unsigned int irq,int __init setup_dt_irq (const struct dt_irq *irq,struct irqaction *new) { -return setup_irq (irq->irq, new); -} - -int __init setup_irq (unsigned int irq,struct irqaction *new) -{int rc;unsigned long flags;struct irq_desc *desc; - desc =irq_to_desc (irq); + desc =irq_to_desc (irq->irq);spin_lock_irqsave (&desc->lock, flags); - rc =__setup_irq (desc, irq, new); + rc =__setup_irq (desc, irq->irq, new);spin_unlock_irqrestore (&desc->lock, flags);
Signature · 1 line
Julien Grall
Re: [PATCH V2 27/33] xen/arm: remove setup_irq
Quoted 4 lines · Julien Grall
All calls to this function in ARM code have been removed. This function SHOULD not be used. If someone calls this function, a linking error will occur.
Signed-off-by Julien Grall <[email protected]>
PATCH v2 28/33 xen/arm: Don't use pl011 UART by default for early printk
In reply to Julien GrallAdd CONFIG_EARLY_PRINTK options in configs/arm{32,64}.mk to let the user to choose if he wants to have early output, ie before the console is initialized.
This code is specific for each UART. When CONFIG_EARLY_PRINTK is enabled, Xen will only be able to run on a board with this UART.
If a developper wants to add support for a new UART, he must implement the following assembly macro/define:
- EALY_UART_BASE_ADDRESS: variable which contains the physical base address for the UART
- early_uart_init: initialize the UART
- early_uart_ready: check and wait until the UART can transmit a new character
- early_uart_transmit: transmit a character
For more details about the parameters of each function, see arm{32,64}/debug-pl011.inc comments.
Changes in v2:
- Use macro instead of function for assembly early printk API
- Add documentation for ARM early printk
--- docs/misc/arm/early-printk.txt | 14 +++++++ xen/arch/arm/Makefile | 2 +- xen/arch/arm/Rules.mk | 15 ++++++++ xen/arch/arm/arm32/Makefile | 5 ++- xen/arch/arm/arm32/debug-pl011.inc | 58 +++++++++++++++++++++++++++++ xen/arch/arm/arm32/debug.S | 33 +++++++++++++++++ xen/arch/arm/arm32/head.S | 65 ++++++++++++++++----------------- xen/arch/arm/arm64/Makefile | 2 + xen/arch/arm/arm64/debug-pl011.inc | 59 ++++++++++++++++++++++++++++++ xen/arch/arm/arm64/debug.S | 33 +++++++++++++++++ xen/arch/arm/arm64/head.S | 71 ++++++++++++++++-------------------- xen/arch/arm/early_printk.c | 16 +------- xen/include/asm-arm/config.h | 2 - xen/include/asm-arm/early_printk.h | 2 +- 14 files changed, 284 insertions(+), 93 deletions(-) create mode 100644 docs/misc/arm/early-printk.txt create mode 100644 xen/arch/arm/arm32/debug-pl011.inc create mode 100644 xen/arch/arm/arm32/debug.S create mode 100644 xen/arch/arm/arm64/debug-pl011.inc create mode 100644 xen/arch/arm/arm64/debug.S
docs/misc/arm/early-printk.txt new file +14 -0
@@ -0,0 +1,14 @@ +How to enable early printk + +Early printk can only be enabled if debug=y. You may want to enable it if +you are debbuging code that executes before the console is initialized. + +Note that selecting this option will limit Xen to a single UART definition. +Attempting to boot Xen image on a different platform *will not work*, so this +option should not be enable for Xens that are intended to be portable. + +CONFIG_EARLY_PRINTK=mach +where mach is the name of the machine: + - vexpress: printk with pl011 for versatile express + +By default early printk is disabled.
xen/arch/arm/Makefile +1 -1
@@ -2,7 +2,7 @@ subdir-$(arm32) += arm32 subdir-$(arm64) += arm64 subdir-y += platforms -obj-y += early_printk.o +obj-$(EARLY_PRINTK) += early_printk.o obj-y += cpu.o obj-y += domain.o obj-y += psci.o
xen/arch/arm/Rules.mk +15 -0
@@ -36,3 +36,18 @@ endif ifneq ($(call cc-option,$(CC),-fvisibility=hidden,n),n) CFLAGS += -DGCC_HAS_VISIBILITY_ATTRIBUTE endif + +EARLY_PRINTK := n + +ifeq ($(debug),y) + +# Early printk for versatile express +# TODO handle UART base address from make command line +ifeq ($(CONFIG_EARLY_PRINTK), vexpress) +EARLY_PRINTK := y +EARLY_PRINTK_INC := pl011 +endif + +CFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK +CFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK_INC=\"debug-$(EARLY_PRINTK_INC).inc\" +endif
xen/arch/arm/arm32/Makefile +4 -1
@@ -5,4 +5,7 @@ obj-y += mode_switch.o obj-y += proc-ca15.o obj-y += traps.o -obj-y += domain.o +obj-y += domain.o + +obj-$(EARLY_PRINTK) += debug.o +obj-$(CONFIG_EARLY_PL011) += debug-pl011.o
xen/arch/arm/arm32/debug-pl011.inc new file +58 -0
58 lines not on this page · raw message
xen/arch/arm/arm32/debug.S new file +33 -0
@@ -0,0 +1,33 @@ +/* + * xen/arch/arm/arm32/debug.S + * + * Wrapper for early printk + * + * Julien Grall <[email protected]> + * Copyright (c) 2013 Linaro Limited. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <asm/config.h> + +#ifdef EARLY_PRINTK_INC +#include EARLY_PRINTK_INC +#endif + +.globl early_putch +/* Print a character on the UART - this function is called by C + * r0: character to print */ +early_putch: + ldr r1, =FIXMAP_ADDR(FIXMAP_CONSOLE) /* r1 := VA UART base address */ + early_uart_ready r1, r2 + early_uart_transmit r1, r0 + mov pc, lr
xen/arch/arm/arm32/head.S +31 -34
134 lines not on this page · raw message
xen/arch/arm/arm64/Makefile +2 -0
@@ -5,3 +5,5 @@ obj-y += mode_switch.o obj-y += traps.o obj-y += domain.o + +obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm64/debug-pl011.inc new file +59 -0
59 lines not on this page · raw message
xen/arch/arm/arm64/debug.S new file +33 -0
@@ -0,0 +1,33 @@ +/* + * xen/arch/arm/arm64/debug.S + * + * Wrapper for early printk + * + * Julien Grall <[email protected]> + * Copyright (c) 2013 Linaro Limited. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <asm/config.h> + +#ifdef EARLY_PRINTK_INC +#include EARLY_PRINTK_INC +#endif + +.globl early_putch +/* Print a character on the UART - this function is called by C + * x0: character to print */ +early_putch: + ldr x23, =FIXMAP_ADDR(FIXMAP_CONSOLE) + early_uart_ready x23, 1 + early_uart_transmit x23, w0 + ret
xen/arch/arm/arm64/head.S +32 -39
144 lines not on this page · raw message
xen/arch/arm/early_printk.c +1 -15
@@ -15,19 +15,7 @@#include <xen/string.h> #include <asm/early_printk.h> -#ifdef EARLY_UART_ADDRESS - -void __init early_putch (char c) -{ -volatile uint32_t *r; - - r = (uint32_t *)(XEN_VIRT_START + (1 <<21 )); - -/* XXX: assuming a PL011 UART. */ -while (*(r +0x6 ) &0x8 ) - ; - *r = c; -} +void early_putch (char c);/* Early printk buffer */ static char __initdata buf[512 ];
@@ -68,5 +56,3 @@ early_panic(const char *fmt, ...)while (1 ); } - -#endif /* #ifdef EARLY_UART_ADDRESS */
xen/include/asm-arm/config.h +0 -2
@@ -141,8 +141,6 @@ extern unsigned long frametable_virt_end;#define watchdog_disable () ((void)0)#define watchdog_enable () ((void)0) -/* Board-specific: base address of PL011 UART */ -#define EARLY_UART_ADDRESS 0x1c090000/* Board-specific: base address of GIC + its regs */ #define GIC_BASE_ADDRESS 0x2c000000#define GIC_DR_OFFSET 0x1000
xen/include/asm-arm/early_printk.h +1 -1
@@ -12,7 +12,7 @@#include <xen/config.h> -#ifdef EARLY_UART_ADDRESS +#ifdef EARLY_PRINTK void early_printk (const char *fmt, ...);void early_panic (const char *fmt, ...) __attribute__((noreturn));
Signature · 1 line
Julien Grall
Re: [PATCH V2 28/33] xen/arm: Don't use pl011 UART by default for early printk
Quoted 5 lines · Julien Grall
xen/arch/arm/arm32/Makefile +0
-0
xen/arch/arm/arm32/Makefile obj-y += mode_switch.o · line 11
Quoted 9 lines
xen/arch/arm/arm32/Makefile +4
-1@@ -5,4 +5,7 @@ obj-y += mode_switch.o obj-y += proc-ca15.o obj-y += traps.o -obj-y += domain.o +obj-y += domain.o + +obj-$(EARLY_PRINTK) += debug.o +obj-$(CONFIG_EARLY_PL011) += debug-pl011.o
Is this correct now that you are using debug-pl011.inc?
Quoted 5 lines
/* Print a 32-bit number in hex. Specific to the PL011 UART.
* r0: Number to print.
- * clobbers r0-r3 */
+ * r11: Early UART base address
+ * clobbers r1-r3 */
This still clobbers r0, via the lsl below.
Quoted 17 lines
putn:
adr r1, hex mov r3, #8 -1: ldr r2, [r11, #0x18] /* <- UARTFR (Flag register) */xen/arch/arm/arm32/Makefile +3
-3- tst r2, #0x8 /* Check BUSY bit */ - bne 1b /* Wait for the UART to be ready */ +1: + early_uart_ready r11, r2 and r2, r0, #0xf0000000 /* Mask off the top nybble */ ldrb r2, [r1, r2, lsr #28] /* Convert to a char */ - str r2, [r11] /* -> UARTDR (Data Register) */ + early_uart_transmit r11, r2 lsl r0, #4 /* Roll it through one nybble at a time */ subs r3, r3, #1 bne 1b@@ -329,51 +329,44 @@ fail: PRINT("- Boot failed -\r\n") 1: wfe
xen/arch/arm/arm32/Makefile fail: PRINT("- Boot failed -\r\n") · line 336
Quoted 10 lines
xen/arch/arm/arm32/Makefile +4
-3b 1b -#ifdef EARLY_UART_ADDRESS +#ifdef EARLY_PRINTK -/* Bring up the UART. Specific to the PL011 UART. - * Clobbers r0-r2 */ +/* Bring up the UART. + * x23: Early UART base address + * Clobbers x0-x1 */
Does it actually clobber x1?
Quoted 15 lines
xen/arch/arm/arm32/Makefile +2
-9init_uart: - mov x1, #0x0 - strh w1, [x23, #0x24] /* -> UARTIBRD (Baud divisor fraction) */ - mov x1, #0x4 /* 7.3728MHz / 0x4 == 16 * 115200 */ - strh w1, [x23, #0x24] /* -> UARTIBRD (Baud divisor integer) */ - mov x1, #0x60 /* 8n1 */ - strh w1, [x23, #0x24] /* -> UARTLCR_H (Line control) */ - ldr x1, =0x00000301 /* RXE | TXE | UARTEN */ - strh w1, [x23, #0x30] /* -> UARTCR (Control Register) */ + early_uart_init x23, 0 adr x0, 1f - b puts + b puts /* Jump to puts */ 1: .asciz "- UART enabled -\r\n" .align 4
Re: [PATCH V2 28/33] xen/arm: Don't use pl011 UART by default for early printk
Quoted 8 lines · Ian Campbell
Quoted 7 lines · Julien Grall
xen/arch/arm/arm32/Makefile +0
-0@@ -5,4 +5,7 @@ obj-y += mode_switch.o obj-y += proc-ca15.o
Quoted 9 lines
xen/arch/arm/arm32/Makefile obj-y += mode_switch.o · line 11
Quoted 7 lines
xen/arch/arm/arm32/Makefile +4
-1obj-y += traps.o -obj-y += domain.o +obj-y += domain.o + +obj-$(EARLY_PRINTK) += debug.o +obj-$(CONFIG_EARLY_PL011) += debug-pl011.oIs this correct now that you are using debug-pl011.inc?
It comes from a bad merge. I will fix it on the next patch series.
Quoted 7 lines
Quoted 5 lines
/* Print a 32-bit number in hex. Specific to the PL011 UART.
* r0: Number to print.
- * clobbers r0-r3 */
+ * r11: Early UART base address
+ * clobbers r1-r3 */This still clobbers r0, via the lsl below.
Right will be fix on the next patch series.
Quoted 22 lines
Quoted 22 lines
putn:
adr r1, hex mov r3, #8 -1: ldr r2, [r11, #0x18] /* <- UARTFR (Flag register) */xen/arch/arm/arm32/Makefile +4
-4- tst r2, #0x8 /* Check BUSY bit */ - bne 1b /* Wait for the UART to be ready */ +1: + early_uart_ready r11, r2 and r2, r0, #0xf0000000 /* Mask off the top nybble */ ldrb r2, [r1, r2, lsr #28] /* Convert to a char */ - str r2, [r11] /* -> UARTDR (Data Register) */ + early_uart_transmit r11, r2 lsl r0, #4 /* Roll it through one nybble at a time */ subs r3, r3, #1 bne 1b@@ -329,51 +329,44 @@ fail: PRINT("- Boot failed -\r\n") 1: wfe b 1b -#ifdef EARLY_UART_ADDRESS +#ifdef EARLY_PRINTK
Quoted 7 lines
xen/arch/arm/arm32/Makefile fail: PRINT("- Boot failed -\r\n") · line 336
Quoted 5 lines
xen/arch/arm/arm32/Makefile +3
-2-/* Bring up the UART. Specific to the PL011 UART. - * Clobbers r0-r2 */ +/* Bring up the UART. + * x23: Early UART base address + * Clobbers x0-x1 */Does it actually clobber x1?
Yes, by puts. init_uart will jump to this function at the end.
Quoted 18 lines
Quoted 15 lines
xen/arch/arm/arm32/Makefile +2
-9init_uart: - mov x1, #0x0 - strh w1, [x23, #0x24] /* -> UARTIBRD (Baud divisor fraction) */ - mov x1, #0x4 /* 7.3728MHz / 0x4 == 16 * 115200 */ - strh w1, [x23, #0x24] /* -> UARTIBRD (Baud divisor integer) */ - mov x1, #0x60 /* 8n1 */ - strh w1, [x23, #0x24] /* -> UARTLCR_H (Line control) */ - ldr x1, =0x00000301 /* RXE | TXE | UARTEN */ - strh w1, [x23, #0x30] /* -> UARTCR (Control Register) */ + early_uart_init x23, 0 adr x0, 1f - b puts + b puts /* Jump to puts */ 1: .asciz "- UART enabled -\r\n" .align 4
Signature · 1 line
Julien
PATCH v2 29/33 xen/arm: Add exynos 4210 UART support
In reply to Julien GrallFrom: Anthony PERARD <[email protected]>
Changes in v2:
- Use defines where it's possible
- Move UART definition in a separate header. Will be used for early UART
- Replace all // by /* ... */
- Add Anthony as first author
--- config/arm32.mk | 1 + xen/drivers/char/Makefile | 1 + xen/drivers/char/exynos4210-uart.c | 357 +++++++++++++++++++++++++++++++++ xen/include/asm-arm/exynos4210-uart.h | 111 ++++++++++ 4 files changed, 470 insertions(+) create mode 100644 xen/drivers/char/exynos4210-uart.c create mode 100644 xen/include/asm-arm/exynos4210-uart.h
config/arm32.mk +1 -0
@@ -8,6 +8,7 @@ CONFIG_ARM_$(XEN_OS) := y CFLAGS += -marm HAS_PL011 := y +HAS_EXYNOS4210 := y # Use only if calling $(LD) directly. #LDFLAGS_DIRECT_OpenBSD = _obsd
xen/drivers/char/Makefile +1 -0
@@ -1,6 +1,7 @@ obj-y += console.o obj-$(HAS_NS16550) += ns16550.o obj-$(HAS_PL011) += pl011.o +obj-$(HAS_EXYNOS4210) += exynos4210-uart.o obj-$(HAS_EHCI) += ehci-dbgp.o obj-$(CONFIG_ARM) += arm-uart.o obj-y += serial.o
xen/drivers/char/exynos4210-uart.c new file +357 -0
357 lines not on this page · raw message
xen/include/asm-arm/exynos4210-uart.h new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
Julien Grall
Re: [PATCH V2 29/33] xen/arm: Add exynos 4210 UART support
xen/drivers/char/exynos4210-uart.c line 137
Quoted 6 lines · Julien Grall
xen/drivers/char/exynos4210-uart.c new file +6
-0+/* TODO: should be updated */ +/* Baud rate already set: read it out from the divisor latch. */ +#if 0 + divisor = (uart->regs[IBRD ] <<6 ) | uart->regs[FBRD ]; + uart->baud = (uart->clock_hz <<2 ) / divisor; +#endif
Can we drop the #if 0, extending the comment if necessary, or if possible drop the whole thing.
Quoted 4 lines
xen/drivers/char/exynos4210-uart.c new file +4
-0+static int __init exynos4210_uart_init (struct dt_device_node *dev, +const void *data) +{ +const struct serial_arm_defaults *defaults = data;
xen/drivers/char/exynos4210-uart.c line 318
Quoted 10 lines
xen/drivers/char/exynos4210-uart.c new file +10
-0+struct exynos4210_uart *uart; +int res; + +if ( (defaults->index <0 ) || (defaults->index >1 ) ) +return -EINVAL ; + + uart = &exynos4210_com[defaults->index]; + +/* uart->clock_hz = 0x16e3600; */ + uart->baud =BAUD_AUTO ;//115200;
Drop the //115200.
xen/include/asm-arm/exynos4210-uart.h line 4
Quoted 10 lines
xen/include/asm-arm/exynos4210-uart.h new file +4
-0@@ -0,0 +1,111 @@ +/* +* xen/include/asm-arm/exynos4210-uart.h +* +* Common constant definition between ealry printk and the UART driver
"early"
If you fix all the above then
Ian.
Re: [PATCH V2 29/33] xen/arm: Add exynos 4210 UART support
Quoted 10 lines · Ian Campbell
xen/drivers/char/exynos4210-uart.c line 137
Quoted 6 lines · Julien Grall
xen/drivers/char/exynos4210-uart.c new file +6
-0+/* TODO: should be updated */ +/* Baud rate already set: read it out from the divisor latch. */ +#if 0 + divisor = (uart->regs[IBRD ] <<6 ) | uart->regs[FBRD ]; + uart->baud = (uart->clock_hz <<2 ) / divisor; +#endif Can we drop the #if 0, extending the comment if necessary, or if possible drop the whole thing.
I will move this two lines in the comment.
Quoted 8 lines
Quoted 8 lines
xen/drivers/char/exynos4210-uart.c new file +8
-0+static int __init exynos4210_uart_init (struct dt_device_node *dev, +const void *data) +{ +const struct serial_arm_defaults *defaults = data; +struct exynos4210_uart *uart; +int res; + +if ( (defaults->index <0 ) || (defaults->index >1 ) )
Quoted 8 lines
xen/drivers/char/exynos4210-uart.c line 318
Quoted 6 lines
xen/drivers/char/exynos4210-uart.c new file +6
-0+return -EINVAL ; + + uart = &exynos4210_com[defaults->index]; + +/* uart->clock_hz = 0x16e3600; */ + uart->baud =BAUD_AUTO ;//115200; Drop the //115200.
Will be fixed in the next patch series.
Quoted 18 lines
xen/include/asm-arm/exynos4210-uart.h line 4
Quoted 10 lines
xen/include/asm-arm/exynos4210-uart.h new file +4
-0@@ -0,0 +1,111 @@ +/* +* xen/include/asm-arm/exynos4210-uart.h +* +* Common constant definition between ealry printk and the UART driver "early"
If you fix all the above then
Acked-by Ian Campbell <[email protected]>Ian.
PATCH v2 30/33 xen/arm: Add Exynos 4210 UART support for early printk
In reply to Julien GrallFrom: Anthony PERARD <[email protected]>
Changes in v2:
- Use assembly macro instead of function
- Add Anthony as first author
--- docs/misc/arm/early-printk.txt | 1 + xen/arch/arm/Rules.mk | 4 ++ xen/arch/arm/arm32/Makefile | 1 - xen/arch/arm/arm32/debug-exynos4210.inc | 77 +++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/arm32/debug-exynos4210.inc
docs/misc/arm/early-printk.txt +1 -0
@@ -10,5 +10,6 @@ option should not be enable for Xens that are intended to be portable. CONFIG_EARLY_PRINTK=mach where mach is the name of the machine: - vexpress: printk with pl011 for versatile express + - exynos5250: printk with the second UART By default early printk is disabled.
xen/arch/arm/Rules.mk +4 -0
@@ -47,6 +47,10 @@ ifeq ($(CONFIG_EARLY_PRINTK), vexpress) EARLY_PRINTK := y EARLY_PRINTK_INC := pl011 endif +ifeq ($(CONFIG_EARLY_PRINTK), exynos5250) +EARLY_PRINTK := y +EARLY_PRINTK_INC := exynos4210 +endif CFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK CFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK_INC=\"debug-$(EARLY_PRINTK_INC).inc\"
xen/arch/arm/arm32/Makefile +0 -1
@@ -8,4 +8,3 @@ obj-y += traps.o obj-y += domain.o obj-$(EARLY_PRINTK) += debug.o -obj-$(CONFIG_EARLY_PL011) += debug-pl011.o
xen/arch/arm/arm32/debug-exynos4210.inc new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
Julien Grall
Re: [PATCH V2 30/33] xen/arm: Add Exynos 4210 UART support for early printk
Quoted 42 lines · Julien Grall
From: Anthony PERARD <[email protected]>
Signed-off-by Anthony PERARD <[email protected]>Signed-off-by Julien Grall <[email protected]>Changes in v2:
- Use assembly macro instead of function
- Add Anthony as first author--- docs/misc/arm/early-printk.txt | 1 + xen/arch/arm/Rules.mk | 4 ++ xen/arch/arm/arm32/Makefile | 1 - xen/arch/arm/arm32/debug-exynos4210.inc | 77 +++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/arm32/debug-exynos4210.incdocs/misc/arm/early-printk.txt +1
-0@@ -10,5 +10,6 @@ option should not be enable for Xens that are intended to be portable. CONFIG_EARLY_PRINTK=mach where mach is the name of the machine: - vexpress: printk with pl011 for versatile express + - exynos5250: printk with the second UART By default early printk is disabled.xen/arch/arm/Rules.mk +4
-0@@ -47,6 +47,10 @@ ifeq ($(CONFIG_EARLY_PRINTK), vexpress) EARLY_PRINTK := y EARLY_PRINTK_INC := pl011 endif +ifeq ($(CONFIG_EARLY_PRINTK), exynos5250) +EARLY_PRINTK := y +EARLY_PRINTK_INC := exynos4210 +endif CFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK
Quoted 1 line
CFLAGS-$(EARLY_PRINTK) += -DEARLY_PRINTK_INC=\"debug-$(EARLY_PRINTK_INC).inc\"
These are somewhat redundant, we could almost combine them into one which is the .inc file to use and then use ifdef on that.
xen/arch/arm/arm32/Makefile obj-y += traps.o · line 11
Quoted 9 lines
xen/arch/arm/arm32/Makefile +0
-1@@ -8,4 +8,3 @@ obj-y += traps.o obj-y += domain.o obj-$(EARLY_PRINTK) += debug.o -obj-$(CONFIG_EARLY_PL011) += debug-pl011.o
I think this shouldn't have been added earlier and so shouldn't need to be removed here.
Quoted 20 lines
xen/arch/arm/arm32/debug-exynos4210.inc new file +14
-0@@ -0,0 +1,77 @@ +/* + * xen/arch/arm/arm32/debug-exynos4210.inc + * + * Exynos 5 specific debug code + * + * Copyright (c) 2013 Citrix Systems. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of
xen/arch/arm/arm32/debug-exynos4210.inc line 24
Quoted 10 lines
xen/arch/arm/arm32/debug-exynos4210.inc new file +10
-0+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <asm/exynos4210-uart.h> + +#define EARLY_UART_BASE_ADDRESS 0x12c20000 + +/* Exynos 5 UART initialization + * rb: register which containts the UART base address
"contains"
Quoted 22 lines
xen/arch/arm/arm32/debug-exynos4210.inc new file +22
-0+ * rc: scratch register 1 + * rd: scratch register 2 */ +.macro early_uart_init rb rc rd + /* init clock */ + ldr \rc, =0x10020000 + /* select MPLL (800MHz) source clock */ + ldr \rd, [\rc, #0x250] + and \rd, \rd, #(~(0xf<<8)) + orr \rd, \rd, #(0x6<<8) + str \rd, [\rc, #0x250] + /* ratio 800/(7+1) */ + ldr \rd, [\rc, #0x558] + and \rd, \rd, #(~(0xf<<8)) + orr \rd, \rd, #(0x7<<8) + str \rd, [\rc, #0x558] + + mov \rc, #4 + str \rc, [\rb, #UFRACVAL] /* -> UFRACVAL (Baud divisor fraction) */ + mov \rc, #53 + str \rc, [\rb, #UBRDIV] /* -> UBRDIV (Baud divisor integer) */ + mov \rc, #3 /* 8n1 */ + str \rc, [\rb, #ULCON] /* -> (Line control) */
xen/arch/arm/arm32/debug-exynos4210.inc line 56
Quoted 10 lines
xen/arch/arm/arm32/debug-exynos4210.inc new file +10
-0+ ldr \rc, =UCON_TX_IRQ /* TX IRQMODE */ + str \rc, [\rb, #UCON] /* -> (Control Register) */ + mov \rc, #0x0 + str \rc, [\rb, #UFCON] /* disable FIFO */ + mov \rc, #0x0 + str \rc, [\rb, #UMCON] /* no auto flow control */ +.endm + +/* Exynos 5 UART wait UART to be ready to transmit + * rb: register which containts the UART base address
"contains", again and twice more below.
Quoted 21 lines
xen/arch/arm/arm32/debug-exynos4210.inc new file +21
-0+ * rc: scratch register */ +.macro early_uart_ready rb rc +1: + ldr \rc, [\rb, #UTRSTAT] /* <- UTRSTAT (Flag register) */ + tst \rc, #UTRSTAT_TX_EMPTY /* Check BUSY bit */ + beq 1b /* Wait for the UART to be ready */ +.endm + +/* Exynos 5 UART transmit character + * rb: register which containts the UART base address + * rt: register which containts the character to transmit */ +.macro early_uart_transmit rb rt + str \rt, [\rb, #UTXH] /* -> UTXH (Data Register) */ +.endm + +/* + * Local variables: + * mode: ASM + * indent-tabs-mode: nil + * End: + */
PATCH v2 31/33 xen/arm: Add platform specific code for the exynos5
In reply to Julien GrallChanges in v2:
- Add dom0 1:1 mapping quirk for the arndale board
- s/mapping/mappings/ in comment
- Remove debug trap (unnecessary with linux 3.9)
--- xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/exynos5.c | 86 +++++++++++++++++++++++++++++++ xen/include/asm-arm/platforms/exynos5.h | 40 ++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 xen/arch/arm/platforms/exynos5.c create mode 100644 xen/include/asm-arm/platforms/exynos5.h
xen/arch/arm/platforms/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += vexpress.o +obj-y += exynos5.o
xen/arch/arm/platforms/exynos5.c new file +86 -0
86 lines not on this page · raw message
xen/include/asm-arm/platforms/exynos5.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef __ASM_ARM_PLATFORMS_EXYNOS5_H +#define __ASM_ASM_PLATFORMS_EXYSNO5_H + +#define EXYNOS5_MCT_BASE 0x101c0000 +#define EXYNOS5_MCTREG (x) (EXYNOS5_MCT_BASE + (x)) +#define EXYNOS5_MCT_G_TCON EXYNOS5_MCTREG(0x240) +#define EXYNOS5_MCT_G_TCON_START (1 << 8) + +#define EXYNOS5_PA_CHIPID 0x10000000 +#define EXYNOS5_PA_TIMER 0x12dd0000 +/* Base address of system controller */ +#define EXYNOS5_PA_PMU 0x10040000 + +#define EXYNOS5_SWRESET (EXYNOS5_PA_PMU + 0x0400) + +#define S5P_PA_SYSRAM 0x02020000 + +/* Constants below is only used in assembly because the DTS is not yet parsed */ +#ifdef __ASSEMBLY__ + +/* GIC Base Address */ +#define EXYNOS5_GIC_BASE_ADDRESS 0x10480000 + +/* Timer's frequency */ +#define EXYNOS5_TIMER_FREQUENCY (24 * 1000 * 1000)/* 24 MHz */ + +/* Arndale machine ID */ +#define MACH_TYPE_SMDK5250 3774 + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_ARM_PLATFORMS_EXYNOS5_H */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
Julien Grall
Re: [PATCH V2 31/33] xen/arm: Add platform specific code for the exynos5
Quoted 50 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>Changes in v2:
- Add dom0 1:1 mapping quirk for the arndale board
- s/mapping/mappings/ in comment
- Remove debug trap (unnecessary with linux 3.9)--- xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/exynos5.c | 86 +++++++++++++++++++++++++++++++ xen/include/asm-arm/platforms/exynos5.h | 40 ++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 xen/arch/arm/platforms/exynos5.c create mode 100644 xen/include/asm-arm/platforms/exynos5.hxen/arch/arm/platforms/Makefile +1
-0@@ -1 +1,2 @@ obj-y += vexpress.o +obj-y += exynos5.oxen/arch/arm/platforms/exynos5.c new file +23
-0@@ -0,0 +1,86 @@ +/* +* xen/arch/arm/platforms/exynos5.c +* +* Exynos5 specific settings +* +* Julien Grall <[email protected]> +* Copyright (c) 2013 Linaro Limited. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/p2m.h> +#include <xen/config.h> +#include <xen/device_tree.h> +#include <xen/domain_page.h>
xen/arch/arm/platforms/exynos5.c line 33
Quoted 10 lines
xen/arch/arm/platforms/exynos5.c new file +10
-0+#include <xen/mm.h> +#include <asm/platforms/exynos5.h> +#include <asm/platform.h> + +static int exynos5_init_time (void ) +{ +uint32_t reg; + +// enable timer on exynos5 arndale board +// should probably be done by u-boot
/* */ please.
xen/arch/arm/platforms/exynos5.c line 40
Quoted 7 lines
xen/arch/arm/platforms/exynos5.c new file +7
-0+ reg =platform_read_register (EXYNOS5_MCT_G_TCON ); +platform_write_register (EXYNOS5_MCT_G_TCON , reg |EXYNOS5_MCT_G_TCON_START ); + +return 0 ; +} + +/* Additionnal mappings for dom0 (Not in the DTS) */
"Additional"
xen/arch/arm/platforms/exynos5.c line 50
Quoted 10 lines
xen/arch/arm/platforms/exynos5.c new file +10
-0+static int exynos5_specific_mapping (struct domain *d) +{ +/* Map the chip ID */ +map_mmio_regions (d,EXYNOS5_PA_CHIPID ,EXYNOS5_PA_CHIPID +PAGE_SIZE -1 , +EXYNOS5_PA_CHIPID ); + +/* Map the PWM region */ +map_mmio_regions (d,EXYNOS5_PA_TIMER , +EXYNOS5_PA_TIMER + (PAGE_SIZE *2 ) -1 , +EXYNOS5_PA_TIMER );
If these get added to a future version of the DTS will badness ensue? I suppose all we can do is add a check for the new compatible node at that time, which we obviously can't do now...
xen/include/asm-arm/platforms/exynos5.h line 7
Quoted 13 lines
xen/include/asm-arm/platforms/exynos5.h new file +7
-0@@ -0,0 +1,40 @@ +#ifndef __ASM_ARM_PLATFORMS_EXYNOS5_H +#define __ASM_ASM_PLATFORMS_EXYSNO5_H + +#define EXYNOS5_MCT_BASE 0x101c0000 +#define EXYNOS5_MCTREG (x) (EXYNOS5_MCT_BASE + (x)) +#define EXYNOS5_MCT_G_TCON EXYNOS5_MCTREG(0x240) +#define EXYNOS5_MCT_G_TCON_START (1 << 8)
Inconsistent indent, hard tabs perhaps?
xen/include/asm-arm/platforms/exynos5.h line 18
Quoted 11 lines
xen/include/asm-arm/platforms/exynos5.h new file +11
-0+ +#define EXYNOS5_PA_CHIPID 0x10000000 +#define EXYNOS5_PA_TIMER 0x12dd0000 +/* Base address of system controller */ +#define EXYNOS5_PA_PMU 0x10040000 + +#define EXYNOS5_SWRESET (EXYNOS5_PA_PMU + 0x0400) + +#define S5P_PA_SYSRAM 0x02020000 + +/* Constants below is only used in assembly because the DTS is not yet parsed */
In a subsequent patch?
Quoted 22 lines
xen/include/asm-arm/platforms/exynos5.h new file +22
-0+#ifdef __ASSEMBLY__ + +/* GIC Base Address */ +#define EXYNOS5_GIC_BASE_ADDRESS 0x10480000 + +/* Timer's frequency */ +#define EXYNOS5_TIMER_FREQUENCY (24 * 1000 * 1000)/* 24 MHz */ + +/* Arndale machine ID */ +#define MACH_TYPE_SMDK5250 3774 + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_ARM_PLATFORMS_EXYNOS5_H */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Re: [PATCH V2 31/33] xen/arm: Add platform specific code for the exynos5
Quoted 74 lines · Ian Campbell
Quoted 50 lines · Julien Grall
Signed-off-by Julien Grall <[email protected]>Changes in v2:
- Add dom0 1:1 mapping quirk for the arndale board
- s/mapping/mappings/ in comment
- Remove debug trap (unnecessary with linux 3.9)--- xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/exynos5.c | 86 +++++++++++++++++++++++++++++++ xen/include/asm-arm/platforms/exynos5.h | 40 ++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 xen/arch/arm/platforms/exynos5.c create mode 100644 xen/include/asm-arm/platforms/exynos5.hxen/arch/arm/platforms/Makefile +1
-0@@ -1 +1,2 @@ obj-y += vexpress.o +obj-y += exynos5.oxen/arch/arm/platforms/exynos5.c new file +23
-0@@ -0,0 +1,86 @@ +/* +* xen/arch/arm/platforms/exynos5.c +* +* Exynos5 specific settings +* +* Julien Grall <[email protected]> +* Copyright (c) 2013 Linaro Limited. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/p2m.h> +#include <xen/config.h> +#include <xen/device_tree.h> +#include <xen/domain_page.h> xen/arch/arm/platforms/exynos5.c line 33
Quoted 10 lines
xen/arch/arm/platforms/exynos5.c new file +10
-0+#include <xen/mm.h> +#include <asm/platforms/exynos5.h> +#include <asm/platform.h> + +static int exynos5_init_time (void ) +{ +uint32_t reg; + +// enable timer on exynos5 arndale board +// should probably be done by u-boot /* */ please.
xen/arch/arm/platforms/exynos5.c line 40
Quoted 7 lines
xen/arch/arm/platforms/exynos5.c new file +7
-0+ reg =platform_read_register (EXYNOS5_MCT_G_TCON ); +platform_write_register (EXYNOS5_MCT_G_TCON , reg |EXYNOS5_MCT_G_TCON_START ); + +return 0 ; +} + +/* Additionnal mappings for dom0 (Not in the DTS) */ "Additional"
Quoted 14 lines
xen/arch/arm/platforms/exynos5.c line 50
Quoted 10 lines
xen/arch/arm/platforms/exynos5.c new file +10
-0+static int exynos5_specific_mapping (struct domain *d) +{ +/* Map the chip ID */ +map_mmio_regions (d,EXYNOS5_PA_CHIPID ,EXYNOS5_PA_CHIPID +PAGE_SIZE -1 , +EXYNOS5_PA_CHIPID ); + +/* Map the PWM region */ +map_mmio_regions (d,EXYNOS5_PA_TIMER , +EXYNOS5_PA_TIMER + (PAGE_SIZE *2 ) -1 , +EXYNOS5_PA_TIMER );If these get added to a future version of the DTS will badness ensue? I suppose all we can do is add a check for the new compatible node at that time, which we obviously can't do now...
In this case, we can remove this both lines. map_devices_from_device_tree will do all the work. But I think it's too specific to be added in the DTS.
Quoted 7 lines
Quoted 7 lines
xen/include/asm-arm/platforms/exynos5.h new file +1
-0@@ -0,0 +1,40 @@ +#ifndef __ASM_ARM_PLATFORMS_EXYNOS5_H
Quoted 8 lines
xen/include/asm-arm/platforms/exynos5.h line 7
Quoted 6 lines
xen/include/asm-arm/platforms/exynos5.h new file +6
-0+#define __ASM_ASM_PLATFORMS_EXYSNO5_H + +#define EXYNOS5_MCT_BASE 0x101c0000 +#define EXYNOS5_MCTREG (x) (EXYNOS5_MCT_BASE + (x)) +#define EXYNOS5_MCT_G_TCON EXYNOS5_MCTREG(0x240) +#define EXYNOS5_MCT_G_TCON_START (1 << 8)Inconsistent indent, hard tabs perhaps?
Right. Will be fix on the next patch series.
Quoted 5 lines
Quoted 5 lines
xen/include/asm-arm/platforms/exynos5.h new file +5
-0+ +#define EXYNOS5_PA_CHIPID 0x10000000 +#define EXYNOS5_PA_TIMER 0x12dd0000 +/* Base address of system controller */ +#define EXYNOS5_PA_PMU 0x10040000
Quoted 8 lines
xen/include/asm-arm/platforms/exynos5.h line 18
Quoted 6 lines
xen/include/asm-arm/platforms/exynos5.h new file +6
-0+ +#define EXYNOS5_SWRESET (EXYNOS5_PA_PMU + 0x0400) + +#define S5P_PA_SYSRAM 0x02020000 + +/* Constants below is only used in assembly because the DTS is not yet parsed */ In a subsequent patch?
Yes. It's used in patch 32.
Quoted 24 lines
Quoted 22 lines
xen/include/asm-arm/platforms/exynos5.h new file +22
-0+#ifdef __ASSEMBLY__ + +/* GIC Base Address */ +#define EXYNOS5_GIC_BASE_ADDRESS 0x10480000 + +/* Timer's frequency */ +#define EXYNOS5_TIMER_FREQUENCY (24 * 1000 * 1000)/* 24 MHz */ + +/* Arndale machine ID */ +#define MACH_TYPE_SMDK5250 3774 + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_ARM_PLATFORMS_EXYNOS5_H */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
Julien
PATCH v2 32/33 xen/arm: WORKAROUND Support kick cpus and switch to hypervisor for the exynos5
In reply to Julien GrallUse machine ID to know what is the current board. This value is only given to the first CPU by the bootloader.
When the exynos 5 starts, there is only one CPU up. Xen needs to start the secondary cpu. The latter boots in secure mode.
Theses modifications aim to be removed as soon as possible. It should be moved either in a platform specific boot-wrapper (which will be start before Xen), or in the bootloader (assuming U-Boot/Grub will support SMP).
Changes in v2:
- Add WORKAROUND keyword in the title
- Add fall-through comment when it's needed
- setup the spis with a while loop instead of a do-while loop
--- xen/arch/arm/arm32/head.S | 19 +++++++- xen/arch/arm/arm32/mode_switch.S | 75 +++++++++++++++++++++++------- xen/include/asm-arm/platforms/vexpress.h | 11 +++++ 3 files changed, 86 insertions(+), 19 deletions(-)
xen/arch/arm/arm32/head.S +18 -1
@@ -76,7 +76,7 @@ past_zImage: cpsid aif /* Disable all interrupts */ /* Save the bootloader arguments in less-clobberable registers */ - /* No need to save r1 == Unused ARM-linux machine type */ + mov r5, r1 /* r5: ARM-linux machine type */ mov r8, r2 /* r8 := DTB base address */ /* Find out where we are */
@@ -119,11 +119,25 @@ boot_cpu: bl putn PRINT(" booting -\r\n") #endif + /* Secondary CPUs doesn't have machine ID + * - Store machine ID on boot CPU + * - Load machine ID on secondary CPUs + * Machine ID is needed in kick_cpus and enter_hyp_mode */ + ldr r0, =machine_id /* VA of machine_id */ + add r0, r0, r10 /* PA of machine_id */ + teq r12, #0 + streq r5, [r0] /* On boot CPU save machine ID */ + ldrne r5, [r0] /* If non boot cpu r5 := machine ID */ /* Wake up secondary cpus */ teq r12, #0 bleq kick_cpus + PRINT("- Machine ID ") + mov r0, r5 + bl putn + PRINT(" -\r\n") + /* Check that this CPU has Hyp mode */ mrc CP32(r0, ID_PFR1) and r0, r0, #0xf000 /* Bits 12-15 define virt extensions */
@@ -403,6 +417,9 @@ putn: mov pc, lr #endif /* !EARLY_PRINTK */ +/* Place holder for machine ID */ +machine_id: .word 0x0 + /* * Local variables: * mode: ASM
xen/arch/arm/arm32/mode_switch.S +57 -18
125 lines not on this page · raw message
xen/include/asm-arm/platforms/vexpress.h +11 -0
@@ -32,6 +32,17 @@int vexpress_syscfg (int write,int function,int device,uint32_t *data);#endif +/* Constants below is only used in assembly because the DTS is not yet parsed */ +#ifdef __ASSEMBLY__ + +/* GIC base address */ +#define V2M_GIC_BASE_ADDRESS 0x2c000000 + +/* Timer's frequency */ +#define V2M_TIMER_FREQUENCY 0x5f5e100/* 100 Mhz */ + +#endif /* __ASSEMBLY__ */ +#endif /* __ASM_ARM_PLATFORMS_VEXPRESS_H */ /* * Local variables:
Signature · 1 line
Julien Grall
Re: [PATCH V2 32/33] xen/arm: WORKAROUND Support kick cpus and switch to hypervisor for the exynos5
Quoted 9 lines · Julien Grall
Use machine ID to know what is the current board. This value is only given to the first CPU by the bootloader.
When the exynos 5 starts, there is only one CPU up. Xen needs to start the secondary cpu. The latter boots in secure mode.
Theses modifications aim to be removed as soon as possible. It should be moved either in a platform specific boot-wrapper (which will be start before Xen), or in the bootloader (assuming U-Boot/Grub will support SMP).
With this proviso I'm OK with this change for 4.3, I'd like to see this gone for 4.4 though.
Quoted 1 line
Signed-off-by Julien Grall <[email protected]>
PATCH v2 33/33 xen/arm64: Remove hardcoded value for gic in assembly code
In reply to Julien Grall- arm64: use V2M_GIC_BASE_ADDRESS
- only expose GIC_*_ADDRESS to assembly. The C code uses base addresses provide by the device tree
Changes in v2:
- Remove stray gi"t diff"
--- xen/arch/arm/arm64/mode_switch.S | 7 ++++--- xen/include/asm-arm/config.h | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-)
xen/arch/arm/arm64/mode_switch.S +4 -3
@@ -21,6 +21,7 @@ #include <asm/config.h> #include <asm/page.h> #include <asm/asm_defns.h> +#include <asm/platforms/vexpress.h> /* Get up a CPU into EL2. Clobbers x0-x3. *
@@ -53,18 +54,18 @@ enter_el2_mode: */ cbnz x22, 1f - ldr x1, =(GIC_BASE_ADDRESS+GIC_DR_OFFSET) // GICD_CTLR + ldr x1, =(V2M_GIC_BASE_ADDRESS+GIC_DR_OFFSET) // GICD_CTLR mov w0, #3 // EnableGrp0 | EnableGrp1 str w0, [x1] -1: ldr x1, =(GIC_BASE_ADDRESS+GIC_DR_OFFSET+0x80) // GICD_IGROUPR +1: ldr x1, =(V2M_GIC_BASE_ADDRESS+GIC_DR_OFFSET+0x80) // GICD_IGROUPR mov w0, #~0 // Grp1 interrupts str w0, [x1], #4 b.ne 2f // Only local interrupts for secondary CPUs str w0, [x1], #4 str w0, [x1], #4 -2: ldr x1, =(GIC_BASE_ADDRESS+GIC_CR_OFFSET) // GICC_CTLR +2: ldr x1, =(V2M_GIC_BASE_ADDRESS+GIC_CR_OFFSET) // GICC_CTLR ldr w0, [x1] mov w0, #3 // EnableGrp0 | EnableGrp1 str w0, [x1]
xen/include/asm-arm/config.h +6 -2
@@ -141,12 +141,16 @@ extern unsigned long frametable_virt_end;#define watchdog_disable () ((void)0)#define watchdog_enable () ((void)0) -/* Board-specific: base address of GIC + its regs */ -#define GIC_BASE_ADDRESS 0x2c000000 +#ifdef __ASSEMBLY__ +/* Board-specific: regs base address for the GIC +* Theses constants are only intend to be used in assembly file +* because the DT is not yet parsed. +*/ #define GIC_DR_OFFSET 0x1000#define GIC_CR_OFFSET 0x2000#define GIC_HR_OFFSET 0x4000/* Guess work http://lists.infradead.org/pipermail/linux-arm-kernel/2011-September/064219.html */ #define GIC_VR_OFFSET 0x6000/* Virtual Machine CPU interface) */ +#endif /* __ASSEMBLY__ */ #endif /* __ARM_CONFIG_H__ */ /*
Signature · 1 line
Julien Grall
Quoted 7 lines
If you want to try this patch series you can clone:
git clone -b arm-v2git://xenbits.xen.org/people/julieng/xen-unstable.gitThe command line to compile Xen is the same as before. You just need to specify on Xen command line, via the device tree, which UART will be used for the console.
Quoted 8 lines
Feel free to test this branch during Xen test day. The wiki has been updated for the arndale board:
http://wiki.xen.org/wiki/Xen_ARM_with_Virtualization_Extensions/ArndaleIt's now based on:
- this patch series for Xen
- linux 3.9
Hello,
While I am testing on your new patch series on the Arndale Board, I have found some mismatching items between wiki and source code.
1. dts path problem:
from kernel 3.9 ( my guessing.. :) ), dtb file will be created in the
same directory with dts file: arch/arm/boot/dts/*.dtb.
However, in the wiki, it still describe dtb path is in arch/arm/boot/*.dtb.
2. early_printk uart:
In the branch name "arndale" from your linux tree
(git://xenbits.xen.org/people/julieng/linux-arm.git),exynos5250-arndale.dts describes "console=com1,dbgp com1=serial0" as a boot argument for early_printk.
However, in your newer patch series for XenARM,${xensrc}/drivers/char/arm-uart.c try to find console that has node name as "dtuart". So, I think it is required to modify "exynos5250-arndale.dts" file like:
- console=com1,dbgp com1=serial0
+console=dtuart dtuart=serial0
Please consider this matters.
Quoted 4 lines
Feel free to test this branch during the Xen test day on both the versatile express and the arndale board.
Cheers,
I am really enjoying to testing with your newly release patch series on the arndale board.
But, I am still facing some problems :( I will post the problem to the mailing list later.
Sincerely yours,
Gihun Jung
Quoted 12 lines · Gihun Jung
Quoted 12 lines
If you want to try this patch series you can clone:
git clone -b arm-v2git://xenbits.xen.org/people/julieng/xen-unstable.gitThe command line to compile Xen is the same as before. You just need to specify on Xen command line, via the device tree, which UART will be used for the console.
Feel free to test this branch during Xen test day. The wiki has been updated for the arndale board:
http://wiki.xen.org/wiki/Xen_ARM_with_Virtualization_Extensions/Arndale
Quoted 8 lines
Quoted 4 lines
It's now based on:
- this patch series for Xen
- linux 3.9Hello,
While I am testing on your new patch series on the Arndale Board, I have found some mismatching items between wiki and source code.
Hi,
Thansk for testing the arndale board with Xen!
Quoted 4 lines
1. dts path problem:
from kernel 3.9 ( my guessing.. :) ), dtb file will be created in the
same directory with dts file:arch/arm/boot/dts/*.dtb.
However, in the wiki, it still describe dtb path is inarch/arm/boot/*.dtb.
The wiki page has been updated.
Quoted 11 lines
2.
early_printkuart:
In the branch name "arndale" from your linux tree
(git://xenbits.xen.org/people/julieng/linux-arm.git),exynos5250-arndale.dtsdescribes "console=com1,dbgp com1=serial0" as a boot argument forearly_printk.
However, in your newer patch series for XenARM,${xensrc}/drivers/char/arm-uart.ctry to find console that has node name as "dtuart". So, I think it is required to modify "exynos5250-arndale.dts" file like:
- console=com1,dbgp com1=serial0
+console=dtuart dtuart=serial0
I have pushed a fix in the linux's tree commit "08d452d".
Cheers,
--
Julien Grall