Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mailbox: pcc: Refactor and simplify check_and_ack()

The existing check_and_ack() function had unnecessary complexity. The
logic could be streamlined to improve code readability and maintainability.

The command update register needs to be updated in order to acknowledge
the platform notification through type 4 channel. So it can be done
unconditionally. Currently it is complicated just to make use of
pcc_send_data() which also executes the same updation.

In order to simplify, let us just ring the doorbell directly from
check_and_ack() instead of calling into pcc_send_data(). While at it,
rename it into pcc_chan_check_and_ack() to maintain consistency in the
driver.

Acked-by: Huisong Li <lihuisong@huawei.com>
Tested-by: Adam Young <admiyo@os.amperecomputing.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>

authored by

Sudeep Holla and committed by
Jassi Brar
2475b364 fa362ffa

+13 -24
+13 -24
drivers/mailbox/pcc.c
··· 117 117 static struct pcc_chan_info *chan_info; 118 118 static int pcc_chan_count; 119 119 120 - static int pcc_send_data(struct mbox_chan *chan, void *data); 121 - 122 120 /* 123 121 * PCC can be used with perf critical drivers such as CPPC 124 122 * So it makes sense to locally cache the virtual address and ··· 286 288 return 0; 287 289 } 288 290 289 - static void check_and_ack(struct pcc_chan_info *pchan, struct mbox_chan *chan) 291 + static void pcc_chan_acknowledge(struct pcc_chan_info *pchan) 290 292 { 291 - struct acpi_pcct_ext_pcc_shared_memory pcc_hdr; 293 + struct acpi_pcct_ext_pcc_shared_memory __iomem *pcc_hdr; 292 294 293 295 if (pchan->type != ACPI_PCCT_TYPE_EXT_PCC_SLAVE_SUBSPACE) 294 296 return; 295 - /* If the memory region has not been mapped, we cannot 296 - * determine if we need to send the message, but we still 297 - * need to set the cmd_update flag before returning. 298 - */ 299 - if (pchan->chan.shmem == NULL) { 300 - pcc_chan_reg_read_modify_write(&pchan->cmd_update); 301 - return; 302 - } 303 - memcpy_fromio(&pcc_hdr, pchan->chan.shmem, 304 - sizeof(struct acpi_pcct_ext_pcc_shared_memory)); 297 + 298 + pcc_chan_reg_read_modify_write(&pchan->cmd_update); 299 + 300 + pcc_hdr = pchan->chan.shmem; 301 + 305 302 /* 306 - * The PCC slave subspace channel needs to set the command complete bit 307 - * after processing message. If the PCC_ACK_FLAG is set, it should also 308 - * ring the doorbell. 309 - * 310 - * The PCC master subspace channel clears chan_in_use to free channel. 303 + * The PCC slave subspace channel needs to set the command 304 + * complete bit after processing message. If the PCC_ACK_FLAG 305 + * is set, it should also ring the doorbell. 311 306 */ 312 - if (pcc_hdr.flags & PCC_CMD_COMPLETION_NOTIFY) 313 - pcc_send_data(chan, NULL); 314 - else 315 - pcc_chan_reg_read_modify_write(&pchan->cmd_update); 307 + if (ioread32(&pcc_hdr->flags) & PCC_CMD_COMPLETION_NOTIFY) 308 + pcc_chan_reg_read_modify_write(&pchan->db); 316 309 } 317 310 318 311 /** ··· 342 353 pchan->chan_in_use = false; 343 354 mbox_chan_received_data(chan, NULL); 344 355 345 - check_and_ack(pchan, chan); 356 + pcc_chan_acknowledge(pchan); 346 357 347 358 return IRQ_HANDLED; 348 359 }