xref: /openbmc/linux/drivers/peci/internal.h (revision ecefa105)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2018-2021 Intel Corporation */
3 
4 #ifndef __PECI_INTERNAL_H
5 #define __PECI_INTERNAL_H
6 
7 #include <linux/device.h>
8 #include <linux/types.h>
9 
10 struct peci_controller;
11 struct attribute_group;
12 struct peci_device;
13 struct peci_request;
14 
15 /* PECI CPU address range 0x30-0x37 */
16 #define PECI_BASE_ADDR		0x30
17 #define PECI_DEVICE_NUM_MAX	8
18 
19 struct peci_request *peci_request_alloc(struct peci_device *device, u8 tx_len, u8 rx_len);
20 void peci_request_free(struct peci_request *req);
21 
22 int peci_request_status(struct peci_request *req);
23 
24 u64 peci_request_dib_read(struct peci_request *req);
25 s16 peci_request_temp_read(struct peci_request *req);
26 
27 u8 peci_request_data_readb(struct peci_request *req);
28 u16 peci_request_data_readw(struct peci_request *req);
29 u32 peci_request_data_readl(struct peci_request *req);
30 u64 peci_request_data_readq(struct peci_request *req);
31 
32 struct peci_request *peci_xfer_get_dib(struct peci_device *device);
33 struct peci_request *peci_xfer_get_temp(struct peci_device *device);
34 
35 struct peci_request *peci_xfer_pkg_cfg_readb(struct peci_device *device, u8 index, u16 param);
36 struct peci_request *peci_xfer_pkg_cfg_readw(struct peci_device *device, u8 index, u16 param);
37 struct peci_request *peci_xfer_pkg_cfg_readl(struct peci_device *device, u8 index, u16 param);
38 struct peci_request *peci_xfer_pkg_cfg_readq(struct peci_device *device, u8 index, u16 param);
39 
40 struct peci_request *peci_xfer_pci_cfg_local_readb(struct peci_device *device,
41 						   u8 bus, u8 dev, u8 func, u16 reg);
42 struct peci_request *peci_xfer_pci_cfg_local_readw(struct peci_device *device,
43 						   u8 bus, u8 dev, u8 func, u16 reg);
44 struct peci_request *peci_xfer_pci_cfg_local_readl(struct peci_device *device,
45 						   u8 bus, u8 dev, u8 func, u16 reg);
46 
47 struct peci_request *peci_xfer_ep_pci_cfg_local_readb(struct peci_device *device, u8 seg,
48 						      u8 bus, u8 dev, u8 func, u16 reg);
49 struct peci_request *peci_xfer_ep_pci_cfg_local_readw(struct peci_device *device, u8 seg,
50 						      u8 bus, u8 dev, u8 func, u16 reg);
51 struct peci_request *peci_xfer_ep_pci_cfg_local_readl(struct peci_device *device, u8 seg,
52 						      u8 bus, u8 dev, u8 func, u16 reg);
53 
54 struct peci_request *peci_xfer_ep_pci_cfg_readb(struct peci_device *device, u8 seg,
55 						u8 bus, u8 dev, u8 func, u16 reg);
56 struct peci_request *peci_xfer_ep_pci_cfg_readw(struct peci_device *device, u8 seg,
57 						u8 bus, u8 dev, u8 func, u16 reg);
58 struct peci_request *peci_xfer_ep_pci_cfg_readl(struct peci_device *device, u8 seg,
59 						u8 bus, u8 dev, u8 func, u16 reg);
60 
61 struct peci_request *peci_xfer_ep_mmio32_readl(struct peci_device *device, u8 bar, u8 seg,
62 					       u8 bus, u8 dev, u8 func, u64 offset);
63 
64 struct peci_request *peci_xfer_ep_mmio64_readl(struct peci_device *device, u8 bar, u8 seg,
65 					       u8 bus, u8 dev, u8 func, u64 offset);
66 /**
67  * struct peci_device_id - PECI device data to match
68  * @data: pointer to driver private data specific to device
69  * @family: device family
70  * @model: device model
71  */
72 struct peci_device_id {
73 	const void *data;
74 	u16 family;
75 	u8 model;
76 };
77 
78 extern struct device_type peci_device_type;
79 extern const struct attribute_group *peci_device_groups[];
80 
81 int peci_device_create(struct peci_controller *controller, u8 addr);
82 void peci_device_destroy(struct peci_device *device);
83 
84 extern struct bus_type peci_bus_type;
85 extern const struct attribute_group *peci_bus_groups[];
86 
87 /**
88  * struct peci_driver - PECI driver
89  * @driver: inherit device driver
90  * @probe: probe callback
91  * @remove: remove callback
92  * @id_table: PECI device match table to decide which device to bind
93  */
94 struct peci_driver {
95 	struct device_driver driver;
96 	int (*probe)(struct peci_device *device, const struct peci_device_id *id);
97 	void (*remove)(struct peci_device *device);
98 	const struct peci_device_id *id_table;
99 };
100 
101 static inline struct peci_driver *to_peci_driver(struct device_driver *d)
102 {
103 	return container_of(d, struct peci_driver, driver);
104 }
105 
106 int __peci_driver_register(struct peci_driver *driver, struct module *owner,
107 			   const char *mod_name);
108 /**
109  * peci_driver_register() - register PECI driver
110  * @driver: the driver to be registered
111  *
112  * PECI drivers that don't need to do anything special in module init should
113  * use the convenience "module_peci_driver" macro instead
114  *
115  * Return: zero on success, else a negative error code.
116  */
117 #define peci_driver_register(driver) \
118 	__peci_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
119 void peci_driver_unregister(struct peci_driver *driver);
120 
121 /**
122  * module_peci_driver() - helper macro for registering a modular PECI driver
123  * @__peci_driver: peci_driver struct
124  *
125  * Helper macro for PECI drivers which do not do anything special in module
126  * init/exit. This eliminates a lot of boilerplate. Each module may only
127  * use this macro once, and calling it replaces module_init() and module_exit()
128  */
129 #define module_peci_driver(__peci_driver) \
130 	module_driver(__peci_driver, peci_driver_register, peci_driver_unregister)
131 
132 extern struct device_type peci_controller_type;
133 
134 int peci_controller_scan_devices(struct peci_controller *controller);
135 
136 #endif /* __PECI_INTERNAL_H */
137