Skip to content

Commit 67f3ec9

Browse files
committed
platform/x86/amd/hsmp: Create wrapper function init_acpi()
This is in preparation to splitting ACPI and platform device drivers. Having init_acpi() helps in smooth code movement. Signed-off-by: Suma Hegde <[email protected]> Reviewed-by: Naveen Krishna Chatradhi <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]>
1 parent 5e83b01 commit 67f3ec9

File tree

1 file changed

+59
-32
lines changed

1 file changed

+59
-32
lines changed

hsmp.c

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,11 @@ static int init_platform_device(struct device *dev)
820820
dev_err(dev, "Is HSMP disabled in BIOS ?\n");
821821
return ret;
822822
}
823+
ret = hsmp_cache_proto_ver(i);
824+
if (ret) {
825+
dev_err(dev, "Failed to read HSMP protocol version\n");
826+
return ret;
827+
}
823828
}
824829

825830
return 0;
@@ -831,10 +836,53 @@ static const struct acpi_device_id amd_hsmp_acpi_ids[] = {
831836
};
832837
MODULE_DEVICE_TABLE(acpi, amd_hsmp_acpi_ids);
833838

839+
static bool check_acpi_support(struct device *dev)
840+
{
841+
struct acpi_device *adev = ACPI_COMPANION(dev);
842+
843+
if (adev && !acpi_match_device_ids(adev, amd_hsmp_acpi_ids))
844+
return true;
845+
846+
return false;
847+
}
848+
849+
static int init_acpi(struct device *dev)
850+
{
851+
u16 sock_ind;
852+
int ret;
853+
854+
ret = hsmp_get_uid(dev, &sock_ind);
855+
if (ret)
856+
return ret;
857+
if (sock_ind >= plat_dev.num_sockets)
858+
return -EINVAL;
859+
860+
ret = hsmp_parse_acpi_table(dev, sock_ind);
861+
if (ret) {
862+
dev_err(dev, "Failed to parse ACPI table\n");
863+
return ret;
864+
}
865+
866+
/* Test the hsmp interface */
867+
ret = hsmp_test(sock_ind, 0xDEADBEEF);
868+
if (ret) {
869+
dev_err(dev, "HSMP test message failed on Fam:%x model:%x\n",
870+
boot_cpu_data.x86, boot_cpu_data.x86_model);
871+
dev_err(dev, "Is HSMP disabled in BIOS ?\n");
872+
return ret;
873+
}
874+
875+
ret = hsmp_cache_proto_ver(sock_ind);
876+
if (ret) {
877+
dev_err(dev, "Failed to read HSMP protocol version\n");
878+
return ret;
879+
}
880+
881+
return ret;
882+
}
883+
834884
static int hsmp_pltdrv_probe(struct platform_device *pdev)
835885
{
836-
struct acpi_device *adev;
837-
u16 sock_ind = 0;
838886
int ret;
839887

840888
/*
@@ -851,46 +899,25 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev)
851899
if (!plat_dev.sock)
852900
return -ENOMEM;
853901
}
854-
adev = ACPI_COMPANION(&pdev->dev);
855-
if (adev && !acpi_match_device_ids(adev, amd_hsmp_acpi_ids)) {
856-
ret = hsmp_get_uid(&pdev->dev, &sock_ind);
857-
if (ret)
858-
return ret;
859-
if (sock_ind >= plat_dev.num_sockets)
860-
return -EINVAL;
861-
ret = hsmp_parse_acpi_table(&pdev->dev, sock_ind);
862-
if (ret) {
863-
dev_err(&pdev->dev, "Failed to parse ACPI table\n");
864-
return ret;
865-
}
866-
/* Test the hsmp interface */
867-
ret = hsmp_test(sock_ind, 0xDEADBEEF);
902+
if (check_acpi_support(&pdev->dev)) {
903+
ret = init_acpi(&pdev->dev);
868904
if (ret) {
869-
dev_err(&pdev->dev, "HSMP test message failed on Fam:%x model:%x\n",
870-
boot_cpu_data.x86, boot_cpu_data.x86_model);
871-
dev_err(&pdev->dev, "Is HSMP disabled in BIOS ?\n");
905+
dev_err(&pdev->dev, "Failed to init HSMP mailbox\n");
872906
return ret;
873907
}
908+
ret = hsmp_create_acpi_sysfs_if(&pdev->dev);
909+
if (ret)
910+
dev_err(&pdev->dev, "Failed to create HSMP sysfs interface\n");
874911
} else {
875912
ret = init_platform_device(&pdev->dev);
876913
if (ret) {
877914
dev_err(&pdev->dev, "Failed to init HSMP mailbox\n");
878915
return ret;
879916
}
880-
}
881-
882-
ret = hsmp_cache_proto_ver(sock_ind);
883-
if (ret) {
884-
dev_err(&pdev->dev, "Failed to read HSMP protocol version\n");
885-
return ret;
886-
}
887-
888-
if (plat_dev.is_acpi_device)
889-
ret = hsmp_create_acpi_sysfs_if(&pdev->dev);
890-
else
891917
ret = hsmp_create_non_acpi_sysfs_if(&pdev->dev);
892-
if (ret)
893-
dev_err(&pdev->dev, "Failed to create HSMP sysfs interface\n");
918+
if (ret)
919+
dev_err(&pdev->dev, "Failed to create HSMP sysfs interface\n");
920+
}
894921

895922
if (!plat_dev.is_probed) {
896923
plat_dev.hsmp_device.name = HSMP_CDEV_NAME;

0 commit comments

Comments
 (0)