Uses the newly introduced mailbox_api rx_alloc callback. Since this callback is registered in the call to request a channel, it prevents a race condition. Without it, it is impossible to assign the callback before activating the mailbox delivery of messages. This patch also removes the flag pcc_mchan->manage_writes which is not necessary: only type 3 and type 4 subspaces will have their buffers managed by the mailbox. It is not required for the driver to explicitly specify. If a future type 3 or type 4 drivers wishes to manage the buffer directly, they can do so by passing NULL in to mbox_send_message. Signed-off-by: Adam Young --- drivers/mailbox/pcc.c | 16 ++++++++++------ include/acpi/pcc.h | 22 ---------------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index 0a00719b2482..4535cd208b9e 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -309,17 +309,20 @@ static void pcc_chan_acknowledge(struct pcc_chan_info *pchan) static void *write_response(struct pcc_chan_info *pchan) { struct pcc_header pcc_header; + struct mbox_client *cl; + void *handle; void *buffer; int data_len; + cl = pchan->chan.mchan->cl; memcpy_fromio(&pcc_header, pchan->chan.shmem, sizeof(pcc_header)); data_len = pcc_header.length - sizeof(u32) + sizeof(struct pcc_header); - buffer = pchan->chan.rx_alloc(pchan->chan.mchan->cl, data_len); + cl->rx_alloc(cl, &handle, &buffer, data_len); if (buffer != NULL) memcpy_fromio(buffer, pchan->chan.shmem, data_len); - return buffer; + return handle; } /** @@ -359,7 +362,7 @@ static irqreturn_t pcc_mbox_irq(int irq, void *p) */ pchan->chan_in_use = false; - if (pchan->chan.rx_alloc) + if (pchan->chan.mchan->cl->rx_alloc) handle = write_response(pchan); if (chan->active_req) { @@ -415,8 +418,6 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id) if (!pcc_mchan->shmem) goto err; - pcc_mchan->manage_writes = false; - /* This indicates that the channel is ready to accept messages. * This needs to happen after the channel has registered * its callback. There is no access point to do that in @@ -466,7 +467,10 @@ static int pcc_write_to_buffer(struct mbox_chan *chan, void *data) struct pcc_mbox_chan *pcc_mbox_chan = &pchan->chan; struct pcc_header *pcc_header = data; - if (!pchan->chan.manage_writes) + if (data == NULL) + return 0; + if (pchan->type < ACPI_PCCT_TYPE_EXT_PCC_MASTER_SUBSPACE || + pchan->type > ACPI_PCCT_TYPE_EXT_PCC_SLAVE_SUBSPACE) return 0; /* The PCC header length includes the command field diff --git a/include/acpi/pcc.h b/include/acpi/pcc.h index 9af3b502f839..5506490e628c 100644 --- a/include/acpi/pcc.h +++ b/include/acpi/pcc.h @@ -17,28 +17,6 @@ struct pcc_mbox_chan { u32 latency; u32 max_access_rate; u16 min_turnaround_time; - - /* Set to true to indicate that the mailbox should manage - * writing the dat to the shared buffer. This differs from - * the case where the drivesr are writing to the buffer and - * using send_data only to ring the doorbell. If this flag - * is set, then the void * data parameter of send_data must - * point to a kernel-memory buffer formatted in accordance with - * the PCC specification. - * - * The active buffer management will include reading the - * notify_on_completion flag, and will then - * call mbox_chan_txdone when the acknowledgment interrupt is - * received. - */ - bool manage_writes; - - /* Optional callback that allows the driver - * to allocate the memory used for receiving - * messages. The return value is the location - * inside the buffer where the mailbox should write the data. - */ - void *(*rx_alloc)(struct mbox_client *cl, int size); }; struct pcc_header { -- 2.43.0