* [PATCH v4 1/4] Mailbox: Prepare to add PCC Mailbox support
2014-09-03 19:38 [PATCH v4 0/4] PCC: Platform Communication Channel Ashwin Chaugule
@ 2014-09-03 19:38 ` Ashwin Chaugule
2014-09-03 19:38 ` [PATCH v4 2/4] Mailbox: Add PCC Mailbox Helper functions Ashwin Chaugule
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Ashwin Chaugule @ 2014-09-03 19:38 UTC (permalink / raw)
To: arnd; +Cc: linux-acpi, linaro-acpi, rjw, broonie, Ashwin Chaugule
Restructure code to allow extending the Mailbox
functionality for PCC (Platform Communication Channel)
as a Mailbox.
Signed-off-by: Ashwin Chaugule <ashwin.chaugule@linaro.org>
---
drivers/mailbox/mailbox.c | 10 +++-------
include/linux/mailbox_controller.h | 4 ++++
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index 63ecc17..5866412 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -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;
diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h
index 9ee195b..956cc06 100644
--- a/include/linux/mailbox_controller.h
+++ b/include/linux/mailbox_controller.h
@@ -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
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v4 2/4] Mailbox: Add PCC Mailbox Helper functions
2014-09-03 19:38 [PATCH v4 0/4] PCC: Platform Communication Channel Ashwin Chaugule
2014-09-03 19:38 ` [PATCH v4 1/4] Mailbox: Prepare to add PCC Mailbox support Ashwin Chaugule
@ 2014-09-03 19:38 ` Ashwin Chaugule
2014-09-03 19:56 ` Arnd Bergmann
2014-09-03 19:38 ` [PATCH v4 3/4] Mailbox: Add support for Platform Communication Channel Ashwin Chaugule
2014-09-03 19:38 ` [PATCH v4 4/4] PCC test Ashwin Chaugule
3 siblings, 1 reply; 7+ messages in thread
From: Ashwin Chaugule @ 2014-09-03 19:38 UTC (permalink / raw)
To: arnd; +Cc: linux-acpi, linaro-acpi, rjw, broonie, 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.
Signed-off-by: Ashwin Chaugule <ashwin.chaugule@linaro.org>
---
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
diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
index c8b5c13..0e7be60 100644
--- a/drivers/mailbox/Kconfig
+++ b/drivers/mailbox/Kconfig
@@ -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
diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile
index 2fa343a..3a4f94d 100644
--- a/drivers/mailbox/Makefile
+++ b/drivers/mailbox/Makefile
@@ -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
diff --git a/drivers/mailbox/pcc_mailbox.c b/drivers/mailbox/pcc_mailbox.c
new file mode 100644
index 0000000..1454b67
--- /dev/null
+++ b/drivers/mailbox/pcc_mailbox.c
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2014 Linaro Ltd.
+ * Author: Ashwin Chaugule <ashwin.chaugule@linaro.org>
+ *
+ * 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 <linux/interrupt.h>
+#include <linux/spinlock.h>
+#include <linux/mutex.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/mailbox_controller.h>
+#include <linux/mailbox_client.h>
+
+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);
+
+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);
+ }
+
+ mutex_lock(&con_mutex);
+ /*
+ * Each PCC Subspace is a Mailbox Channel.
+ * The PCC Clients get their PCC Subspace ID
+ * from their own tables and pass it here.
+ * This returns a pointer to the PCC subspace
+ * for the Client to operate on.
+ */
+ chan = &pcc_mbox->chans[index];
+
+ if (!chan || chan->cl || !try_module_get(pcc_mbox->dev->driver->owner)) {
+ pr_err("%s: PCC mailbox not free\n", __func__);
+ mutex_unlock(&con_mutex);
+ return ERR_PTR(-EBUSY);
+ }
+
+ spin_lock_irqsave(&chan->lock, flags);
+ chan->msg_free = 0;
+ chan->msg_count = 0;
+ chan->active_req = NULL;
+ chan->cl = cl;
+ init_completion(&chan->tx_complete);
+
+ if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone)
+ chan->txdone_method |= TXDONE_BY_ACK;
+
+ spin_unlock_irqrestore(&chan->lock, flags);
+
+ mutex_unlock(&con_mutex);
+ return chan;
+}
+EXPORT_SYMBOL_GPL(pcc_mbox_request_channel);
+
+void pcc_mbox_free_channel(struct mbox_chan *chan)
+{
+ unsigned long flags;
+
+ if (!chan || !chan->cl)
+ return;
+
+ spin_lock_irqsave(&chan->lock, flags);
+ chan->cl = NULL;
+ chan->active_req = NULL;
+ if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK))
+ chan->txdone_method = TXDONE_BY_POLL;
+
+ module_put(chan->mbox->dev->driver->owner);
+ spin_unlock_irqrestore(&chan->lock, flags);
+}
+EXPORT_SYMBOL_GPL(pcc_mbox_free_channel);
+
+int pcc_mbox_controller_register(struct mbox_controller *mbox)
+{
+ int i, txdone;
+
+ /* Sanity check */
+ if (!mbox || !mbox->dev || !mbox->ops || !mbox->num_chans)
+ return -EINVAL;
+
+ if (mbox->txdone_irq)
+ txdone = TXDONE_BY_IRQ;
+ else if (mbox->txdone_poll)
+ txdone = TXDONE_BY_POLL;
+ else /* It has to be ACK then */
+ txdone = TXDONE_BY_ACK;
+
+ if (txdone == TXDONE_BY_POLL) {
+ mbox->poll.function = &poll_txdone;
+ mbox->poll.data = (unsigned long)mbox;
+ init_timer(&mbox->poll);
+ }
+
+ for (i = 0; i < mbox->num_chans; i++) {
+ struct mbox_chan *chan = &mbox->chans[i];
+
+ chan->cl = NULL;
+ chan->mbox = mbox;
+ chan->txdone_method = txdone;
+ spin_lock_init(&chan->lock);
+ }
+
+ mutex_lock(&con_mutex);
+ list_add_tail(&mbox->node, &mbox_cons);
+ /*
+ * Store this so we avoid digging for a PCC mbox in
+ * the Channel lookup.
+ */
+ pcc_mbox = mbox;
+ mutex_unlock(&con_mutex);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pcc_mbox_controller_register);
+
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v4 2/4] Mailbox: Add PCC Mailbox Helper functions
2014-09-03 19:38 ` [PATCH v4 2/4] Mailbox: Add PCC Mailbox Helper functions Ashwin Chaugule
@ 2014-09-03 19:56 ` Arnd Bergmann
2014-09-03 20:06 ` Ashwin Chaugule
0 siblings, 1 reply; 7+ messages in thread
From: Arnd Bergmann @ 2014-09-03 19:56 UTC (permalink / raw)
To: Ashwin Chaugule; +Cc: linux-acpi, linaro-acpi, rjw, broonie
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.
>
> Signed-off-by: Ashwin Chaugule <ashwin.chaugule@linaro.org>
I think the general concept makes sense, but the split between files
is not good in this version:
> ---
> 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
>
> diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
> index c8b5c13..0e7be60 100644
> --- a/drivers/mailbox/Kconfig
> +++ b/drivers/mailbox/Kconfig
> @@ -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.
> +
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.
> +
> +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.
> +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.
> +
> + 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.
> +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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v4 2/4] Mailbox: Add PCC Mailbox Helper functions
2014-09-03 19:56 ` Arnd Bergmann
@ 2014-09-03 20:06 ` Ashwin Chaugule
0 siblings, 0 replies; 7+ messages in thread
From: Ashwin Chaugule @ 2014-09-03 20:06 UTC (permalink / raw)
To: Arnd Bergmann
Cc: linux acpi, linaro-acpi@lists.linaro.org, Rafael J. Wysocki,
Mark Brown
On 3 September 2014 15:56, Arnd Bergmann <arnd@arndb.de> wrote:
> 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.
>>
>> Signed-off-by: Ashwin Chaugule <ashwin.chaugule@linaro.org>
>
> I think the general concept makes sense, but the split between files
> is not good in this version:
>
>> ---
>> 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
>>
>> diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
>> index c8b5c13..0e7be60 100644
>> --- a/drivers/mailbox/Kconfig
>> +++ b/drivers/mailbox/Kconfig
>> @@ -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.
>> +
>
> 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.
>
>> +
>> +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.
>
>> +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.
>
>> +
>> + 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.
>
>> +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.
hmm. I like the idea of merging this with pcc.c instead. I'll spin
another version soon.
Thanks,
Ashwin
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4 3/4] Mailbox: Add support for Platform Communication Channel
2014-09-03 19:38 [PATCH v4 0/4] PCC: Platform Communication Channel Ashwin Chaugule
2014-09-03 19:38 ` [PATCH v4 1/4] Mailbox: Prepare to add PCC Mailbox support Ashwin Chaugule
2014-09-03 19:38 ` [PATCH v4 2/4] Mailbox: Add PCC Mailbox Helper functions Ashwin Chaugule
@ 2014-09-03 19:38 ` Ashwin Chaugule
2014-09-03 19:38 ` [PATCH v4 4/4] PCC test Ashwin Chaugule
3 siblings, 0 replies; 7+ messages in thread
From: Ashwin Chaugule @ 2014-09-03 19:38 UTC (permalink / raw)
To: arnd; +Cc: linux-acpi, linaro-acpi, rjw, broonie, 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.
Signed-off-by: Ashwin Chaugule <ashwin.chaugule@linaro.org>
---
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
diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
index 0e7be60..4a73707 100644
--- a/drivers/mailbox/Kconfig
+++ b/drivers/mailbox/Kconfig
@@ -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
diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile
index 3a4f94d..e746e26 100644
--- a/drivers/mailbox/Makefile
+++ b/drivers/mailbox/Makefile
@@ -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
diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c
new file mode 100644
index 0000000..54712b6
--- /dev/null
+++ b/drivers/mailbox/pcc.c
@@ -0,0 +1,245 @@
+/*
+ * Copyright (C) 2014 Linaro Ltd.
+ * Author: Ashwin Chaugule <ashwin.chaugule@linaro.org>
+ *
+ * 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 <linux/acpi.h>
+#include <linux/io.h>
+#include <linux/uaccess.h>
+#include <linux/init.h>
+#include <linux/cpufreq.h>
+#include <linux/delay.h>
+#include <linux/ioctl.h>
+#include <linux/vmalloc.h>
+#include <linux/mailbox_controller.h>
+#include <linux/platform_device.h>
+
+#include <acpi/actbl.h>
+
+#define MAX_PCC_SUBSPACES 256
+#define PCCS_SS_SIG_MAGIC 0x50434300
+#define PCC_CMD_COMPLETE 0x1
+#define PCC_VERSION "0.1"
+
+static struct mbox_chan pcc_mbox_chan[MAX_PCC_SUBSPACES];
+static struct mbox_controller pcc_mbox_ctrl = {};
+
+extern int pcc_mbox_controller_register(struct mbox_controller *);
+extern struct mbox_chan *pcc_mbox_request_channel(struct mbox_client *, int);
+
+static bool pcc_tx_done(struct mbox_chan *chan)
+{
+ struct acpi_pcct_subspace *pcct_ss = chan->con_priv;
+ struct acpi_pcct_shared_memory *generic_comm_base =
+ (struct acpi_pcct_shared_memory *) pcct_ss->base_address;
+ u16 cmd_delay = pcct_ss->min_turnaround_time;
+
+ /* Wait for Platform to consume. */
+ while (!(ioread16(&generic_comm_base->status) & PCC_CMD_COMPLETE))
+ udelay(cmd_delay);
+
+ return true;
+}
+
+static int get_subspace_id(struct mbox_chan *chan)
+{
+ unsigned int i;
+ int ret = -ENOENT;
+
+ for (i = 0; i < pcc_mbox_ctrl.num_chans; i++) {
+ if (chan == &pcc_mbox_chan[i])
+ return i;
+ }
+
+ return ret;
+}
+
+/* Channel lock is already held by mbox controller code. */
+static int pcc_send_data(struct mbox_chan *chan, void *data)
+{
+ struct acpi_pcct_subspace *pcct_ss = chan->con_priv;
+ struct acpi_pcct_shared_memory *generic_comm_base =
+ (struct acpi_pcct_shared_memory *) pcct_ss->base_address;
+ struct acpi_generic_address doorbell;
+ u64 doorbell_preserve;
+ u64 doorbell_val;
+ u64 doorbell_write;
+ u16 cmd = 0;
+ u16 ss_idx = -1;
+ int ret = 0;
+
+ /* Get PCC CMD */
+ ret = kstrtou16((char*)data, 0, &cmd);
+ if (ret < 0) {
+ pr_err("Err while converting PCC CMD to u16: %d\n", ret);
+ goto out_err;
+ }
+
+ ss_idx = get_subspace_id(chan);
+
+ if (ss_idx < 0) {
+ pr_err("Invalid Subspace ID from PCC client\n");
+ ret = ss_idx;
+ goto out_err;
+ }
+
+ doorbell = pcct_ss->doorbell_register;
+ doorbell_preserve = pcct_ss->preserve_mask;
+ doorbell_write = pcct_ss->write_mask;
+
+ /* Write to the shared comm region. */
+ iowrite16(cmd, &generic_comm_base->command);
+
+ /* Write Subspace MAGIC value so platform can identify destination. */
+ iowrite32((PCCS_SS_SIG_MAGIC | ss_idx), &generic_comm_base->signature);
+
+ /* Flip CMD COMPLETE bit */
+ iowrite16(0, &generic_comm_base->status);
+
+ /* Sync notification from OSPM to Platform. */
+ acpi_read(&doorbell_val, &doorbell);
+ acpi_write((doorbell_val & doorbell_preserve) | doorbell_write,
+ &doorbell);
+
+out_err:
+ return ret;
+}
+
+static struct mbox_chan_ops pcc_chan_ops = {
+ .send_data = pcc_send_data,
+ .last_tx_done = pcc_tx_done,
+};
+
+static int parse_pcc_subspace(struct acpi_subtable_header *header,
+ const unsigned long end)
+{
+ struct acpi_pcct_subspace *pcct_ss;
+
+ if (pcc_mbox_ctrl.num_chans <= MAX_PCC_SUBSPACES) {
+ pcct_ss = (struct acpi_pcct_subspace *) header;
+
+ if (pcct_ss->header.type != ACPI_PCCT_TYPE_GENERIC_SUBSPACE) {
+ pr_err("Incorrect PCC Subspace type detected\n");
+ return -EINVAL;
+ }
+
+ /* New mbox channel entry for each PCC subspace detected. */
+ pcc_mbox_chan[pcc_mbox_ctrl.num_chans].con_priv = pcct_ss;
+ pcc_mbox_ctrl.num_chans++;
+
+ } else {
+ pr_err("No more space for PCC subspaces.\n");
+ return -ENOSPC;
+ }
+
+ return 0;
+}
+
+/*
+ * Create a virtual device to back the PCCT, so
+ * that the generic Mailbox framework can do its
+ * ref counting.
+ */
+struct platform_device pcc_pdev = {
+ .name = "PCCT",
+};
+
+static int __init acpi_pcc_probe(void)
+{
+ acpi_status status = AE_OK;
+ acpi_size pcct_tbl_header_size;
+ struct acpi_table_pcct *pcct_tbl;
+ int ret;
+
+ /* Search for PCCT */
+ status = acpi_get_table_with_size(ACPI_SIG_PCCT, 0,
+ (struct acpi_table_header **)&pcct_tbl,
+ &pcct_tbl_header_size);
+
+ if (ACPI_SUCCESS(status) && !pcct_tbl) {
+ pr_warn("PCCT header not found.\n");
+ status = AE_NOT_FOUND;
+ goto out_err;
+ }
+
+ status = acpi_table_parse_entries(ACPI_SIG_PCCT,
+ sizeof(struct acpi_table_pcct),
+ ACPI_PCCT_TYPE_GENERIC_SUBSPACE,
+ parse_pcc_subspace, MAX_PCC_SUBSPACES);
+
+ if (ACPI_SUCCESS(status))
+ pr_err("Error parsing PCC subspaces from PCCT\n");
+
+ pr_info("Detected %d PCC Subspaces\n", pcc_mbox_ctrl.num_chans);
+
+ pcc_mbox_ctrl.chans = pcc_mbox_chan;
+ pcc_mbox_ctrl.ops = &pcc_chan_ops;
+ pcc_mbox_ctrl.txdone_poll = true;
+ pcc_mbox_ctrl.txpoll_period = 1;
+
+ ret = platform_device_register(&pcc_pdev);
+
+ if (ret) {
+ pr_err ("Err registering PCC platform device\n");
+ return -ENODEV;
+ }
+
+out_err:
+ return ACPI_SUCCESS(status) ? 1 : 0;
+}
+
+static int pcc_mbox_probe(struct platform_device *pdev)
+{
+ int ret = 0;
+
+ pcc_mbox_ctrl.dev = &pdev->dev;
+
+ pr_info("Registering PCC driver as Mailbox controller\n");
+ ret = pcc_mbox_controller_register(&pcc_mbox_ctrl);
+
+ if (ret) {
+ pr_err("Err registering PCC as Mailbox controller: %d\n", ret);
+ ret = -ENODEV;
+ }
+
+ return ret;
+}
+
+struct platform_driver pcc_mbox_driver = {
+ .probe = pcc_mbox_probe,
+ .driver = {
+ .name = "PCCT",
+ .owner = THIS_MODULE,
+ },
+};
+
+static int __init pcc_init(void)
+{
+ int ret;
+
+ if (acpi_disabled)
+ return -ENODEV;
+
+ /* Check if PCC support is available. */
+ ret = acpi_pcc_probe();
+
+ if (ret) {
+ pr_debug("PCC probe failed.\n");
+ return -EINVAL;
+ }
+
+ return platform_driver_register(&pcc_mbox_driver);
+}
+
+device_initcall(pcc_init);
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v4 4/4] PCC test
2014-09-03 19:38 [PATCH v4 0/4] PCC: Platform Communication Channel Ashwin Chaugule
` (2 preceding siblings ...)
2014-09-03 19:38 ` [PATCH v4 3/4] Mailbox: Add support for Platform Communication Channel Ashwin Chaugule
@ 2014-09-03 19:38 ` Ashwin Chaugule
3 siblings, 0 replies; 7+ messages in thread
From: Ashwin Chaugule @ 2014-09-03 19:38 UTC (permalink / raw)
To: arnd; +Cc: linux-acpi, linaro-acpi, rjw, broonie, 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.
Signed-off-by: Ashwin Chaugule <ashwin.chaugule@linaro.org>
---
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
diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile
index e746e26..cd3f263 100644
--- a/drivers/mailbox/Makefile
+++ b/drivers/mailbox/Makefile
@@ -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
diff --git a/drivers/mailbox/pcc-test.c b/drivers/mailbox/pcc-test.c
new file mode 100644
index 0000000..0425711
--- /dev/null
+++ b/drivers/mailbox/pcc-test.c
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2014 Linaro Ltd.
+ * Author: Ashwin Chaugule <ashwin.chaugule@linaro.org>
+ *
+ * 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 <linux/acpi.h>
+#include <linux/io.h>
+#include <linux/uaccess.h>
+#include <linux/init.h>
+#include <linux/cpufreq.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
+#include <linux/mailbox_client.h>
+#include <linux/mailbox_controller.h>
+#include <linux/platform_device.h>
+#include <asm/uaccess.h>
+
+#include <acpi/actbl.h>
+
+static void __iomem *comm_base_addr; /* For use after ioremap */
+
+extern int pcc_mbox_controller_register(struct mbox_controller *mbox);
+extern struct mbox_chan *pcc_mbox_request_channel(struct mbox_client *, unsigned int);
+extern int mbox_send_message(struct mbox_chan *chan, void *mssg);
+
+
+/* XXX: The PCC Subspace id is hard coded here only for test purposes.
+ * In reality it should be parsed from the PCC package as described
+ * in the PCC client table. e.g. CPC for CPPC
+ */
+#define PCC_SUBSPACE_IDX 0
+#define CMD_COMPLETE 1
+
+struct mbox_chan *pcc_test_chan;
+enum ppc_cmds {
+ CMD_READ,
+ CMD_WRITE,
+ RESERVED,
+};
+
+static u64 reg1, reg2;
+
+static void run_pcc_test_read(void)
+{
+ u64 reg1_addr = (u64)comm_base_addr + 0x100;
+ u64 reg2_addr = (u64)comm_base_addr + 0x110;
+ char mssg[2];
+ int ret;
+
+ /* READ part of the test */
+ pr_info("Sending PCC read req from Channel base addr: %llx\n", (u64)comm_base_addr);
+
+ snprintf(mssg, sizeof(short), "%d", CMD_READ);
+ ret = mbox_send_message(pcc_test_chan, &mssg);
+ if (ret >= 0) {
+ pr_info("Read updated values from Platform.\n");
+ reg1 = readq((void*)reg1_addr);
+ reg2 = readq((void*)reg2_addr);
+ pr_info("updated value of reg1:%llx\n", reg1);
+ pr_info("updated value of reg2:%llx\n", reg2);
+ } else
+ pr_err("Failed to read PCC parameters: ret=%d\n", ret);
+}
+
+static void run_pcc_test_write(void)
+{
+ u64 reg1_addr = (u64)comm_base_addr + 0x100;
+ u64 reg2_addr = (u64)comm_base_addr + 0x110;
+ char mssg[2];
+ int ret;
+
+ /* WRITE part of the test */
+ reg1++;
+ reg2++;
+
+ writeq(reg1, (void *)reg1_addr);
+ writeq(reg2, (void *)reg2_addr);
+
+ pr_info("Sending PCC write req from Channel base addr: %llx\n", (u64)comm_base_addr);
+ snprintf(mssg, sizeof(short), "%d", CMD_WRITE);
+
+ ret = mbox_send_message(pcc_test_chan, &mssg);
+
+ if (ret >= 0)
+ pr_info("OSPM successfully sent PCC write cmd to platform\n");
+ else
+ pr_err("Failed to write PCC parameters. ret= %d\n", ret);
+}
+
+static void pcc_chan_tx_done(struct mbox_client *cl, void *mssg, int ret)
+{
+ if (!ret)
+ pr_info("PCC channel TX successfully completed. CMD sent = %s\n", (char*)mssg);
+ else
+ pr_warn("PCC channel TX did not complete: CMD sent = %s\n", (char*)mssg);
+}
+
+struct mbox_client pcc_mbox_cl = {
+ .tx_done = pcc_chan_tx_done,
+};
+
+void get_pcc_comm(void)
+{
+ u64 base_addr;
+ u32 len;
+ struct acpi_pcct_subspace *pcc_ss;
+
+ pcc_test_chan = pcc_mbox_request_channel(&pcc_mbox_cl, PCC_SUBSPACE_IDX);
+
+ if (!pcc_test_chan) {
+ pr_err("PCC Channel not found!\n");
+ return;
+ }
+
+ pcc_ss = pcc_test_chan->con_priv;
+
+ base_addr = pcc_ss->base_address;
+ len = pcc_ss->length;
+
+ pr_info("ioremapping: %llx, len: %x\n", base_addr, len);
+
+// comm_base_addr = ioremap_nocache(base_addr, len);
+ /* HACK to test PCC commands */
+ comm_base_addr = kzalloc(PAGE_SIZE, GFP_KERNEL);
+
+ if (!comm_base_addr) {
+ pr_err("Could not ioremap channel\n");
+ return;
+ }
+
+ pcc_ss->base_address = (u64)comm_base_addr;
+
+ pr_info("Comm_base_addr: %llx\n", (u64)comm_base_addr);
+}
+
+static ssize_t pcc_test_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *offs)
+{
+ char ctl[2];
+
+ if (count != 2 || *offs)
+ return -EINVAL;
+
+ if (copy_from_user(ctl, buf, count))
+ return -EFAULT;
+
+ switch (ctl[0]) {
+ case '0':
+ /* PCC read */
+ run_pcc_test_read();
+ break;
+ case '1':
+ /* PCC write */
+ run_pcc_test_write();
+ break;
+ case '2':
+ /* Get PCC channel */
+ get_pcc_comm();
+ break;
+ default:
+ pr_err("Unknown val\n");
+ break;
+ }
+
+ return count;
+}
+
+static int pcc_test_open(struct inode *inode, struct file *filp)
+{
+ return 0;
+}
+
+static int pcc_test_release(struct inode *inode, struct file *filp)
+{
+ return 0;
+}
+
+static const struct file_operations pcc_test_fops = {
+ .open = pcc_test_open,
+// .read = seq_read,
+ .write = pcc_test_write,
+ .release = pcc_test_release,
+};
+
+static int __init pcc_test(void)
+{
+ struct proc_dir_entry *pe;
+
+ pe = proc_create("pcc_test", 0644, NULL, &pcc_test_fops);
+
+ if (!pe)
+ return -ENOMEM;
+
+ return 0;
+}
+
+late_initcall(pcc_test);
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread