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/miscdevice.h>
17 #include <linux/pci.h>
18 #include <linux/semaphore.h>
19 #include <linux/sysfs.h>
20
21 #define HSMP_METRICS_TABLE_NAME "metrics_bin"
22
23 #define HSMP_ATTR_GRP_NAME_SIZE 10
24
25 #define HSMP_CDEV_NAME "hsmp_cdev"
26 #define HSMP_DEVNODE_NAME "hsmp"
27 #define ACPI_HSMP_DEVICE_HID "AMDI0097"
28
29 #define DRIVER_VERSION "2.5"
30
31 struct hsmp_mbaddr_info {
32 u32 base_addr;
33 u32 msg_id_off;
34 u32 msg_resp_off;
35 u32 msg_arg_off;
36 u32 size;
37 };
38
39 struct hsmp_socket {
40 struct bin_attribute hsmp_attr;
41 struct hsmp_mbaddr_info mbinfo;
42 void __iomem *metric_tbl_addr;
43 void __iomem *virt_base_addr;
44 struct semaphore hsmp_sem;
45 char name[HSMP_ATTR_GRP_NAME_SIZE];
46 struct device *dev;
47 u16 sock_ind;
48 int (*amd_hsmp_rdwr)(struct hsmp_socket *sock, u32 off, u32 *val, bool rw);
49 };
50
51 struct hsmp_plat_device {
52 struct miscdevice mdev;
53 struct hsmp_socket *sock;
54 u32 proto_ver;
55 u16 num_sockets;
56 bool is_probed;
57 };
58
59 int hsmp_cache_proto_ver(u16 sock_ind);
60 int hsmp_test(u16 sock_ind, u32 value);
61 long hsmp_ioctl(struct file *fp, unsigned int cmd, unsigned long arg);
62 void hsmp_misc_deregister(void);
63 int hsmp_misc_register(struct device *dev);
64 int hsmp_get_tbl_dram_base(u16 sock_ind);
65 ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t size);
66 struct hsmp_plat_device *get_hsmp_pdev(void);
67 #if IS_REACHABLE(CONFIG_HWMON)
68 int hsmp_create_sensor(struct device *dev, u16 sock_ind);
69 #else
hsmp_create_sensor(struct device * dev,u16 sock_ind)70 static inline int hsmp_create_sensor(struct device *dev, u16 sock_ind) { return 0; }
71 #endif
72 int hsmp_msg_get_nargs(u16 sock_ind, u32 msg_id, u32 *data, u8 num_args);
73 #endif /* HSMP_H */
74