| /* SPDX-License-Identifier: GPL-2.0 */ | |
| /* | |
| * AMD HSMP Platform Driver | |
| * Copyright (c) 2024, AMD. | |
| * All Rights Reserved. | |
| * | |
| * Header file for HSMP driver | |
| */ | |
| #ifndef HSMP_H | |
| #define HSMP_H | |
| #include <asm/amd/hsmp.h> | |
| #include <linux/acpi.h> | |
| #include <linux/compiler_types.h> | |
| #include <linux/device.h> | |
| #include <linux/hwmon.h> | |
| #include <linux/kconfig.h> | |
| #include <linux/miscdevice.h> | |
| #include <linux/mutex.h> | |
| #include <linux/pci.h> | |
| #include <linux/processor.h> | |
| #include <linux/rwsem.h> | |
| #include <linux/semaphore.h> | |
| #include <linux/sysfs.h> | |
| #include <linux/types.h> | |
| #define HSMP_METRICS_TABLE_NAME "metrics_bin" | |
| #define HSMP_ATTR_GRP_NAME_SIZE 10 | |
| #define HSMP_CDEV_NAME "hsmp_cdev" | |
| #define HSMP_DEVNODE_NAME "hsmp" | |
| #define ACPI_HSMP_DEVICE_HID "AMDI0097" | |
| #define DRIVER_VERSION "2.6" | |
| /* True when the ACPI-reported PM profile indicates a client platform */ | |
| static inline bool is_client_platform(void) | |
| { | |
| if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) | |
| return false; | |
| #if IS_ENABLED(CONFIG_ACPI) | |
| switch (acpi_gbl_FADT.preferred_profile) { | |
| case PM_DESKTOP: | |
| case PM_MOBILE: | |
| case PM_TABLET: | |
| return true; | |
| default: | |
| return false; | |
| } | |
| #else | |
| return false; | |
| #endif | |
| } | |
| struct hsmp_mbaddr_info { | |
| u32 base_addr; | |
| u32 msg_id_off; | |
| u32 msg_resp_off; | |
| u32 msg_arg_off; | |
| u32 size; | |
| }; | |
| struct hsmp_socket { | |
| struct bin_attribute hsmp_attr; | |
| struct hsmp_mbaddr_info mbinfo; | |
| void __iomem *metric_tbl_addr; | |
| /* Size of the region mapped at @metric_tbl_addr, as reported by SMU */ | |
| size_t metric_tbl_size; | |
| void __iomem *virt_base_addr; | |
| struct semaphore hsmp_sem; | |
| /* Serializes HSMP_GET_METRIC_TABLE fill-and-copy for this socket */ | |
| struct mutex metric_read_lock; | |
| char name[HSMP_ATTR_GRP_NAME_SIZE]; | |
| struct device *dev; | |
| u16 sock_ind; | |
| int (*amd_hsmp_rdwr)(struct hsmp_socket *sock, u32 off, u32 *val, bool rw); | |
| }; | |
| struct hsmp_plat_device { | |
| struct miscdevice mdev; | |
| struct hsmp_socket *sock; | |
| u32 proto_ver; | |
| u16 num_sockets; | |
| }; | |
| int hsmp_cache_proto_ver(u16 sock_ind); | |
| int hsmp_test(u16 sock_ind, u32 value); | |
| long hsmp_ioctl(struct file *fp, unsigned int cmd, unsigned long arg); | |
| void hsmp_misc_deregister(void); | |
| int hsmp_misc_register(struct device *dev); | |
| int hsmp_get_tbl_dram_base(u16 sock_ind); | |
| void hsmp_unmap_metric_tbls(struct hsmp_plat_device *pdev); | |
| void hsmp_init_metric_read_locks(struct hsmp_plat_device *pdev); | |
| void hsmp_destroy_metric_read_locks(struct hsmp_plat_device *pdev); | |
| ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t size); | |
| struct hsmp_plat_device *get_hsmp_pdev(void); | |
| #if IS_ENABLED(CONFIG_HWMON) | |
| int hsmp_create_sensor(struct device *dev, u16 sock_ind); | |
| #else | |
| static inline int hsmp_create_sensor(struct device *dev, u16 sock_ind) { return 0; } | |
| #endif | |
| int hsmp_msg_get_nargs(u16 sock_ind, u32 msg_id, u32 *data, u8 num_args); | |
| /* | |
| * Gates the HSMP data plane: hsmp_send_message() takes it for read; probe and | |
| * remove take it for write to bring sockets up and tear them down. | |
| */ | |
| extern struct rw_semaphore hsmp_sock_rwsem; | |
| #endif /* HSMP_H */ |