1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Copyright (c) 2018-2021 Intel Corporation */ 3 4 #ifndef __LINUX_PECI_H 5 #define __LINUX_PECI_H 6 7 #include <linux/device.h> 8 #include <linux/kernel.h> 9 #include <linux/mutex.h> 10 #include <linux/types.h> 11 12 /* 13 * Currently we don't support any PECI command over 32 bytes. 14 */ 15 #define PECI_REQUEST_MAX_BUF_SIZE 32 16 17 struct peci_controller; 18 struct peci_request; 19 20 /** 21 * struct peci_controller_ops - PECI controller specific methods 22 * @xfer: PECI transfer function 23 * 24 * PECI controllers may have different hardware interfaces - the drivers 25 * implementing PECI controllers can use this structure to abstract away those 26 * differences by exposing a common interface for PECI core. 27 */ 28 struct peci_controller_ops { 29 int (*xfer)(struct peci_controller *controller, u8 addr, struct peci_request *req); 30 }; 31 32 /** 33 * struct peci_controller - PECI controller 34 * @dev: device object to register PECI controller to the device model 35 * @ops: pointer to device specific controller operations 36 * @bus_lock: lock used to protect multiple callers 37 * @id: PECI controller ID 38 * 39 * PECI controllers usually connect to their drivers using non-PECI bus, 40 * such as the platform bus. 41 * Each PECI controller can communicate with one or more PECI devices. 42 */ 43 struct peci_controller { 44 struct device dev; 45 struct peci_controller_ops *ops; 46 struct mutex bus_lock; /* held for the duration of xfer */ 47 u8 id; 48 }; 49 50 struct peci_controller *devm_peci_controller_add(struct device *parent, 51 struct peci_controller_ops *ops); 52 to_peci_controller(void * d)53static inline struct peci_controller *to_peci_controller(void *d) 54 { 55 return container_of(d, struct peci_controller, dev); 56 } 57 58 /** 59 * struct peci_device - PECI device 60 * @dev: device object to register PECI device to the device model 61 * @controller: manages the bus segment hosting this PECI device 62 * @info: PECI device characteristics 63 * @info.family: device family 64 * @info.model: device model 65 * @info.peci_revision: PECI revision supported by the PECI device 66 * @info.socket_id: the socket ID represented by the PECI device 67 * @addr: address used on the PECI bus connected to the parent controller 68 * @deleted: indicates that PECI device was already deleted 69 * 70 * A peci_device identifies a single device (i.e. CPU) connected to a PECI bus. 71 * The behaviour exposed to the rest of the system is defined by the PECI driver 72 * managing the device. 73 */ 74 struct peci_device { 75 struct device dev; 76 struct { 77 u16 family; 78 u8 model; 79 u8 peci_revision; 80 u8 socket_id; 81 } info; 82 u8 addr; 83 bool deleted; 84 }; 85 to_peci_device(struct device * d)86static inline struct peci_device *to_peci_device(struct device *d) 87 { 88 return container_of(d, struct peci_device, dev); 89 } 90 91 /** 92 * struct peci_request - PECI request 93 * @device: PECI device to which the request is sent 94 * @tx: TX buffer specific data 95 * @tx.buf: TX buffer 96 * @tx.len: transfer data length in bytes 97 * @rx: RX buffer specific data 98 * @rx.buf: RX buffer 99 * @rx.len: received data length in bytes 100 * 101 * A peci_request represents a request issued by PECI originator (TX) and 102 * a response received from PECI responder (RX). 103 */ 104 struct peci_request { 105 struct peci_device *device; 106 struct { 107 u8 buf[PECI_REQUEST_MAX_BUF_SIZE]; 108 u8 len; 109 } rx, tx; 110 }; 111 112 #endif /* __LINUX_PECI_H */ 113