1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2018-2021 Intel Corporation */
4 #ifndef __PECI_INTERNAL_H
5 #define __PECI_INTERNAL_H
7 #include <linux/device.h>
8 #include <linux/types.h>
10 struct peci_controller
;
11 struct attribute_group
;
15 /* PECI CPU address range 0x30-0x37 */
16 #define PECI_BASE_ADDR 0x30
17 #define PECI_DEVICE_NUM_MAX 8
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
);
22 int peci_request_status(struct peci_request
*req
);
24 u64
peci_request_dib_read(struct peci_request
*req
);
25 s16
peci_request_temp_read(struct peci_request
*req
);
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
);
32 struct peci_request
*peci_xfer_get_dib(struct peci_device
*device
);
33 struct peci_request
*peci_xfer_get_temp(struct peci_device
*device
);
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
);
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
);
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
);
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
);
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
);
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
);
67 * struct peci_device_id - PECI device data to match
68 * @data: pointer to driver private data specific to device
69 * @x86_vfm: device vendor-family-model
71 struct peci_device_id
{
76 extern const struct device_type peci_device_type
;
77 extern const struct attribute_group
*peci_device_groups
[];
79 int peci_device_create(struct peci_controller
*controller
, u8 addr
);
80 void peci_device_destroy(struct peci_device
*device
);
82 extern const struct bus_type peci_bus_type
;
83 extern const struct attribute_group
*peci_bus_groups
[];
86 * struct peci_driver - PECI driver
87 * @driver: inherit device driver
88 * @probe: probe callback
89 * @remove: remove callback
90 * @id_table: PECI device match table to decide which device to bind
93 struct device_driver driver
;
94 int (*probe
)(struct peci_device
*device
, const struct peci_device_id
*id
);
95 void (*remove
)(struct peci_device
*device
);
96 const struct peci_device_id
*id_table
;
99 #define to_peci_driver(__drv) container_of_const(__drv, struct peci_driver, driver)
101 int __peci_driver_register(struct peci_driver
*driver
, struct module
*owner
,
102 const char *mod_name
);
104 * peci_driver_register() - register PECI driver
105 * @driver: the driver to be registered
107 * PECI drivers that don't need to do anything special in module init should
108 * use the convenience "module_peci_driver" macro instead
110 * Return: zero on success, else a negative error code.
112 #define peci_driver_register(driver) \
113 __peci_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
114 void peci_driver_unregister(struct peci_driver
*driver
);
117 * module_peci_driver() - helper macro for registering a modular PECI driver
118 * @__peci_driver: peci_driver struct
120 * Helper macro for PECI drivers which do not do anything special in module
121 * init/exit. This eliminates a lot of boilerplate. Each module may only
122 * use this macro once, and calling it replaces module_init() and module_exit()
124 #define module_peci_driver(__peci_driver) \
125 module_driver(__peci_driver, peci_driver_register, peci_driver_unregister)
127 extern const struct device_type peci_controller_type
;
129 int peci_controller_scan_devices(struct peci_controller
*controller
);
131 #endif /* __PECI_INTERNAL_H */