Skip to content

Commit 7b6da7f

Browse files
sudeep-hollaJassiBrar
authored andcommitted
mailbox: pcc: Use PCC mailbox channel pointer instead of standard
Now that we have all the shared memory region information populated in the pcc_mbox_chan, let us propagate the pointer to the same as the return value to pcc_mbox_request channel. This eliminates the need for the individual users of PCC mailbox to parse the PCCT subspace entries and fetch the shmem information. This also eliminates the need for PCC mailbox controller to set con_priv to PCCT subspace entries. This is required as con_priv is private to the controller driver to attach private data associated with the channel and not meant to be used by the mailbox client/users. Let us convert all the users of pcc_mbox_{request,free}_channel to use new interface. Cc: Jean Delvare <[email protected]> Signed-off-by: Sudeep Holla <[email protected]> Acked-by: Wolfram Sang <[email protected]> Acked-by: Guenter Roeck <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent 0f2591e commit 7b6da7f

File tree

5 files changed

+64
-122
lines changed

5 files changed

+64
-122
lines changed

drivers/acpi/cppc_acpi.c

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include <acpi/cppc_acpi.h>
4444

4545
struct cppc_pcc_data {
46-
struct mbox_chan *pcc_channel;
46+
struct pcc_mbox_chan *pcc_channel;
4747
void __iomem *pcc_comm_addr;
4848
bool pcc_channel_acquired;
4949
unsigned int deadline_us;
@@ -295,7 +295,7 @@ static int send_pcc_cmd(int pcc_ss_id, u16 cmd)
295295
pcc_ss_data->platform_owns_pcc = true;
296296

297297
/* Ring doorbell */
298-
ret = mbox_send_message(pcc_ss_data->pcc_channel, &cmd);
298+
ret = mbox_send_message(pcc_ss_data->pcc_channel->mchan, &cmd);
299299
if (ret < 0) {
300300
pr_err("Err sending PCC mbox message. ss: %d cmd:%d, ret:%d\n",
301301
pcc_ss_id, cmd, ret);
@@ -308,10 +308,10 @@ static int send_pcc_cmd(int pcc_ss_id, u16 cmd)
308308
if (pcc_ss_data->pcc_mrtt)
309309
pcc_ss_data->last_cmd_cmpl_time = ktime_get();
310310

311-
if (pcc_ss_data->pcc_channel->mbox->txdone_irq)
312-
mbox_chan_txdone(pcc_ss_data->pcc_channel, ret);
311+
if (pcc_ss_data->pcc_channel->mchan->mbox->txdone_irq)
312+
mbox_chan_txdone(pcc_ss_data->pcc_channel->mchan, ret);
313313
else
314-
mbox_client_txdone(pcc_ss_data->pcc_channel, ret);
314+
mbox_client_txdone(pcc_ss_data->pcc_channel->mchan, ret);
315315

316316
end:
317317
if (cmd == CMD_WRITE) {
@@ -493,46 +493,33 @@ EXPORT_SYMBOL_GPL(acpi_get_psd_map);
493493

494494
static int register_pcc_channel(int pcc_ss_idx)
495495
{
496-
struct acpi_pcct_hw_reduced *cppc_ss;
496+
struct pcc_mbox_chan *pcc_chan;
497497
u64 usecs_lat;
498498

499499
if (pcc_ss_idx >= 0) {
500-
pcc_data[pcc_ss_idx]->pcc_channel =
501-
pcc_mbox_request_channel(&cppc_mbox_cl, pcc_ss_idx);
500+
pcc_chan = pcc_mbox_request_channel(&cppc_mbox_cl, pcc_ss_idx);
502501

503-
if (IS_ERR(pcc_data[pcc_ss_idx]->pcc_channel)) {
502+
if (IS_ERR(pcc_chan)) {
504503
pr_err("Failed to find PCC channel for subspace %d\n",
505504
pcc_ss_idx);
506505
return -ENODEV;
507506
}
508507

509-
/*
510-
* The PCC mailbox controller driver should
511-
* have parsed the PCCT (global table of all
512-
* PCC channels) and stored pointers to the
513-
* subspace communication region in con_priv.
514-
*/
515-
cppc_ss = (pcc_data[pcc_ss_idx]->pcc_channel)->con_priv;
516-
517-
if (!cppc_ss) {
518-
pr_err("No PCC subspace found for %d CPPC\n",
519-
pcc_ss_idx);
520-
return -ENODEV;
521-
}
522-
508+
pcc_data[pcc_ss_idx]->pcc_channel = pcc_chan;
523509
/*
524510
* cppc_ss->latency is just a Nominal value. In reality
525511
* the remote processor could be much slower to reply.
526512
* So add an arbitrary amount of wait on top of Nominal.
527513
*/
528-
usecs_lat = NUM_RETRIES * cppc_ss->latency;
514+
usecs_lat = NUM_RETRIES * pcc_chan->latency;
529515
pcc_data[pcc_ss_idx]->deadline_us = usecs_lat;
530-
pcc_data[pcc_ss_idx]->pcc_mrtt = cppc_ss->min_turnaround_time;
531-
pcc_data[pcc_ss_idx]->pcc_mpar = cppc_ss->max_access_rate;
532-
pcc_data[pcc_ss_idx]->pcc_nominal = cppc_ss->latency;
516+
pcc_data[pcc_ss_idx]->pcc_mrtt = pcc_chan->min_turnaround_time;
517+
pcc_data[pcc_ss_idx]->pcc_mpar = pcc_chan->max_access_rate;
518+
pcc_data[pcc_ss_idx]->pcc_nominal = pcc_chan->latency;
533519

534520
pcc_data[pcc_ss_idx]->pcc_comm_addr =
535-
acpi_os_ioremap(cppc_ss->base_address, cppc_ss->length);
521+
acpi_os_ioremap(pcc_chan->shmem_base_addr,
522+
pcc_chan->shmem_size);
536523
if (!pcc_data[pcc_ss_idx]->pcc_comm_addr) {
537524
pr_err("Failed to ioremap PCC comm region mem for %d\n",
538525
pcc_ss_idx);

drivers/hwmon/xgene-hwmon.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct slimpro_resp_msg {
9393
struct xgene_hwmon_dev {
9494
struct device *dev;
9595
struct mbox_chan *mbox_chan;
96+
struct pcc_mbox_chan *pcc_chan;
9697
struct mbox_client mbox_client;
9798
int mbox_idx;
9899

@@ -652,7 +653,7 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
652653
goto out_mbox_free;
653654
}
654655
} else {
655-
struct acpi_pcct_hw_reduced *cppc_ss;
656+
struct pcc_mbox_chan *pcc_chan;
656657
const struct acpi_device_id *acpi_id;
657658
int version;
658659

@@ -671,26 +672,16 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
671672
}
672673

673674
cl->rx_callback = xgene_hwmon_pcc_rx_cb;
674-
ctx->mbox_chan = pcc_mbox_request_channel(cl, ctx->mbox_idx);
675-
if (IS_ERR(ctx->mbox_chan)) {
675+
pcc_chan = pcc_mbox_request_channel(cl, ctx->mbox_idx);
676+
if (IS_ERR(pcc_chan)) {
676677
dev_err(&pdev->dev,
677678
"PPC channel request failed\n");
678679
rc = -ENODEV;
679680
goto out_mbox_free;
680681
}
681682

682-
/*
683-
* The PCC mailbox controller driver should
684-
* have parsed the PCCT (global table of all
685-
* PCC channels) and stored pointers to the
686-
* subspace communication region in con_priv.
687-
*/
688-
cppc_ss = ctx->mbox_chan->con_priv;
689-
if (!cppc_ss) {
690-
dev_err(&pdev->dev, "PPC subspace not found\n");
691-
rc = -ENODEV;
692-
goto out;
693-
}
683+
ctx->pcc_chan = pcc_chan;
684+
ctx->mbox_chan = pcc_chan->mchan;
694685

695686
if (!ctx->mbox_chan->mbox->txdone_irq) {
696687
dev_err(&pdev->dev, "PCC IRQ not supported\n");
@@ -702,16 +693,16 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
702693
* This is the shared communication region
703694
* for the OS and Platform to communicate over.
704695
*/
705-
ctx->comm_base_addr = cppc_ss->base_address;
696+
ctx->comm_base_addr = pcc_chan->shmem_base_addr;
706697
if (ctx->comm_base_addr) {
707698
if (version == XGENE_HWMON_V2)
708699
ctx->pcc_comm_addr = (void __force *)ioremap(
709700
ctx->comm_base_addr,
710-
cppc_ss->length);
701+
pcc_chan->shmem_size);
711702
else
712703
ctx->pcc_comm_addr = memremap(
713704
ctx->comm_base_addr,
714-
cppc_ss->length,
705+
pcc_chan->shmem_size,
715706
MEMREMAP_WB);
716707
} else {
717708
dev_err(&pdev->dev, "Failed to get PCC comm region\n");
@@ -727,11 +718,11 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
727718
}
728719

729720
/*
730-
* cppc_ss->latency is just a Nominal value. In reality
721+
* pcc_chan->latency is just a Nominal value. In reality
731722
* the remote processor could be much slower to reply.
732723
* So add an arbitrary amount of wait on top of Nominal.
733724
*/
734-
ctx->usecs_lat = PCC_NUM_RETRIES * cppc_ss->latency;
725+
ctx->usecs_lat = PCC_NUM_RETRIES * pcc_chan->latency;
735726
}
736727

737728
ctx->hwmon_dev = hwmon_device_register_with_groups(ctx->dev,
@@ -757,7 +748,7 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
757748
if (acpi_disabled)
758749
mbox_free_channel(ctx->mbox_chan);
759750
else
760-
pcc_mbox_free_channel(ctx->mbox_chan);
751+
pcc_mbox_free_channel(ctx->pcc_chan);
761752
out_mbox_free:
762753
kfifo_free(&ctx->async_msg_fifo);
763754

@@ -773,7 +764,7 @@ static int xgene_hwmon_remove(struct platform_device *pdev)
773764
if (acpi_disabled)
774765
mbox_free_channel(ctx->mbox_chan);
775766
else
776-
pcc_mbox_free_channel(ctx->mbox_chan);
767+
pcc_mbox_free_channel(ctx->pcc_chan);
777768

778769
return 0;
779770
}

drivers/i2c/busses/i2c-xgene-slimpro.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct slimpro_i2c_dev {
103103
struct i2c_adapter adapter;
104104
struct device *dev;
105105
struct mbox_chan *mbox_chan;
106+
struct pcc_mbox_chan *pcc_chan;
106107
struct mbox_client mbox_client;
107108
int mbox_idx;
108109
struct completion rd_complete;
@@ -466,7 +467,7 @@ static int xgene_slimpro_i2c_probe(struct platform_device *pdev)
466467
return PTR_ERR(ctx->mbox_chan);
467468
}
468469
} else {
469-
struct acpi_pcct_hw_reduced *cppc_ss;
470+
struct pcc_mbox_chan *pcc_chan;
470471
const struct acpi_device_id *acpi_id;
471472
int version = XGENE_SLIMPRO_I2C_V1;
472473

@@ -483,24 +484,14 @@ static int xgene_slimpro_i2c_probe(struct platform_device *pdev)
483484

484485
cl->tx_block = false;
485486
cl->rx_callback = slimpro_i2c_pcc_rx_cb;
486-
ctx->mbox_chan = pcc_mbox_request_channel(cl, ctx->mbox_idx);
487-
if (IS_ERR(ctx->mbox_chan)) {
487+
pcc_chan = pcc_mbox_request_channel(cl, ctx->mbox_idx);
488+
if (IS_ERR(pcc_chan)) {
488489
dev_err(&pdev->dev, "PCC mailbox channel request failed\n");
489-
return PTR_ERR(ctx->mbox_chan);
490+
return PTR_ERR(ctx->pcc_chan);
490491
}
491492

492-
/*
493-
* The PCC mailbox controller driver should
494-
* have parsed the PCCT (global table of all
495-
* PCC channels) and stored pointers to the
496-
* subspace communication region in con_priv.
497-
*/
498-
cppc_ss = ctx->mbox_chan->con_priv;
499-
if (!cppc_ss) {
500-
dev_err(&pdev->dev, "PPC subspace not found\n");
501-
rc = -ENOENT;
502-
goto mbox_err;
503-
}
493+
ctx->pcc_chan = pcc_chan;
494+
ctx->mbox_chan = pcc_chan->mchan;
504495

505496
if (!ctx->mbox_chan->mbox->txdone_irq) {
506497
dev_err(&pdev->dev, "PCC IRQ not supported\n");
@@ -512,17 +503,17 @@ static int xgene_slimpro_i2c_probe(struct platform_device *pdev)
512503
* This is the shared communication region
513504
* for the OS and Platform to communicate over.
514505
*/
515-
ctx->comm_base_addr = cppc_ss->base_address;
506+
ctx->comm_base_addr = pcc_chan->shmem_base_addr;
516507
if (ctx->comm_base_addr) {
517508
if (version == XGENE_SLIMPRO_I2C_V2)
518509
ctx->pcc_comm_addr = memremap(
519510
ctx->comm_base_addr,
520-
cppc_ss->length,
511+
pcc_chan->shmem_size,
521512
MEMREMAP_WT);
522513
else
523514
ctx->pcc_comm_addr = memremap(
524515
ctx->comm_base_addr,
525-
cppc_ss->length,
516+
pcc_chan->shmem_size,
526517
MEMREMAP_WB);
527518
} else {
528519
dev_err(&pdev->dev, "Failed to get PCC comm region\n");
@@ -561,7 +552,7 @@ static int xgene_slimpro_i2c_probe(struct platform_device *pdev)
561552
if (acpi_disabled)
562553
mbox_free_channel(ctx->mbox_chan);
563554
else
564-
pcc_mbox_free_channel(ctx->mbox_chan);
555+
pcc_mbox_free_channel(ctx->pcc_chan);
565556

566557
return rc;
567558
}
@@ -575,7 +566,7 @@ static int xgene_slimpro_i2c_remove(struct platform_device *pdev)
575566
if (acpi_disabled)
576567
mbox_free_channel(ctx->mbox_chan);
577568
else
578-
pcc_mbox_free_channel(ctx->mbox_chan);
569+
pcc_mbox_free_channel(ctx->pcc_chan);
579570

580571
return 0;
581572
}

drivers/mailbox/pcc.c

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,9 @@ struct pcc_chan_info {
7979
int db_irq;
8080
};
8181

82+
#define to_pcc_chan_info(c) container_of(c, struct pcc_chan_info, chan)
8283
static struct pcc_chan_info *chan_info;
83-
8484
static struct mbox_controller pcc_mbox_ctrl = {};
85-
/**
86-
* get_pcc_channel - Given a PCC subspace idx, get
87-
* the respective mbox_channel.
88-
* @id: PCC subspace index.
89-
*
90-
* Return: ERR_PTR(errno) if error, else pointer
91-
* to mbox channel.
92-
*/
93-
static struct mbox_chan *get_pcc_channel(int id)
94-
{
95-
if (id < 0 || id >= pcc_mbox_ctrl.num_chans)
96-
return ERR_PTR(-ENOENT);
97-
98-
return &pcc_mbox_channels[id];
99-
}
10085

10186
/*
10287
* PCC can be used with perf critical drivers such as CPPC
@@ -239,31 +224,25 @@ static irqreturn_t pcc_mbox_irq(int irq, void *p)
239224
* ACPI package. This is used to lookup the array of PCC
240225
* subspaces as parsed by the PCC Mailbox controller.
241226
*
242-
* Return: Pointer to the Mailbox Channel if successful or
243-
* ERR_PTR.
227+
* Return: Pointer to the PCC Mailbox Channel if successful or ERR_PTR.
244228
*/
245-
struct mbox_chan *pcc_mbox_request_channel(struct mbox_client *cl,
246-
int subspace_id)
229+
struct pcc_mbox_chan *
230+
pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id)
247231
{
248232
struct pcc_chan_info *pchan;
249233
struct device *dev = pcc_mbox_ctrl.dev;
250234
struct mbox_chan *chan;
251235
unsigned long flags;
252236

253-
/*
254-
* Each PCC Subspace is a Mailbox Channel.
255-
* The PCC Clients get their PCC Subspace ID
256-
* from their own tables and pass it here.
257-
* This returns a pointer to the PCC subspace
258-
* for the Client to operate on.
259-
*/
260-
chan = get_pcc_channel(subspace_id);
237+
if (subspace_id < 0 || subspace_id >= pcc_mbox_ctrl.num_chans)
238+
return ERR_PTR(-ENOENT);
261239

240+
pchan = chan_info + subspace_id;
241+
chan = pchan->chan.mchan;
262242
if (IS_ERR(chan) || chan->cl) {
263243
dev_err(dev, "Channel not found for idx: %d\n", subspace_id);
264244
return ERR_PTR(-EBUSY);
265245
}
266-
pchan = chan_info + subspace_id;
267246

268247
spin_lock_irqsave(&chan->lock, flags);
269248
chan->msg_free = 0;
@@ -285,38 +264,32 @@ struct mbox_chan *pcc_mbox_request_channel(struct mbox_client *cl,
285264
if (unlikely(rc)) {
286265
dev_err(dev, "failed to register PCC interrupt %d\n",
287266
pchan->db_irq);
288-
pcc_mbox_free_channel(chan);
289-
chan = ERR_PTR(rc);
267+
pcc_mbox_free_channel(&pchan->chan);
268+
return ERR_PTR(rc);
290269
}
291270
}
292271

293-
return chan;
272+
return &pchan->chan;
294273
}
295274
EXPORT_SYMBOL_GPL(pcc_mbox_request_channel);
296275

297276
/**
298277
* pcc_mbox_free_channel - Clients call this to free their Channel.
299278
*
300-
* @chan: Pointer to the mailbox channel as returned by
301-
* pcc_mbox_request_channel()
279+
* @pchan: Pointer to the PCC mailbox channel as returned by
280+
* pcc_mbox_request_channel()
302281
*/
303-
void pcc_mbox_free_channel(struct mbox_chan *chan)
282+
void pcc_mbox_free_channel(struct pcc_mbox_chan *pchan)
304283
{
305-
u32 id = chan - pcc_mbox_channels;
306-
struct pcc_chan_info *pchan;
284+
struct pcc_chan_info *pchan_info = to_pcc_chan_info(pchan);
285+
struct mbox_chan *chan = pchan->mchan;
307286
unsigned long flags;
308287

309288
if (!chan || !chan->cl)
310289
return;
311290

312-
if (id >= pcc_mbox_ctrl.num_chans) {
313-
pr_debug("pcc_mbox_free_channel: Invalid mbox_chan passed\n");
314-
return;
315-
}
316-
317-
pchan = chan_info + id;
318-
if (pchan->db_irq > 0)
319-
devm_free_irq(chan->mbox->dev, pchan->db_irq, chan);
291+
if (pchan_info->db_irq > 0)
292+
devm_free_irq(chan->mbox->dev, pchan_info->db_irq, chan);
320293

321294
spin_lock_irqsave(&chan->lock, flags);
322295
chan->cl = NULL;

0 commit comments

Comments
 (0)