# PECI

---

# PECI Subsystem

_Peios Kernel / Hardware and drivers / PECI_

> Reference for PECI Subsystem.

<a id="rst-peci-subsystem"></a>

<!-- SPDX-License-Identifier: GPL-2.0-only -->

- [Overview](</kernel/hardware/peci/peci.md>)

---

# Overview

_Peios Kernel / Hardware and drivers / PECI_

> The Platform Environment Control Interface (PECI) is a communication interface between Intel processor and management controllers (e.g. Baseboard Management Controller, BMC). PECI provides services that allow the management controller to…

<a id="rst-overview"></a>

<!-- SPDX-License-Identifier: GPL-2.0-only -->

The Platform Environment Control Interface (PECI) is a communication interface between Intel processor and management controllers (e.g. Baseboard Management Controller, BMC). PECI provides services that allow the management controller to configure, monitor and debug platform by accessing various registers. It defines a dedicated command protocol, where the management controller is acting as a PECI originator and the processor - as a PECI responder. PECI can be used in both single processor and multiple-processor based systems.

NOTE: Intel PECI specification is not released as a dedicated document, instead it is a part of External Design Specification (EDS) for given Intel CPU. External Design Specifications are usually not publicly available.

<a id="rst-peci-wire"></a>

## PECI Wire

PECI Wire interface uses a single wire for self-clocking and data transfer. It does not require any additional control lines - the physical layer is a self-clocked one-wire bus signal that begins each bit with a driven, rising edge from an idle near zero volts. The duration of the signal driven high allows to determine whether the bit value is logic '0' or logic '1'. PECI Wire also includes variable data rate established with every message.

For PECI Wire, each processor package will utilize unique, fixed addresses within a defined range and that address should have a fixed relationship with the processor socket ID - if one of the processors is removed, it does not affect addresses of remaining processors.

<a id="rst-peci-subsystem-internals"></a>

## PECI subsystem internals


#### <a id="c-struct-peci_controller_ops"></a>`struct peci_controller_ops`

PECI controller specific methods

**Definition**

```c
struct peci_controller_ops {
    int (*xfer)(struct peci_controller *controller, u8 addr, struct peci_request *req);
};
```

**Members**

- `xfer`: PECI transfer function

**Description**

PECI controllers may have different hardware interfaces - the drivers
implementing PECI controllers can use this structure to abstract away those
differences by exposing a common interface for PECI core.

#### <a id="c-struct-peci_controller"></a>`struct peci_controller`

PECI controller

**Definition**

```c
struct peci_controller {
    struct device dev;
    const struct peci_controller_ops *ops;
    struct mutex bus_lock;
    u8 id;
};
```

**Members**

- `dev`: device object to register PECI controller to the device model
- `ops`: pointer to device specific controller operations
- `bus_lock`: lock used to protect multiple callers
- `id`: PECI controller ID

**Description**

PECI controllers usually connect to their drivers using non-PECI bus,
such as the platform bus.
Each PECI controller can communicate with one or more PECI devices.

#### <a id="c-struct-peci_device"></a>`struct peci_device`

PECI device

**Definition**

```c
struct peci_device {
    struct device dev;
    struct {
        u32 x86_vfm;
        u8 peci_revision;
        u8 socket_id;
    } info;
    u8 addr;
    bool deleted;
};
```

**Members**

- `dev`: device object to register PECI device to the device model
- `info`: PECI device characteristics
- `info.x86_vfm`: device vendor-family-model
- `info.peci_revision`: PECI revision supported by the PECI device
- `info.socket_id`: the socket ID represented by the PECI device
- `addr`: address used on the PECI bus connected to the parent controller
- `deleted`: indicates that PECI device was already deleted

**Description**

A peci_device identifies a single device (i.e. CPU) connected to a PECI bus.
The behaviour exposed to the rest of the system is defined by the PECI driver
managing the device.

#### <a id="c-struct-peci_request"></a>`struct peci_request`

PECI request

**Definition**

```c
struct peci_request {
    struct peci_device *device;
    struct {
        u8 buf[PECI_REQUEST_MAX_BUF_SIZE];
        u8 len;
    } rx, tx;
};
```

**Members**

- `device`: PECI device to which the request is sent
- `rx`: RX buffer specific data
- `rx.buf`: RX buffer
- `rx.len`: received data length in bytes
- `tx`: TX buffer specific data
- `tx.buf`: TX buffer
- `tx.len`: transfer data length in bytes

**Description**

A peci_request represents a request issued by PECI originator (TX) and
a response received from PECI responder (RX).



#### <a id="c-struct-peci_device_id"></a>`struct peci_device_id`

PECI device data to match

**Definition**

```c
struct peci_device_id {
    const void *data;
    u32 x86_vfm;
};
```

**Members**

- `data`: pointer to driver private data specific to device
- `x86_vfm`: device vendor-family-model

#### <a id="c-struct-peci_driver"></a>`struct peci_driver`

PECI driver

**Definition**

```c
struct peci_driver {
    struct device_driver driver;
    int (*probe)(struct peci_device *device, const struct peci_device_id *id);
    void (*remove)(struct peci_device *device);
    const struct peci_device_id *id_table;
};
```

**Members**

- `driver`: inherit device driver
- `probe`: probe callback
- `remove`: remove callback
- `id_table`: PECI device match table to decide which device to bind

#### <a id="c-peci_driver_register"></a>`peci_driver_register()`

```c
peci_driver_register(driver)
```

register PECI driver

**Parameters**

- `driver`: the driver to be registered

**Description**

PECI drivers that don't need to do anything special in module init should
use the convenience "module_peci_driver" macro instead

**Return**

zero on success, else a negative error code.

#### <a id="c-module_peci_driver"></a>`module_peci_driver()`

```c
module_peci_driver(__peci_driver)
```

helper macro for registering a modular PECI driver

**Parameters**

- `__peci_driver`: peci_driver struct

**Description**

Helper macro for PECI drivers which do not do anything special in module
init/exit. This eliminates a lot of boilerplate. Each module may only
use this macro once, and calling it replaces [`module_init()`](/kernel/hardware/driver-api/fundamentals/basics.md#c-module_init) and [`module_exit()`](/kernel/hardware/driver-api/fundamentals/basics.md#c-module_exit)



#### <a id="c-devm_peci_controller_add"></a>`devm_peci_controller_add()`

```c
struct peci_controller * devm_peci_controller_add(struct device *dev, const struct peci_controller_ops *ops)
```

add PECI controller

**Parameters**

- `struct device *dev`: device for devm operations
- `const struct peci_controller_ops *ops`: pointer to controller specific methods

**Description**

In final stage of its `probe()`, peci_controller driver calls
[`devm_peci_controller_add()`](#c-devm_peci_controller_add) to register itself with the PECI bus.

**Return**

Pointer to the newly allocated controller or [`ERR_PTR()`](/kernel/internals/core-api/kernel-api.md#c-ERR_PTR) in case of failure.



#### <a id="c-peci_request_status"></a>`peci_request_status()`

```c
int peci_request_status(struct peci_request *req)
```

return -errno based on PECI completion code

**Parameters**

- `struct peci_request *req`: the PECI request that contains response data with completion code

**Description**

It can't be used for `Ping()`, `GetDIB()` and `GetTemp()` - for those commands we
don't expect completion code in the response.

**Return**

-errno

#### <a id="c-peci_request_alloc"></a>`peci_request_alloc()`

```c
struct peci_request * peci_request_alloc(struct peci_device *device, u8 tx_len, u8 rx_len)
```

allocate `struct peci_requests`

**Parameters**

- `struct peci_device *device`: PECI device to which request is going to be sent
- `u8 tx_len`: TX length
- `u8 rx_len`: RX length

**Return**

A pointer to a newly allocated [`struct peci_request`](#c-struct-peci_request) on success or NULL otherwise.

#### <a id="c-peci_request_free"></a>`peci_request_free()`

```c
void peci_request_free(struct peci_request *req)
```

free peci_request

**Parameters**

- `struct peci_request *req`: the PECI request to be freed


<a id="rst-peci-cpu-driver-api"></a>

## PECI CPU Driver API


#### <a id="c-peci_temp_read"></a>`peci_temp_read()`

```c
int peci_temp_read(struct peci_device *device, s16 *temp_raw)
```

read the maximum die temperature from PECI target device

**Parameters**

- `struct peci_device *device`: PECI device to which request is going to be sent
- `s16 *temp_raw`: where to store the read temperature

**Description**

It uses GetTemp PECI command.

**Return**

0 if succeeded, other values in case errors.

#### <a id="c-peci_pcs_read"></a>`peci_pcs_read()`

```c
int peci_pcs_read(struct peci_device *device, u8 index, u16 param, u32 *data)
```

read PCS register

**Parameters**

- `struct peci_device *device`: PECI device to which request is going to be sent
- `u8 index`: PCS index
- `u16 param`: PCS parameter
- `u32 *data`: where to store the read data

**Description**

It uses RdPkgConfig PECI command.

**Return**

0 if succeeded, other values in case errors.

#### <a id="c-peci_pci_local_read"></a>`peci_pci_local_read()`

```c
int peci_pci_local_read(struct peci_device *device, u8 bus, u8 dev, u8 func, u16 reg, u32 *data)
```

read 32-bit memory location using raw address

**Parameters**

- `struct peci_device *device`: PECI device to which request is going to be sent
- `u8 bus`: bus
- `u8 dev`: device
- `u8 func`: function
- `u16 reg`: register
- `u32 *data`: where to store the read data

**Description**

It uses RdPCIConfigLocal PECI command.

**Return**

0 if succeeded, other values in case errors.

#### <a id="c-peci_ep_pci_local_read"></a>`peci_ep_pci_local_read()`

```c
int peci_ep_pci_local_read(struct peci_device *device, u8 seg, u8 bus, u8 dev, u8 func, u16 reg, u32 *data)
```

read 32-bit memory location using raw address

**Parameters**

- `struct peci_device *device`: PECI device to which request is going to be sent
- `u8 seg`: PCI segment
- `u8 bus`: bus
- `u8 dev`: device
- `u8 func`: function
- `u16 reg`: register
- `u32 *data`: where to store the read data

**Description**

Like [`peci_pci_local_read`](#c-peci_pci_local_read), but it uses RdEndpointConfig PECI command.

**Return**

0 if succeeded, other values in case errors.

#### <a id="c-peci_mmio_read"></a>`peci_mmio_read()`

```c
int peci_mmio_read(struct peci_device *device, u8 bar, u8 seg, u8 bus, u8 dev, u8 func, u64 address, u32 *data)
```

read 32-bit memory location using 64-bit bar offset address

**Parameters**

- `struct peci_device *device`: PECI device to which request is going to be sent
- `u8 bar`: PCI bar
- `u8 seg`: PCI segment
- `u8 bus`: bus
- `u8 dev`: device
- `u8 func`: function
- `u64 address`: 64-bit MMIO address
- `u32 *data`: where to store the read data

**Description**

It uses RdEndpointConfig PECI command.

**Return**

0 if succeeded, other values in case errors.
