]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
platform/x86/amd/hsmp: Convert amd_hsmp_rdwr() to a function pointer
authorSuma Hegde <suma.hegde@amd.com>
Mon, 21 Oct 2024 11:14:20 +0000 (11:14 +0000)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 22 Oct 2024 10:36:50 +0000 (13:36 +0300)
This is in preparation to ACPI, Non-ACPI split.
amd_hsmp_rdwr() is used to access HSMP protocol registers.
ACPI and Non-ACPI use different methods to access these registers.
Now that code is split and common functionality is kept in hsmp.c
we need to define a function pointer to handle these functions separately.

Signed-off-by: Suma Hegde <suma.hegde@amd.com>
Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20241021111428.2676884-3-suma.hegde@amd.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/amd/hsmp/hsmp.c

index f7b9964522de4aa04179d954e8ff31c5902c9cf5..759c824f2c4fadc988cac2f51a56306b29a20984 100644 (file)
@@ -82,6 +82,7 @@ struct hsmp_socket {
        struct pci_dev *root;
        struct device *dev;
        u16 sock_ind;
+       int (*amd_hsmp_rdwr)(struct hsmp_socket *sock, u32 off, u32 *val, bool rw);
 };
 
 struct hsmp_plat_device {
@@ -114,22 +115,13 @@ static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset,
        return ret;
 }
 
-static void amd_hsmp_acpi_rdwr(struct hsmp_socket *sock, u32 offset,
-                              u32 *value, bool write)
+static int amd_hsmp_acpi_rdwr(struct hsmp_socket *sock, u32 offset,
+                             u32 *value, bool write)
 {
        if (write)
                iowrite32(*value, sock->virt_base_addr + offset);
        else
                *value = ioread32(sock->virt_base_addr + offset);
-}
-
-static int amd_hsmp_rdwr(struct hsmp_socket *sock, u32 offset,
-                        u32 *value, bool write)
-{
-       if (plat_dev.is_acpi_device)
-               amd_hsmp_acpi_rdwr(sock, offset, value, write);
-       else
-               return amd_hsmp_pci_rdwr(sock, offset, value, write);
 
        return 0;
 }
@@ -156,7 +148,7 @@ static int __hsmp_send_message(struct hsmp_socket *sock, struct hsmp_message *ms
 
        /* Clear the status register */
        mbox_status = HSMP_STATUS_NOT_READY;
-       ret = amd_hsmp_rdwr(sock, mbinfo->msg_resp_off, &mbox_status, HSMP_WR);
+       ret = sock->amd_hsmp_rdwr(sock, mbinfo->msg_resp_off, &mbox_status, HSMP_WR);
        if (ret) {
                pr_err("Error %d clearing mailbox status register\n", ret);
                return ret;
@@ -165,8 +157,8 @@ static int __hsmp_send_message(struct hsmp_socket *sock, struct hsmp_message *ms
        index = 0;
        /* Write any message arguments */
        while (index < msg->num_args) {
-               ret = amd_hsmp_rdwr(sock, mbinfo->msg_arg_off + (index << 2),
-                                   &msg->args[index], HSMP_WR);
+               ret = sock->amd_hsmp_rdwr(sock, mbinfo->msg_arg_off + (index << 2),
+                                         &msg->args[index], HSMP_WR);
                if (ret) {
                        pr_err("Error %d writing message argument %d\n", ret, index);
                        return ret;
@@ -175,7 +167,7 @@ static int __hsmp_send_message(struct hsmp_socket *sock, struct hsmp_message *ms
        }
 
        /* Write the message ID which starts the operation */
-       ret = amd_hsmp_rdwr(sock, mbinfo->msg_id_off, &msg->msg_id, HSMP_WR);
+       ret = sock->amd_hsmp_rdwr(sock, mbinfo->msg_id_off, &msg->msg_id, HSMP_WR);
        if (ret) {
                pr_err("Error %d writing message ID %u\n", ret, msg->msg_id);
                return ret;
@@ -192,7 +184,7 @@ static int __hsmp_send_message(struct hsmp_socket *sock, struct hsmp_message *ms
        timeout = jiffies + msecs_to_jiffies(HSMP_MSG_TIMEOUT);
 
        while (time_before(jiffies, timeout)) {
-               ret = amd_hsmp_rdwr(sock, mbinfo->msg_resp_off, &mbox_status, HSMP_RD);
+               ret = sock->amd_hsmp_rdwr(sock, mbinfo->msg_resp_off, &mbox_status, HSMP_RD);
                if (ret) {
                        pr_err("Error %d reading mailbox status\n", ret);
                        return ret;
@@ -227,8 +219,8 @@ static int __hsmp_send_message(struct hsmp_socket *sock, struct hsmp_message *ms
         */
        index = 0;
        while (index < msg->response_sz) {
-               ret = amd_hsmp_rdwr(sock, mbinfo->msg_arg_off + (index << 2),
-                                   &msg->args[index], HSMP_RD);
+               ret = sock->amd_hsmp_rdwr(sock, mbinfo->msg_arg_off + (index << 2),
+                                         &msg->args[index], HSMP_RD);
                if (ret) {
                        pr_err("Error %d reading response %u for message ID:%u\n",
                               ret, index, msg->msg_id);
@@ -545,6 +537,7 @@ static int hsmp_parse_acpi_table(struct device *dev, u16 sock_ind)
 
        sock->sock_ind          = sock_ind;
        sock->dev               = dev;
+       sock->amd_hsmp_rdwr     = amd_hsmp_acpi_rdwr;
        plat_dev.is_acpi_device = true;
 
        sema_init(&sock->hsmp_sem, 1);
@@ -756,6 +749,7 @@ static int init_platform_device(struct device *dev)
                sock->sock_ind                  = i;
                sock->dev                       = dev;
                sock->mbinfo.base_addr          = SMN_HSMP_BASE;
+               sock->amd_hsmp_rdwr             = amd_hsmp_pci_rdwr;
 
                /*
                 * This is a transitional change from non-ACPI to ACPI, only