1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * AMD HSMP Platform Driver 4 * Copyright (c) 2024, AMD. 5 * All Rights Reserved. 6 * 7 * Header file for HSMP driver 8 */ 9 10 #ifndef HSMP_H 11 #define HSMP_H 12 13 #include <linux/compiler_types.h> 14 #include <linux/device.h> 15 #include <linux/hwmon.h> 16 #include <linux/kconfig.h> 17 #include <linux/miscdevice.h> 18 #include <linux/pci.h> 19 #include <linux/semaphore.h> 20 #include <linux/sysfs.h> 21 22 #define HSMP_METRICS_TABLE_NAME "metrics_bin" 23 24 #define HSMP_ATTR_GRP_NAME_SIZE 10 25 26 #define HSMP_CDEV_NAME "hsmp_cdev" 27 #define HSMP_DEVNODE_NAME "hsmp" 28 #define ACPI_HSMP_DEVICE_HID "AMDI0097" 29 30 #define DRIVER_VERSION "2.5" 31 32 struct hsmp_mbaddr_info { 33 u32 base_addr; 34 u32 msg_id_off; 35 u32 msg_resp_off; 36 u32 msg_arg_off; 37 u32 size; 38 }; 39 40 struct hsmp_socket { 41 struct bin_attribute hsmp_attr; 42 struct hsmp_mbaddr_info mbinfo; 43 void __iomem *metric_tbl_addr; 44 void __iomem *virt_base_addr; 45 struct semaphore hsmp_sem; 46 char name[HSMP_ATTR_GRP_NAME_SIZE]; 47 struct device *dev; 48 u16 sock_ind; 49 int (*amd_hsmp_rdwr)(struct hsmp_socket *sock, u32 off, u32 *val, bool rw); 50 }; 51 52 struct hsmp_plat_device { 53 struct miscdevice mdev; 54 struct hsmp_socket *sock; 55 u32 proto_ver; 56 u16 num_sockets; 57 bool is_probed; 58 }; 59 60 int hsmp_cache_proto_ver(u16 sock_ind); 61 int hsmp_test(u16 sock_ind, u32 value); 62 long hsmp_ioctl(struct file *fp, unsigned int cmd, unsigned long arg); 63 void hsmp_misc_deregister(void); 64 int hsmp_misc_register(struct device *dev); 65 int hsmp_get_tbl_dram_base(u16 sock_ind); 66 ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t size); 67 struct hsmp_plat_device *get_hsmp_pdev(void); 68 #if IS_ENABLED(CONFIG_HWMON) 69 int hsmp_create_sensor(struct device *dev, u16 sock_ind); 70 #else 71 static inline int hsmp_create_sensor(struct device *dev, u16 sock_ind) { return 0; } 72 #endif 73 int hsmp_msg_get_nargs(u16 sock_ind, u32 msg_id, u32 *data, u8 num_args); 74 #endif /* HSMP_H */ 75