Skip to contentSkip to conversation

ps3: add vuart support

PATCH In review Geoff Levand 3 participants 8 messages Dec 7, 2006 – Dec 9, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ps3: add vuart support

Adds support for the PS3 virtual UART (vuart). The vuart provides a bi-directional byte stream data link between logical partitions.

---

This is needed for the ps3 graphics driver and the ps3 power management support. Please apply.

 arch/powerpc/platforms/ps3/Kconfig |   11 
 drivers/ps3/Makefile               |    1 
 drivers/ps3/vuart.c                |  971 +++++++++++++++++++++++++++++++++++++
 drivers/ps3/vuart.h                |   94 +++
 4 files changed, 1077 insertions(+)
arch/powerpc/platforms/ps3/Kconfig +11 -0
@@ -40,4 +40,15 @@ config PS3_USE_LPAR_ADDR
 
 	  If you have any doubt, choose the default y.
 
+config PS3_VUART
+	depends on PPC_PS3
+	tristate "PS3 Virtual UART support"
+	default y
+	help
+	  Include support for the PS3 Virtual UART.
+
+	  This support is required for several system services
+	  including the System Manager and AV Settings.  In
+	  general, all users will say Y or M.
+
 endmenu
drivers/ps3/Makefile +1 -0
@@ -1 +1,2 @@
 obj-y += system-bus.o
+obj-$(CONFIG_PS3_VUART) += vuart.o
drivers/ps3/vuart.c new file +971 -0

971 lines not on this page · raw message

drivers/ps3/vuart.h new file +94 -0

94 lines not on this page · raw message

#1 lore raw

Adds support for the PS3 virtual UART (vuart). The vuart provides a bi-directional byte stream data link between logical partitions.

This is needed for the ps3 graphics driver and the ps3 power management support to be able to talk with the system policy module.

---

This is a resend that adds the forgotten update to ps3_defconfig.

This is needed for the ps3 graphics driver and the ps3 power management support. Please apply.

 arch/powerpc/configs/ps3_defconfig |   12 
 arch/powerpc/platforms/ps3/Kconfig |   11 
 drivers/ps3/Makefile               |    1 
 drivers/ps3/vuart.c                |  964 +++++++++++++++++++++++++++++++++++++
 drivers/ps3/vuart.h                |   94 +++
 5 files changed, 1076 insertions(+), 6 deletions(-)
arch/powerpc/configs/ps3_defconfig +1 -0
@@ -157,6 +159,7 @@ CONFIG_SPU_BASE=y
 CONFIG_PS3_HTAB_SIZE=20
 CONFIG_PS3_DYNAMIC_DMA=y
 CONFIG_PS3_USE_LPAR_ADDR=y
+CONFIG_PS3_VUART=y
 
 #
 # Kernel options
arch/powerpc/platforms/ps3/Kconfig +11 -0
@@ -40,4 +40,15 @@ config PS3_USE_LPAR_ADDR
 
 	  If you have any doubt, choose the default y.
 
+config PS3_VUART
+	depends on PPC_PS3
+	tristate "PS3 Virtual UART support"
+	default y
+	help
+	  Include support for the PS3 Virtual UART.
+
+	  This support is required for several system services
+	  including the System Manager and AV Settings.  In
+	  general, all users will say Y or M.
+
 endmenu
drivers/ps3/Makefile +1 -0
@@ -1 +1,2 @@
 obj-y += system-bus.o
+obj-$(CONFIG_PS3_VUART) += vuart.o
drivers/ps3/vuart.c new file +964 -0

964 lines not on this page · raw message

drivers/ps3/vuart.h new file +94 -0

94 lines not on this page · raw message

#2 lore raw
In reply to Geoff Levand
Quoted 2 lines · Geoff Levand

Adds support for the PS3 virtual UART (vuart). The vuart provides a bi-directional byte stream data link between logical partitions.

Looks good now, just a few minor comments:

drivers/ps3/vuart.c line 83

Quoted 5 lines
drivers/ps3/vuart.c new file +5 -0
+struct ports_bmp
+{
+	u64 status;
+	u64 unused[3];
+} __attribute__ ((packed));

Do you really want to have this structure packed? It will produce better code if it isn't.
For structure definitions, the common way is to write the opening braces in the same line as the name, i.e.

struct ports_bmp {
	...
};

drivers/ps3/vuart.c line 105

Quoted 4 lines
drivers/ps3/vuart.c new file +4 -0
+	default:
+		BUG();
+		*port_number = UINT_MAX;
+		return -EINVAL;

No need to return after BUG(), the process is dead anyway. It should probably be WARN_ON(1) instead of BUG().

drivers/ps3/vuart.c line 246

Quoted 12 lines
drivers/ps3/vuart.c new file +12 -0
+static int get_rx_bytes_waiting(struct ps3_vuart_port_device *dev,
+	unsigned long *bytes_waiting)
+{
+	int result = lv1_get_virtual_uart_param(dev->port_number,
+		PARAM_RX_BYTES, bytes_waiting);
+
+	if (result)
+		pr_debug("%s:%d: port_%u: rx_bytes failed: %s\n", __func__,
+			__LINE__, dev->port_number, ps3_result(result));
+
+	pr_debug("%s:%d: port_%u: %lxh\n", __func__, __LINE__,
+		dev->port_number, *bytes_waiting);

In places where you carry around a device pointer (probably most places), it's nicer to use dev_dbg instead of pr_debug.

drivers/ps3/vuart.c line 338

Quoted 2 lines
drivers/ps3/vuart.c new file +2 -0
+static int raw_write(struct ps3_vuart_port_device *dev, const void* buf,
+	unsigned int bytes, unsigned long *bytes_written)

I'd give the function names a prefix, e.g. ps3_vuart_raw_write here, even if they are static. This makes reading oops messages easier if you are not familiar with the code, raw_write is a pretty common function name.

	Arnd <><
#3 lore raw
Quoted 6 lines · Arnd Bergmann
Quoted 2 lines · Geoff Levand

Adds support for the PS3 virtual UART (vuart). The vuart provides a bi-directional byte stream data link between logical partitions.

Looks good now, just a few minor comments:

Quoted 8 lines

drivers/ps3/vuart.c line 83

Quoted 5 lines
drivers/ps3/vuart.c new file +5 -0
+struct ports_bmp
+{
+	u64 status;
+	u64 unused[3];
+} __attribute__ ((packed));

Do you really want to have this structure packed? It will produce better code if it isn't.

Yes, it is a little obscure in the code, but the address of the ports_bmp instance is passed to ps3_alloc_vuart_irq(), which in turn calls lv1_configure_virtual_uart_irq(). The HV (actually the vuart service in the policy module) uses this as a 256 bit bitmap to indicate the interrupt status of the ports. The system supports 256 ports, but currently just two ports, 1 and 3, are used, so I took advantage of that to simplify the code and just used the first word of the bitmap.

I'll post an updated patch to address your other comments.

-Geoff

#4 lore raw
Quoted 16 lines · Geoff Levand
Quoted 6 lines · Arnd Bergmann
Quoted 2 lines · Geoff Levand

Adds support for the PS3 virtual UART (vuart). The vuart provides a bi-directional byte stream data link between logical partitions.

Looks good now, just a few minor comments:

Quoted 8 lines

drivers/ps3/vuart.c line 83

Quoted 5 lines
drivers/ps3/vuart.c new file +5 -0
+struct ports_bmp
+{
+	u64 status;
+	u64 unused[3];
+} __attribute__ ((packed));

Do you really want to have this structure packed? It will produce better code if it isn't.

Quoted 7 lines

Yes, it is a little obscure in the code, but the address of the ports_bmp instance is passed to ps3_alloc_vuart_irq(), which in turn calls lv1_configure_virtual_uart_irq(). The HV (actually the vuart service in the policy module) uses this as a 256 bit bitmap to indicate the interrupt status of the ports. The system supports 256 ports, but currently just two ports, 1 and 3, are used, so I took advantage of that to simplify the code and just used the first word of the bitmap.

I think Arnd meant that the `__attribute__ ((packed))' is useless for structs containing u64 members only. The natural alignment of 64-bit values is on a 64-bit boundary, so there won't be padding anyway.

IIRC, someone (davem?) told me a long time ago gcc _always_ uses byte-accesses when accessing members in a struct with __attribute__ ((packed))', since the members may be unaligned. Even when the values are perfectly aligned. So it's better not to use __attribute__ ((packed))' unless it's really needed.

Why is there a comment about `Needs 4 byte alignment.'? The way it's used, it will always be 8-byte aligned anyway.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- Sony Network and Software Technology Center Europe (NSCE) [email protected] ------- The Corporate Village, Da Vincilaan 7-D1 Voice +32-2-7008453 Fax +32-2-7008622 ---------------- B-1935 Zaventem, Belgium

#5 lore raw
Quoted 29 lines · Geert Uytterhoeven
Quoted 16 lines · Geoff Levand
Quoted 6 lines · Arnd Bergmann
Quoted 2 lines · Geoff Levand

Adds support for the PS3 virtual UART (vuart). The vuart provides a bi-directional byte stream data link between logical partitions.

Looks good now, just a few minor comments:

Quoted 8 lines

drivers/ps3/vuart.c line 83

Quoted 5 lines
drivers/ps3/vuart.c new file +5 -0
+struct ports_bmp
+{
+	u64 status;
+	u64 unused[3];
+} __attribute__ ((packed));

Do you really want to have this structure packed? It will produce better code if it isn't.

Quoted 7 lines

Yes, it is a little obscure in the code, but the address of the ports_bmp instance is passed to ps3_alloc_vuart_irq(), which in turn calls lv1_configure_virtual_uart_irq(). The HV (actually the vuart service in the policy module) uses this as a 256 bit bitmap to indicate the interrupt status of the ports. The system supports 256 ports, but currently just two ports, 1 and 3, are used, so I took advantage of that to simplify the code and just used the first word of the bitmap.

I think Arnd meant that the `__attribute__ ((packed))' is useless for structs containing u64 members only. The natural alignment of 64-bit values is on a 64-bit boundary, so there won't be padding anyway.

Quoted 7 lines

IIRC, someone (davem?) told me a long time ago gcc _always_ uses byte-accesses when accessing members in a struct with __attribute__ ((packed))', since the members may be unaligned. Even when the values are perfectly aligned. So it's better not to use __attribute__ ((packed))' unless it's really needed.

Why is there a comment about `Needs 4 byte alignment.'? The way it's used, it will always be 8-byte aligned anyway.

After some discussion on IRC I understand that my comment above is in error.

The packed attribute forces both the structure members and the structure instance to have 1-byte alignment, so it will not have an 8-byte alignment, but a 1-byte. In the usage here though, the ports_bmp instance follows an aligned long, so it by chance starts at 8-byte aligned address.

The 4-byte alignment is a requirement of the HV, so I just noted that in the comment. I'll change the comment to be more clear.

-Geoff

#6 lore raw
In reply to Geoff Levand

Adds support for the PS3 virtual UART (vuart). The vuart provides a bi-directional byte stream data link between logical partitions.

This is needed for the ps3 graphics driver and the ps3 power control support to be able to communicate with the lv1 policy module.

---

Paul,

This is version #2. It addresses all previous comments. Please consider for inclusion in 2.6.20.

-Geoff

 arch/powerpc/configs/ps3_defconfig |    1 
 arch/powerpc/platforms/ps3/Kconfig |   11 
 drivers/ps3/Makefile               |    1 
 drivers/ps3/vuart.c                |  965 +++++++++++++++++++++++++++++++++++++
 drivers/ps3/vuart.h                |   94 +++
 5 files changed, 1072 insertions(+)
arch/powerpc/configs/ps3_defconfig +1 -0
@@ -157,6 +157,7 @@ CONFIG_SPU_BASE=y
 CONFIG_PS3_HTAB_SIZE=20
 CONFIG_PS3_DYNAMIC_DMA=y
 CONFIG_PS3_USE_LPAR_ADDR=y
+CONFIG_PS3_VUART=y
 
 #
 # Kernel options
arch/powerpc/platforms/ps3/Kconfig +11 -0
@@ -40,4 +40,15 @@ config PS3_USE_LPAR_ADDR
 
 	  If you have any doubt, choose the default y.
 
+config PS3_VUART
+	depends on PPC_PS3
+	bool "PS3 Virtual UART support"
+	default y
+	help
+	  Include support for the PS3 Virtual UART.
+
+	  This support is required for several system services
+	  including the System Manager and AV Settings.  In
+	  general, all users will say Y.
+
 endmenu
drivers/ps3/Makefile +1 -0
@@ -1 +1,2 @@
 obj-y += system-bus.o
+obj-$(CONFIG_PS3_VUART) += vuart.o
drivers/ps3/vuart.c new file +965 -0

965 lines not on this page · raw message

drivers/ps3/vuart.h new file +94 -0

94 lines not on this page · raw message

Acked-by
#7 lore raw
Quoted 8 lines · Geoff Levand

Adds support for the PS3 virtual UART (vuart). =A0The vuart provides a bi-directional byte stream data link between logical partitions. =20
This is needed for the ps3 graphics driver and the ps3 power control support to be able to communicate with the lv1 policy module.
=20