xref: /linux/drivers/platform/x86/amd/hsmp/hsmp.h (revision 024bfd2e9d80d7131f1178eb2235030b96f7ef0e)
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/miscdevice.h>
16 #include <linux/pci.h>
17 #include <linux/semaphore.h>
18 #include <linux/sysfs.h>
19 
20 #define HSMP_METRICS_TABLE_NAME	"metrics_bin"
21 
22 #define HSMP_ATTR_GRP_NAME_SIZE	10
23 
24 #define MAX_AMD_SOCKETS 8
25 
26 #define HSMP_CDEV_NAME		"hsmp_cdev"
27 #define HSMP_DEVNODE_NAME	"hsmp"
28 
29 struct hsmp_mbaddr_info {
30 	u32 base_addr;
31 	u32 msg_id_off;
32 	u32 msg_resp_off;
33 	u32 msg_arg_off;
34 	u32 size;
35 };
36 
37 struct hsmp_socket {
38 	struct bin_attribute hsmp_attr;
39 	struct hsmp_mbaddr_info mbinfo;
40 	void __iomem *metric_tbl_addr;
41 	void __iomem *virt_base_addr;
42 	struct semaphore hsmp_sem;
43 	char name[HSMP_ATTR_GRP_NAME_SIZE];
44 	struct pci_dev *root;
45 	struct device *dev;
46 	u16 sock_ind;
47 	int (*amd_hsmp_rdwr)(struct hsmp_socket *sock, u32 off, u32 *val, bool rw);
48 };
49 
50 struct hsmp_plat_device {
51 	struct miscdevice mdev;
52 	struct hsmp_socket *sock;
53 	u32 proto_ver;
54 	u16 num_sockets;
55 	bool is_probed;
56 };
57 
58 int hsmp_cache_proto_ver(u16 sock_ind);
59 int hsmp_test(u16 sock_ind, u32 value);
60 long hsmp_ioctl(struct file *fp, unsigned int cmd, unsigned long arg);
61 void hsmp_misc_deregister(void);
62 int hsmp_misc_register(struct device *dev);
63 int hsmp_get_tbl_dram_base(u16 sock_ind);
64 ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t size);
65 struct hsmp_plat_device *get_hsmp_pdev(void);
66 #endif /* HSMP_H */
67