acpi.c (4fc0366ef83f493c63ecf732cbb7ed49edd62072) | acpi.c (c1691730d9ffb8e813018235ad1b9754104cf67b) |
---|---|
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 an ACPI based driver implementation for HSMP interface. 8 */ 9 10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 | 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 an ACPI based driver implementation for HSMP interface. 8 */ 9 10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 |
12#include <asm/amd_hsmp.h> |
|
12#include <asm/amd_nb.h> 13 14#include <linux/acpi.h> 15#include <linux/device.h> 16#include <linux/dev_printk.h> 17#include <linux/ioport.h> 18#include <linux/kstrtox.h> 19#include <linux/module.h> --- 186 unchanged lines hidden (view full) --- 206 int ret; 207 208 sock->sock_ind = sock_ind; 209 sock->dev = dev; 210 sock->amd_hsmp_rdwr = amd_hsmp_acpi_rdwr; 211 212 sema_init(&sock->hsmp_sem, 1); 213 | 13#include <asm/amd_nb.h> 14 15#include <linux/acpi.h> 16#include <linux/device.h> 17#include <linux/dev_printk.h> 18#include <linux/ioport.h> 19#include <linux/kstrtox.h> 20#include <linux/module.h> --- 186 unchanged lines hidden (view full) --- 207 int ret; 208 209 sock->sock_ind = sock_ind; 210 sock->dev = dev; 211 sock->amd_hsmp_rdwr = amd_hsmp_acpi_rdwr; 212 213 sema_init(&sock->hsmp_sem, 1); 214 |
215 dev_set_drvdata(dev, sock); 216 |
|
214 /* Read MP1 base address from CRS method */ 215 ret = hsmp_read_acpi_crs(sock); 216 if (ret) 217 return ret; 218 219 /* Read mailbox offsets from DSD table */ 220 return hsmp_read_acpi_dsd(sock); 221} 222 | 217 /* Read MP1 base address from CRS method */ 218 ret = hsmp_read_acpi_crs(sock); 219 if (ret) 220 return ret; 221 222 /* Read mailbox offsets from DSD table */ 223 return hsmp_read_acpi_dsd(sock); 224} 225 |
223static int hsmp_create_acpi_sysfs_if(struct device *dev) | 226static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj, 227 struct bin_attribute *bin_attr, char *buf, 228 loff_t off, size_t count) |
224{ | 229{ |
225 struct attribute_group *attr_grp; 226 u16 sock_ind; 227 int ret; | 230 struct device *dev = container_of(kobj, struct device, kobj); 231 struct hsmp_socket *sock = dev_get_drvdata(dev); |
228 | 232 |
229 attr_grp = devm_kzalloc(dev, sizeof(struct attribute_group), GFP_KERNEL); 230 if (!attr_grp) 231 return -ENOMEM; | 233 return hsmp_metric_tbl_read(sock, buf, count); 234} |
232 | 235 |
233 attr_grp->is_bin_visible = hsmp_is_sock_attr_visible; | 236static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj, 237 struct bin_attribute *battr, int id) 238{ 239 if (hsmp_pdev.proto_ver == HSMP_PROTO_VER6) 240 return battr->attr.mode; |
234 | 241 |
235 ret = hsmp_get_uid(dev, &sock_ind); 236 if (ret) 237 return ret; 238 239 ret = hsmp_create_attr_list(attr_grp, dev, sock_ind); 240 if (ret) 241 return ret; 242 243 return devm_device_add_group(dev, attr_grp); | 242 return 0; |
244} 245 246static int init_acpi(struct device *dev) 247{ 248 u16 sock_ind; 249 int ret; 250 251 ret = hsmp_get_uid(dev, &sock_ind); --- 18 unchanged lines hidden (view full) --- 270 } 271 272 ret = hsmp_cache_proto_ver(sock_ind); 273 if (ret) { 274 dev_err(dev, "Failed to read HSMP protocol version\n"); 275 return ret; 276 } 277 | 243} 244 245static int init_acpi(struct device *dev) 246{ 247 u16 sock_ind; 248 int ret; 249 250 ret = hsmp_get_uid(dev, &sock_ind); --- 18 unchanged lines hidden (view full) --- 269 } 270 271 ret = hsmp_cache_proto_ver(sock_ind); 272 if (ret) { 273 dev_err(dev, "Failed to read HSMP protocol version\n"); 274 return ret; 275 } 276 |
277 if (hsmp_pdev.proto_ver == HSMP_PROTO_VER6) { 278 ret = hsmp_get_tbl_dram_base(sock_ind); 279 if (ret) 280 dev_err(dev, "Failed to init metric table\n"); 281 } 282 |
|
278 return ret; 279} 280 | 283 return ret; 284} 285 |
286static struct bin_attribute hsmp_metric_tbl_attr = { 287 .attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444}, 288 .read = hsmp_metric_tbl_acpi_read, 289 .size = sizeof(struct hsmp_metric_table), 290}; 291 292static struct bin_attribute *hsmp_attr_list[] = { 293 &hsmp_metric_tbl_attr, 294 NULL 295}; 296 297static struct attribute_group hsmp_attr_grp = { 298 .bin_attrs = hsmp_attr_list, 299 .is_bin_visible = hsmp_is_sock_attr_visible, 300}; 301 302static const struct attribute_group *hsmp_groups[] = { 303 &hsmp_attr_grp, 304 NULL 305}; 306 |
|
281static const struct acpi_device_id amd_hsmp_acpi_ids[] = { 282 {ACPI_HSMP_DEVICE_HID, 0}, 283 {} 284}; 285MODULE_DEVICE_TABLE(acpi, amd_hsmp_acpi_ids); 286 287static int hsmp_acpi_probe(struct platform_device *pdev) 288{ --- 12 unchanged lines hidden (view full) --- 301 } 302 303 ret = init_acpi(&pdev->dev); 304 if (ret) { 305 dev_err(&pdev->dev, "Failed to initialize HSMP interface.\n"); 306 return ret; 307 } 308 | 307static const struct acpi_device_id amd_hsmp_acpi_ids[] = { 308 {ACPI_HSMP_DEVICE_HID, 0}, 309 {} 310}; 311MODULE_DEVICE_TABLE(acpi, amd_hsmp_acpi_ids); 312 313static int hsmp_acpi_probe(struct platform_device *pdev) 314{ --- 12 unchanged lines hidden (view full) --- 327 } 328 329 ret = init_acpi(&pdev->dev); 330 if (ret) { 331 dev_err(&pdev->dev, "Failed to initialize HSMP interface.\n"); 332 return ret; 333 } 334 |
309 ret = hsmp_create_acpi_sysfs_if(&pdev->dev); 310 if (ret) 311 dev_err(&pdev->dev, "Failed to create HSMP sysfs interface\n"); 312 | |
313 if (!hsmp_pdev.is_probed) { 314 ret = hsmp_misc_register(&pdev->dev); 315 if (ret) 316 return ret; 317 hsmp_pdev.is_probed = true; 318 } 319 320 return 0; --- 12 unchanged lines hidden (view full) --- 333} 334 335static struct platform_driver amd_hsmp_driver = { 336 .probe = hsmp_acpi_probe, 337 .remove = hsmp_acpi_remove, 338 .driver = { 339 .name = DRIVER_NAME, 340 .acpi_match_table = amd_hsmp_acpi_ids, | 335 if (!hsmp_pdev.is_probed) { 336 ret = hsmp_misc_register(&pdev->dev); 337 if (ret) 338 return ret; 339 hsmp_pdev.is_probed = true; 340 } 341 342 return 0; --- 12 unchanged lines hidden (view full) --- 355} 356 357static struct platform_driver amd_hsmp_driver = { 358 .probe = hsmp_acpi_probe, 359 .remove = hsmp_acpi_remove, 360 .driver = { 361 .name = DRIVER_NAME, 362 .acpi_match_table = amd_hsmp_acpi_ids, |
363 .dev_groups = hsmp_groups, |
|
341 }, 342}; 343 344module_platform_driver(amd_hsmp_driver); 345 346MODULE_IMPORT_NS(AMD_HSMP); 347MODULE_DESCRIPTION("AMD HSMP Platform Interface Driver"); 348MODULE_VERSION(DRIVER_VERSION); 349MODULE_LICENSE("GPL"); | 364 }, 365}; 366 367module_platform_driver(amd_hsmp_driver); 368 369MODULE_IMPORT_NS(AMD_HSMP); 370MODULE_DESCRIPTION("AMD HSMP Platform Interface Driver"); 371MODULE_VERSION(DRIVER_VERSION); 372MODULE_LICENSE("GPL"); |