xref: /openbmc/linux/drivers/peci/internal.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
16523d3b2SIwona Winiarska /* SPDX-License-Identifier: GPL-2.0-only */
26523d3b2SIwona Winiarska /* Copyright (c) 2018-2021 Intel Corporation */
36523d3b2SIwona Winiarska 
46523d3b2SIwona Winiarska #ifndef __PECI_INTERNAL_H
56523d3b2SIwona Winiarska #define __PECI_INTERNAL_H
66523d3b2SIwona Winiarska 
76523d3b2SIwona Winiarska #include <linux/device.h>
86523d3b2SIwona Winiarska #include <linux/types.h>
96523d3b2SIwona Winiarska 
106523d3b2SIwona Winiarska struct peci_controller;
1142bed52bSIwona Winiarska struct attribute_group;
1252857e68SIwona Winiarska struct peci_device;
1352857e68SIwona Winiarska struct peci_request;
1452857e68SIwona Winiarska 
1552857e68SIwona Winiarska /* PECI CPU address range 0x30-0x37 */
1652857e68SIwona Winiarska #define PECI_BASE_ADDR		0x30
1752857e68SIwona Winiarska #define PECI_DEVICE_NUM_MAX	8
1852857e68SIwona Winiarska 
1952857e68SIwona Winiarska struct peci_request *peci_request_alloc(struct peci_device *device, u8 tx_len, u8 rx_len);
2052857e68SIwona Winiarska void peci_request_free(struct peci_request *req);
2152857e68SIwona Winiarska 
226b8145b0SIwona Winiarska int peci_request_status(struct peci_request *req);
236b8145b0SIwona Winiarska 
246b8145b0SIwona Winiarska u64 peci_request_dib_read(struct peci_request *req);
25*93e1821cSIwona Winiarska s16 peci_request_temp_read(struct peci_request *req);
266b8145b0SIwona Winiarska 
276b8145b0SIwona Winiarska u8 peci_request_data_readb(struct peci_request *req);
286b8145b0SIwona Winiarska u16 peci_request_data_readw(struct peci_request *req);
296b8145b0SIwona Winiarska u32 peci_request_data_readl(struct peci_request *req);
306b8145b0SIwona Winiarska u64 peci_request_data_readq(struct peci_request *req);
316b8145b0SIwona Winiarska 
326b8145b0SIwona Winiarska struct peci_request *peci_xfer_get_dib(struct peci_device *device);
336b8145b0SIwona Winiarska struct peci_request *peci_xfer_get_temp(struct peci_device *device);
346b8145b0SIwona Winiarska 
356b8145b0SIwona Winiarska struct peci_request *peci_xfer_pkg_cfg_readb(struct peci_device *device, u8 index, u16 param);
366b8145b0SIwona Winiarska struct peci_request *peci_xfer_pkg_cfg_readw(struct peci_device *device, u8 index, u16 param);
376b8145b0SIwona Winiarska struct peci_request *peci_xfer_pkg_cfg_readl(struct peci_device *device, u8 index, u16 param);
386b8145b0SIwona Winiarska struct peci_request *peci_xfer_pkg_cfg_readq(struct peci_device *device, u8 index, u16 param);
396b8145b0SIwona Winiarska 
40*93e1821cSIwona Winiarska struct peci_request *peci_xfer_pci_cfg_local_readb(struct peci_device *device,
41*93e1821cSIwona Winiarska 						   u8 bus, u8 dev, u8 func, u16 reg);
42*93e1821cSIwona Winiarska struct peci_request *peci_xfer_pci_cfg_local_readw(struct peci_device *device,
43*93e1821cSIwona Winiarska 						   u8 bus, u8 dev, u8 func, u16 reg);
44*93e1821cSIwona Winiarska struct peci_request *peci_xfer_pci_cfg_local_readl(struct peci_device *device,
45*93e1821cSIwona Winiarska 						   u8 bus, u8 dev, u8 func, u16 reg);
46*93e1821cSIwona Winiarska 
47*93e1821cSIwona Winiarska struct peci_request *peci_xfer_ep_pci_cfg_local_readb(struct peci_device *device, u8 seg,
48*93e1821cSIwona Winiarska 						      u8 bus, u8 dev, u8 func, u16 reg);
49*93e1821cSIwona Winiarska struct peci_request *peci_xfer_ep_pci_cfg_local_readw(struct peci_device *device, u8 seg,
50*93e1821cSIwona Winiarska 						      u8 bus, u8 dev, u8 func, u16 reg);
51*93e1821cSIwona Winiarska struct peci_request *peci_xfer_ep_pci_cfg_local_readl(struct peci_device *device, u8 seg,
52*93e1821cSIwona Winiarska 						      u8 bus, u8 dev, u8 func, u16 reg);
53*93e1821cSIwona Winiarska 
54*93e1821cSIwona Winiarska struct peci_request *peci_xfer_ep_pci_cfg_readb(struct peci_device *device, u8 seg,
55*93e1821cSIwona Winiarska 						u8 bus, u8 dev, u8 func, u16 reg);
56*93e1821cSIwona Winiarska struct peci_request *peci_xfer_ep_pci_cfg_readw(struct peci_device *device, u8 seg,
57*93e1821cSIwona Winiarska 						u8 bus, u8 dev, u8 func, u16 reg);
58*93e1821cSIwona Winiarska struct peci_request *peci_xfer_ep_pci_cfg_readl(struct peci_device *device, u8 seg,
59*93e1821cSIwona Winiarska 						u8 bus, u8 dev, u8 func, u16 reg);
60*93e1821cSIwona Winiarska 
61*93e1821cSIwona Winiarska struct peci_request *peci_xfer_ep_mmio32_readl(struct peci_device *device, u8 bar, u8 seg,
62*93e1821cSIwona Winiarska 					       u8 bus, u8 dev, u8 func, u64 offset);
63*93e1821cSIwona Winiarska 
64*93e1821cSIwona Winiarska struct peci_request *peci_xfer_ep_mmio64_readl(struct peci_device *device, u8 bar, u8 seg,
65*93e1821cSIwona Winiarska 					       u8 bus, u8 dev, u8 func, u64 offset);
666b8145b0SIwona Winiarska /**
676b8145b0SIwona Winiarska  * struct peci_device_id - PECI device data to match
686b8145b0SIwona Winiarska  * @data: pointer to driver private data specific to device
696b8145b0SIwona Winiarska  * @family: device family
706b8145b0SIwona Winiarska  * @model: device model
716b8145b0SIwona Winiarska  */
726b8145b0SIwona Winiarska struct peci_device_id {
736b8145b0SIwona Winiarska 	const void *data;
746b8145b0SIwona Winiarska 	u16 family;
756b8145b0SIwona Winiarska 	u8 model;
766b8145b0SIwona Winiarska };
776b8145b0SIwona Winiarska 
7852857e68SIwona Winiarska extern struct device_type peci_device_type;
7942bed52bSIwona Winiarska extern const struct attribute_group *peci_device_groups[];
8052857e68SIwona Winiarska 
8152857e68SIwona Winiarska int peci_device_create(struct peci_controller *controller, u8 addr);
8252857e68SIwona Winiarska void peci_device_destroy(struct peci_device *device);
836523d3b2SIwona Winiarska 
846523d3b2SIwona Winiarska extern struct bus_type peci_bus_type;
8542bed52bSIwona Winiarska extern const struct attribute_group *peci_bus_groups[];
866523d3b2SIwona Winiarska 
876b8145b0SIwona Winiarska /**
886b8145b0SIwona Winiarska  * struct peci_driver - PECI driver
896b8145b0SIwona Winiarska  * @driver: inherit device driver
906b8145b0SIwona Winiarska  * @probe: probe callback
916b8145b0SIwona Winiarska  * @remove: remove callback
926b8145b0SIwona Winiarska  * @id_table: PECI device match table to decide which device to bind
936b8145b0SIwona Winiarska  */
946b8145b0SIwona Winiarska struct peci_driver {
956b8145b0SIwona Winiarska 	struct device_driver driver;
966b8145b0SIwona Winiarska 	int (*probe)(struct peci_device *device, const struct peci_device_id *id);
976b8145b0SIwona Winiarska 	void (*remove)(struct peci_device *device);
986b8145b0SIwona Winiarska 	const struct peci_device_id *id_table;
996b8145b0SIwona Winiarska };
1006b8145b0SIwona Winiarska 
to_peci_driver(struct device_driver * d)1016b8145b0SIwona Winiarska static inline struct peci_driver *to_peci_driver(struct device_driver *d)
1026b8145b0SIwona Winiarska {
1036b8145b0SIwona Winiarska 	return container_of(d, struct peci_driver, driver);
1046b8145b0SIwona Winiarska }
1056b8145b0SIwona Winiarska 
1066b8145b0SIwona Winiarska int __peci_driver_register(struct peci_driver *driver, struct module *owner,
1076b8145b0SIwona Winiarska 			   const char *mod_name);
1086b8145b0SIwona Winiarska /**
1096b8145b0SIwona Winiarska  * peci_driver_register() - register PECI driver
1106b8145b0SIwona Winiarska  * @driver: the driver to be registered
1116b8145b0SIwona Winiarska  *
1126b8145b0SIwona Winiarska  * PECI drivers that don't need to do anything special in module init should
1136b8145b0SIwona Winiarska  * use the convenience "module_peci_driver" macro instead
1146b8145b0SIwona Winiarska  *
1156b8145b0SIwona Winiarska  * Return: zero on success, else a negative error code.
1166b8145b0SIwona Winiarska  */
1176b8145b0SIwona Winiarska #define peci_driver_register(driver) \
1186b8145b0SIwona Winiarska 	__peci_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
1196b8145b0SIwona Winiarska void peci_driver_unregister(struct peci_driver *driver);
1206b8145b0SIwona Winiarska 
1216b8145b0SIwona Winiarska /**
1226b8145b0SIwona Winiarska  * module_peci_driver() - helper macro for registering a modular PECI driver
1236b8145b0SIwona Winiarska  * @__peci_driver: peci_driver struct
1246b8145b0SIwona Winiarska  *
1256b8145b0SIwona Winiarska  * Helper macro for PECI drivers which do not do anything special in module
1266b8145b0SIwona Winiarska  * init/exit. This eliminates a lot of boilerplate. Each module may only
1276b8145b0SIwona Winiarska  * use this macro once, and calling it replaces module_init() and module_exit()
1286b8145b0SIwona Winiarska  */
1296b8145b0SIwona Winiarska #define module_peci_driver(__peci_driver) \
1306b8145b0SIwona Winiarska 	module_driver(__peci_driver, peci_driver_register, peci_driver_unregister)
1316b8145b0SIwona Winiarska 
1326523d3b2SIwona Winiarska extern struct device_type peci_controller_type;
1336523d3b2SIwona Winiarska 
13442bed52bSIwona Winiarska int peci_controller_scan_devices(struct peci_controller *controller);
13542bed52bSIwona Winiarska 
1366523d3b2SIwona Winiarska #endif /* __PECI_INTERNAL_H */
137