Skip to contentSkip to conversation

PCC: Platform Communication Channel

PATCH Superseded Ashwin Chaugule 2 participants 7 messages Sep 3, 2014

Subsystems (3)

v4 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v4 cover PCC: Platform Communication Channel

Changes since V3:
- Added PCC helper functions to work around "struct device" limitations.
- PCC driver changes to work with PCC specific Mailbox helpers.

Changes since V2:
- Rebased on top of git://git.linaro.org/landing-teams/working/fujitsu/integration.git

	branch mailbox-for-3.17

- Added PCC API to mailbox framework as per Arnd's suggestion to allow usage without ACPI.

Changes since V1:
- Integration with Mailbox framework - https://lkml.org/lkml/2014/5/15/49

This patchset adds support for the PCC (Platform Communication Channel) interface as described in the current ACPI 5.0 spec. See Section 14 of the ACPI spec - http://acpi.info/DOWNLOADS/ACPI_5_Errata%20A.pdf for more details on how PCC works.

In brief PCC is a generic means for PCC clients, to talk to the firmware. The PCC register space is typically memory mapped IO and uses a doorbell mechanism to communicate synchronously from the OS to the firmware. The PCC driver is completely agnostic to the protocol implemented by the PCC clients. It only implements the enumeration of PCC channels and the low level transport mechanism and leaves the rest to the PCC clients.

The PCC is meant to be useable in the future by clients such as CPPC (Collaborative Processor Performance Control), RAS (Reliability, Availability and Serviceability) and MPST (Memory Power State Tables) and possibly others.

Ashwin Chaugule (4):
Mailbox: Prepare to add PCC Mailbox support
Mailbox: Add PCC Mailbox Helper functions
Mailbox: Add support for Platform Communication Channel PCC test

 drivers/mailbox/Kconfig            |  19 +++
 drivers/mailbox/Makefile           |   4 +
 drivers/mailbox/mailbox.c          |  10 +-
 drivers/mailbox/pcc-test.c         | 208 +++++++++++++++++++++++++++++++
 drivers/mailbox/pcc.c              | 245 +++++++++++++++++++++++++++++++++++++
 drivers/mailbox/pcc_mailbox.c      | 136 ++++++++++++++++++++
 include/linux/mailbox_controller.h |   4 +
 7 files changed, 619 insertions(+), 7 deletions(-)
 create mode 100644 drivers/mailbox/pcc-test.c
 create mode 100644 drivers/mailbox/pcc.c
 create mode 100644 drivers/mailbox/pcc_mailbox.c
Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 1/4 Mailbox: Prepare to add PCC Mailbox support

Restructure code to allow extending the Mailbox functionality for PCC (Platform Communication Channel) as a Mailbox.

---
 drivers/mailbox/mailbox.c          | 10 +++-------
 include/linux/mailbox_controller.h |  4 ++++
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/mailbox/mailbox.c +3 -7
index 63ecc17..5866412 100644
@@ -21,12 +21,8 @@
 #include <linux/mailbox_client.h>
 #include <linux/mailbox_controller.h>
 
-#define TXDONE_BY_IRQ	BIT(0) /* controller has remote RTR irq */
-#define TXDONE_BY_POLL	BIT(1) /* controller can read status of last TX */
-#define TXDONE_BY_ACK	BIT(2) /* S/W ACK recevied by Client ticks the TX */
-
-static LIST_HEAD(mbox_cons);
-static DEFINE_MUTEX(con_mutex);
+LIST_HEAD(mbox_cons);
+DEFINE_MUTEX(con_mutex);
 
 static int add_to_rbuf(struct mbox_chan *chan, void *mssg)
 {
@@ -107,7 +103,7 @@ static void tx_tick(struct mbox_chan *chan, int r)
 		complete(&chan->tx_complete);
 }
 
-static void poll_txdone(unsigned long data)
+void poll_txdone(unsigned long data)
 {
 	struct mbox_controller *mbox = (struct mbox_controller *)data;
 	bool txdone, resched = false;
include/linux/mailbox_controller.h +4 -0
index 9ee195b..956cc06 100644
@@ -15,6 +15,10 @@
 
 struct mbox_chan;
 
+#define TXDONE_BY_IRQ	BIT(0) /* controller has remote RTR irq */
+#define TXDONE_BY_POLL	BIT(1) /* controller can read status of last TX */
+#define TXDONE_BY_ACK	BIT(2) /* S/W ACK recevied by Client ticks the TX */
+
 /**
  * struct mbox_chan_ops - methods to control mailbox channels
  * @send_data:	The API asks the MBOX controller driver, in atomic
Signature · 1 line
1.9.1
#2 lore raw

PATCH v4 2/4 Mailbox: Add PCC Mailbox Helper functions

In reply to Ashwin Chaugule

The current Mailbox framework expects the Mailbox controller and clients to be backed by Struct devices and uses a DT specific matching method for clients to lookup channels in a controller.

The helper functions introduced here allow the PCC Mailbox as defined in the ACPI 5.0+ specification to workaround these expectations and continue to work with the rest of the Mailbox framework even in the case where PCC is defined using DT bindings.

---
 drivers/mailbox/Kconfig       |   8 +++
 drivers/mailbox/Makefile      |   2 +
 drivers/mailbox/pcc_mailbox.c | 136 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644 drivers/mailbox/pcc_mailbox.c
drivers/mailbox/Kconfig +8 -0
index c8b5c13..0e7be60 100644
@@ -50,4 +50,12 @@ config OMAP_MBOX_KFIFO_SIZE
 	  Specify the default size of mailbox's kfifo buffers (bytes).
 	  This can also be changed at runtime (via the mbox_kfifo_size
 	  module parameter).
+
+config PCC_MAILBOX_API
+	bool "Platform Communication Channel Mailbox API"
+	help
+		This contains helper functions for registering a PCC mailbox
+		with the generic Mailbox framework and for looking up a PCC
+		channel.
+
 endif
drivers/mailbox/Makefile +2 -0
index 2fa343a..3a4f94d 100644
@@ -9,3 +9,5 @@ obj-$(CONFIG_OMAP1_MBOX)	+= mailbox_omap1.o
 mailbox_omap1-objs		:= mailbox-omap1.o
 obj-$(CONFIG_OMAP2PLUS_MBOX)	+= mailbox_omap2.o
 mailbox_omap2-objs		:= mailbox-omap2.o
+
+obj-$(CONFIG_PCC_MAILBOX_API) += pcc_mailbox.o
drivers/mailbox/pcc_mailbox.c new file +136 -0

136 lines not on this page · raw message

Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH v4 2/4] Mailbox: Add PCC Mailbox Helper functions

Quoted 10 lines · On Wednesday 03 September 2014 15:38:57 Ashwin Chaugule wrote:

The current Mailbox framework expects the Mailbox controller and clients to be backed by Struct devices and uses a DT specific matching method for clients to lookup channels in a controller.

The helper functions introduced here allow the PCC Mailbox as defined in the ACPI 5.0+ specification to workaround these expectations and continue to work with the rest of the Mailbox framework even in the case where PCC is defined using DT bindings.

I think the general concept makes sense, but the split between files is not good in this version:

Quoted 13 lines
---
 drivers/mailbox/Kconfig       |   8 +++
 drivers/mailbox/Makefile      |   2 +
 drivers/mailbox/pcc_mailbox.c | 136 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644 drivers/mailbox/pcc_mailbox.c
drivers/mailbox/Kconfig +0 -0
index c8b5c13..0e7be60 100644
@@ -50,4 +50,12 @@ config OMAP_MBOX_KFIFO_SIZE
 	  Specify the default size of mailbox's kfifo buffers (bytes).

drivers/mailbox/Kconfig config OMAP_MBOX_KFIFO_SIZE · line 60

Quoted 10 lines
drivers/mailbox/Kconfig +8 -0
 	  This can also be changed at runtime (via the mbox_kfifo_size
 	  module parameter).
+
+config PCC_MAILBOX_API
+	bool "Platform Communication Channel Mailbox API"
+	help
+		This contains helper functions for registering a PCC mailbox
+		with the generic Mailbox framework and for looking up a PCC
+		channel.
+

I might be missing something, but I see no reason to have separate Kconfig symbols for the API and the driver, since you can't really have one without the other.

drivers/mailbox/Kconfig config OMAP_MBOX_KFIFO_SIZE

Quoted 5 lines
drivers/mailbox/Kconfig +5 -0
+
+extern struct list_head mbox_cons;
+extern struct mutex con_mutex;
+extern void mbox_free_channel(struct mbox_chan *chan);
+extern void poll_txdone(unsigned long data);

This part is the main issue: you should never declare 'extern' functions or data structures in a .c file. They are the interface between two files and need to be in a header file that is included by both of them.

It's also bad style to make internal data structures of one driver or subsystem available to other drivers, those should go through some form of accessor function. Note that you are currently putting those four identifiers into the global kernel namespace, where they might conflict with any driver that has a local 'poll_txdone' or 'con_mutex' symbol, which is not that unlikely.

drivers/mailbox/Kconfig

Quoted 12 lines
drivers/mailbox/Kconfig +12 -0
+static struct mbox_controller *pcc_mbox;
+
+struct mbox_chan *pcc_mbox_request_channel(struct mbox_client *cl, int index)
+{
+	struct mbox_chan *chan;
+	unsigned long flags;
+	int ret;
+
+	if (!pcc_mbox) {
+		pr_err("PCC Mailbox not found.\n");
+		return ERR_PTR(-ENODEV);
+	}

(minor comment)
It's better to use dev_err whenever you can.

drivers/mailbox/Kconfig

Quoted 2 lines
drivers/mailbox/Kconfig +2 -0
+
+	mutex_lock(&con_mutex);

What do you need the mutex for in this function? The only thing I see that might need to be protected is the pointer access above, but that is outside of the mutex.

drivers/mailbox/Kconfig

Quoted 3 lines
drivers/mailbox/Kconfig +3 -0
+int pcc_mbox_controller_register(struct mbox_controller *mbox)
+{
+	int i, txdone;

Why can't you just call the normal registration function?

The pcc mailbox will nor be reachable afterwards through the normal mailbox API, but you already have the pointer in the driver from patch 3, so if you just move the pcc_mbox_request_channel/pcc_mbox_free_channel into drivers/mailbox/pcc.c and register the device as normal, this should become unnecessary.

Arnd

#4 lore raw

Re: [PATCH v4 2/4] Mailbox: Add PCC Mailbox Helper functions

Quoted 89 lines · Arnd Bergmann
Quoted 10 lines · On Wednesday 03 September 2014 15:38:57 Ashwin Chaugule wrote:

The current Mailbox framework expects the Mailbox controller and clients to be backed by Struct devices and uses a DT specific matching method for clients to lookup channels in a controller.

The helper functions introduced here allow the PCC Mailbox as defined in the ACPI 5.0+ specification to workaround these expectations and continue to work with the rest of the Mailbox framework even in the case where PCC is defined using DT bindings.

I think the general concept makes sense, but the split between files is not good in this version:

Quoted 13 lines
---
 drivers/mailbox/Kconfig       |   8 +++
 drivers/mailbox/Makefile      |   2 +
 drivers/mailbox/pcc_mailbox.c | 136 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644 drivers/mailbox/pcc_mailbox.c
drivers/mailbox/Kconfig +0 -0
index c8b5c13..0e7be60 100644
@@ -50,4 +50,12 @@ config OMAP_MBOX_KFIFO_SIZE
        Specify the default size of mailbox's kfifo buffers (bytes).

drivers/mailbox/Kconfig config OMAP_MBOX_KFIFO_SIZE · line 60

Quoted 10 lines
drivers/mailbox/Kconfig +8 -0
        This can also be changed at runtime (via the mbox_kfifo_size
        module parameter).
+
+config PCC_MAILBOX_API
+     bool "Platform Communication Channel Mailbox API"
+     help
+             This contains helper functions for registering a PCC mailbox
+             with the generic Mailbox framework and for looking up a PCC
+             channel.
+

I might be missing something, but I see no reason to have separate Kconfig symbols for the API and the driver, since you can't really have one without the other.

drivers/mailbox/Kconfig config OMAP_MBOX_KFIFO_SIZE

Quoted 5 lines
drivers/mailbox/Kconfig +5 -0
+
+extern struct list_head mbox_cons;
+extern struct mutex con_mutex;
+extern void mbox_free_channel(struct mbox_chan *chan);
+extern void poll_txdone(unsigned long data);

This part is the main issue: you should never declare 'extern' functions or data structures in a .c file. They are the interface between two files and need to be in a header file that is included by both of them.

It's also bad style to make internal data structures of one driver or subsystem available to other drivers, those should go through some form of accessor function. Note that you are currently putting those four identifiers into the global kernel namespace, where they might conflict with any driver that has a local 'poll_txdone' or 'con_mutex' symbol, which is not that unlikely.

drivers/mailbox/Kconfig

Quoted 12 lines
drivers/mailbox/Kconfig +12 -0
+static struct mbox_controller *pcc_mbox;
+
+struct mbox_chan *pcc_mbox_request_channel(struct mbox_client *cl, int index)
+{
+     struct mbox_chan *chan;
+     unsigned long flags;
+     int ret;
+
+     if (!pcc_mbox) {
+             pr_err("PCC Mailbox not found.\n");
+             return ERR_PTR(-ENODEV);
+     }

(minor comment)
It's better to use dev_err whenever you can.

drivers/mailbox/Kconfig

Quoted 2 lines
drivers/mailbox/Kconfig +2 -0
+
+     mutex_lock(&con_mutex);

What do you need the mutex for in this function? The only thing I see that might need to be protected is the pointer access above, but that is outside of the mutex.

drivers/mailbox/Kconfig

Quoted 3 lines
drivers/mailbox/Kconfig +3 -0
+int pcc_mbox_controller_register(struct mbox_controller *mbox)
+{
+     int i, txdone;

Why can't you just call the normal registration function?

Quoted 6 lines

The pcc mailbox will nor be reachable afterwards through the normal mailbox API, but you already have the pointer in the driver from patch 3, so if you just move the pcc_mbox_request_channel/pcc_mbox_free_channel into drivers/mailbox/pcc.c and register the device as normal, this should become unnecessary.

hmm. I like the idea of merging this with pcc.c instead. I'll spin another version soon.

Thanks,
Ashwin

#5 lore raw

PATCH v4 3/4 Mailbox: Add support for Platform Communication Channel

In reply to Ashwin Chaugule

ACPI 5.0+ spec defines a generic mode of communication between the OS and a platform such as the BMC. This medium (PCC) is typically used by CPPC (ACPI CPU Performance management), RAS (ACPI reliability protocol) and MPST (ACPI Memory power states).

This patch adds PCC support as a Mailbox Controller.

---
 drivers/mailbox/Kconfig  |  11 +++
 drivers/mailbox/Makefile |   2 +
 drivers/mailbox/pcc.c    | 245 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 258 insertions(+)
 create mode 100644 drivers/mailbox/pcc.c
drivers/mailbox/Kconfig +11 -0
index 0e7be60..4a73707 100644
@@ -58,4 +58,15 @@ config PCC_MAILBOX_API
 		with the generic Mailbox framework and for looking up a PCC
 		channel.
 
+config PCC
+	bool "Platform Communication Channel"
+	depends on ACPI && PCC_MAILBOX_API
+	help
+		ACPI 5.0+ spec defines a generic mode of communication
+		between the OS and a platform such as the BMC. This medium
+		(PCC) is typically used by CPPC (ACPI CPU Performance management),
+		RAS (ACPI reliability protocol) and MPST (ACPI Memory power
+		states). Select this driver if your platform implements the
+		PCC clients mentioned above.
+
 endif
drivers/mailbox/Makefile +2 -0
index 3a4f94d..e746e26 100644
@@ -11,3 +11,5 @@ obj-$(CONFIG_OMAP2PLUS_MBOX)	+= mailbox_omap2.o
 mailbox_omap2-objs		:= mailbox-omap2.o
 
 obj-$(CONFIG_PCC_MAILBOX_API) += pcc_mailbox.o
+
+obj-$(CONFIG_PCC) += pcc.o
drivers/mailbox/pcc.c new file +245 -0

245 lines not on this page · raw message

Signature · 1 line
1.9.1
#6 lore raw

PATCH v4 4/4 PCC test

In reply to Ashwin Chaugule

Not for upstreaming. This is only to show how the PCC driver was tested.

echo 2 > /proc/pcc_test [ to get the PCC base address from the PCCT ]

echo 1 > /proc/pcc_test [ to trigger a PCC write ]

echo 0 > /proc/pcc_test [ to trigger a PCC read ]

dmesg shows the output.

---
 drivers/mailbox/Makefile   |   2 +-
 drivers/mailbox/pcc-test.c | 208 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 209 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mailbox/pcc-test.c
drivers/mailbox/Makefile +1 -1
index e746e26..cd3f263 100644
@@ -12,4 +12,4 @@ mailbox_omap2-objs		:= mailbox-omap2.o
 
 obj-$(CONFIG_PCC_MAILBOX_API) += pcc_mailbox.o
 
-obj-$(CONFIG_PCC) += pcc.o
+obj-$(CONFIG_PCC) += pcc.o pcc-test.o
drivers/mailbox/pcc-test.c new file +208 -0

208 lines not on this page · raw message

Signature · 1 line
1.9.1