peci.h 3.2 KB

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