plat.c (c1691730d9ffb8e813018235ad1b9754104cf67b) | plat.c (1349dd7dc21c63c9bad0e91fd1bf5f1ada34b0e2) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * AMD HSMP Platform Driver 4 * Copyright (c) 2024, AMD. 5 * All Rights Reserved. 6 * 7 * This file provides platform device implementations. 8 */ --- 23 unchanged lines hidden (view full) --- 32#define SMN_HSMP_MSG_ID 0x0010534 33#define SMN_HSMP_MSG_ID_F1A_M0H 0x0010934 34#define SMN_HSMP_MSG_RESP 0x0010980 35#define SMN_HSMP_MSG_DATA 0x00109E0 36 37#define HSMP_INDEX_REG 0xc4 38#define HSMP_DATA_REG 0xc8 39 | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * AMD HSMP Platform Driver 4 * Copyright (c) 2024, AMD. 5 * All Rights Reserved. 6 * 7 * This file provides platform device implementations. 8 */ --- 23 unchanged lines hidden (view full) --- 32#define SMN_HSMP_MSG_ID 0x0010534 33#define SMN_HSMP_MSG_ID_F1A_M0H 0x0010934 34#define SMN_HSMP_MSG_RESP 0x0010980 35#define SMN_HSMP_MSG_DATA 0x00109E0 36 37#define HSMP_INDEX_REG 0xc4 38#define HSMP_DATA_REG 0xc8 39 |
40static struct hsmp_plat_device *hsmp_pdev; 41 |
|
40static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset, 41 u32 *value, bool write) 42{ 43 int ret; 44 45 if (!sock->root) 46 return -ENODEV; 47 --- 11 unchanged lines hidden (view full) --- 59static ssize_t hsmp_metric_tbl_plat_read(struct file *filp, struct kobject *kobj, 60 struct bin_attribute *bin_attr, char *buf, 61 loff_t off, size_t count) 62{ 63 struct hsmp_socket *sock; 64 u16 sock_ind; 65 66 sock_ind = (uintptr_t)bin_attr->private; | 42static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset, 43 u32 *value, bool write) 44{ 45 int ret; 46 47 if (!sock->root) 48 return -ENODEV; 49 --- 11 unchanged lines hidden (view full) --- 61static ssize_t hsmp_metric_tbl_plat_read(struct file *filp, struct kobject *kobj, 62 struct bin_attribute *bin_attr, char *buf, 63 loff_t off, size_t count) 64{ 65 struct hsmp_socket *sock; 66 u16 sock_ind; 67 68 sock_ind = (uintptr_t)bin_attr->private; |
67 if (sock_ind >= hsmp_pdev.num_sockets) | 69 if (sock_ind >= hsmp_pdev->num_sockets) |
68 return -EINVAL; 69 | 70 return -EINVAL; 71 |
70 sock = &hsmp_pdev.sock[sock_ind]; | 72 sock = &hsmp_pdev->sock[sock_ind]; |
71 72 return hsmp_metric_tbl_read(sock, buf, count); 73} 74 75static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj, 76 struct bin_attribute *battr, int id) 77{ 78 u16 sock_ind; 79 80 sock_ind = (uintptr_t)battr->private; 81 | 73 74 return hsmp_metric_tbl_read(sock, buf, count); 75} 76 77static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj, 78 struct bin_attribute *battr, int id) 79{ 80 u16 sock_ind; 81 82 sock_ind = (uintptr_t)battr->private; 83 |
82 if (id == 0 && sock_ind >= hsmp_pdev.num_sockets) | 84 if (id == 0 && sock_ind >= hsmp_pdev->num_sockets) |
83 return SYSFS_GROUP_INVISIBLE; 84 | 85 return SYSFS_GROUP_INVISIBLE; 86 |
85 if (hsmp_pdev.proto_ver == HSMP_PROTO_VER6) | 87 if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6) |
86 return battr->attr.mode; 87 88 return 0; 89} 90 91/* 92 * AMD supports maximum of 8 sockets in a system. 93 * Static array of 8 + 1(for NULL) elements is created below --- 57 unchanged lines hidden (view full) --- 151 return false; 152} 153 154static int init_platform_device(struct device *dev) 155{ 156 struct hsmp_socket *sock; 157 int ret, i; 158 | 88 return battr->attr.mode; 89 90 return 0; 91} 92 93/* 94 * AMD supports maximum of 8 sockets in a system. 95 * Static array of 8 + 1(for NULL) elements is created below --- 57 unchanged lines hidden (view full) --- 153 return false; 154} 155 156static int init_platform_device(struct device *dev) 157{ 158 struct hsmp_socket *sock; 159 int ret, i; 160 |
159 for (i = 0; i < hsmp_pdev.num_sockets; i++) { | 161 for (i = 0; i < hsmp_pdev->num_sockets; i++) { |
160 if (!node_to_amd_nb(i)) 161 return -ENODEV; | 162 if (!node_to_amd_nb(i)) 163 return -ENODEV; |
162 sock = &hsmp_pdev.sock[i]; | 164 sock = &hsmp_pdev->sock[i]; |
163 sock->root = node_to_amd_nb(i)->root; 164 sock->sock_ind = i; 165 sock->dev = dev; 166 sock->mbinfo.base_addr = SMN_HSMP_BASE; 167 sock->amd_hsmp_rdwr = amd_hsmp_pci_rdwr; 168 169 /* 170 * This is a transitional change from non-ACPI to ACPI, only --- 18 unchanged lines hidden (view full) --- 189 } 190 191 ret = hsmp_cache_proto_ver(i); 192 if (ret) { 193 dev_err(dev, "Failed to read HSMP protocol version\n"); 194 return ret; 195 } 196 | 165 sock->root = node_to_amd_nb(i)->root; 166 sock->sock_ind = i; 167 sock->dev = dev; 168 sock->mbinfo.base_addr = SMN_HSMP_BASE; 169 sock->amd_hsmp_rdwr = amd_hsmp_pci_rdwr; 170 171 /* 172 * This is a transitional change from non-ACPI to ACPI, only --- 18 unchanged lines hidden (view full) --- 191 } 192 193 ret = hsmp_cache_proto_ver(i); 194 if (ret) { 195 dev_err(dev, "Failed to read HSMP protocol version\n"); 196 return ret; 197 } 198 |
197 if (hsmp_pdev.proto_ver == HSMP_PROTO_VER6) { | 199 if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6) { |
198 ret = hsmp_get_tbl_dram_base(i); 199 if (ret) 200 dev_err(dev, "Failed to init metric table\n"); 201 } 202 } 203 204 return 0; 205} 206 207static int hsmp_pltdrv_probe(struct platform_device *pdev) 208{ 209 int ret; 210 | 200 ret = hsmp_get_tbl_dram_base(i); 201 if (ret) 202 dev_err(dev, "Failed to init metric table\n"); 203 } 204 } 205 206 return 0; 207} 208 209static int hsmp_pltdrv_probe(struct platform_device *pdev) 210{ 211 int ret; 212 |
211 hsmp_pdev.sock = devm_kcalloc(&pdev->dev, hsmp_pdev.num_sockets, 212 sizeof(*hsmp_pdev.sock), 213 GFP_KERNEL); 214 if (!hsmp_pdev.sock) | 213 hsmp_pdev->sock = devm_kcalloc(&pdev->dev, hsmp_pdev->num_sockets, 214 sizeof(*hsmp_pdev->sock), 215 GFP_KERNEL); 216 if (!hsmp_pdev->sock) |
215 return -ENOMEM; 216 217 ret = init_platform_device(&pdev->dev); 218 if (ret) { 219 dev_err(&pdev->dev, "Failed to init HSMP mailbox\n"); 220 return ret; 221 } 222 --- 70 unchanged lines hidden (view full) --- 293 int ret = -ENODEV; 294 295 if (!legacy_hsmp_support()) { 296 pr_info("HSMP is not supported on Family:%x model:%x\n", 297 boot_cpu_data.x86, boot_cpu_data.x86_model); 298 return ret; 299 } 300 | 217 return -ENOMEM; 218 219 ret = init_platform_device(&pdev->dev); 220 if (ret) { 221 dev_err(&pdev->dev, "Failed to init HSMP mailbox\n"); 222 return ret; 223 } 224 --- 70 unchanged lines hidden (view full) --- 295 int ret = -ENODEV; 296 297 if (!legacy_hsmp_support()) { 298 pr_info("HSMP is not supported on Family:%x model:%x\n", 299 boot_cpu_data.x86, boot_cpu_data.x86_model); 300 return ret; 301 } 302 |
303 hsmp_pdev = get_hsmp_pdev(); 304 if (!hsmp_pdev) 305 return -ENOMEM; 306 |
|
301 /* 302 * amd_nb_num() returns number of SMN/DF interfaces present in the system 303 * if we have N SMN/DF interfaces that ideally means N sockets 304 */ | 307 /* 308 * amd_nb_num() returns number of SMN/DF interfaces present in the system 309 * if we have N SMN/DF interfaces that ideally means N sockets 310 */ |
305 hsmp_pdev.num_sockets = amd_nb_num(); 306 if (hsmp_pdev.num_sockets == 0 || hsmp_pdev.num_sockets > MAX_AMD_SOCKETS) | 311 hsmp_pdev->num_sockets = amd_nb_num(); 312 if (hsmp_pdev->num_sockets == 0 || hsmp_pdev->num_sockets > MAX_AMD_SOCKETS) |
307 return ret; 308 309 ret = platform_driver_register(&amd_hsmp_driver); 310 if (ret) 311 return ret; 312 313 ret = hsmp_plat_dev_register(); 314 if (ret) --- 18 unchanged lines hidden --- | 313 return ret; 314 315 ret = platform_driver_register(&amd_hsmp_driver); 316 if (ret) 317 return ret; 318 319 ret = hsmp_plat_dev_register(); 320 if (ret) --- 18 unchanged lines hidden --- |