cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

internal.h (5168B)


      1/* SPDX-License-Identifier: GPL-2.0-only */
      2/* Copyright (c) 2018-2021 Intel Corporation */
      3
      4#ifndef __PECI_INTERNAL_H
      5#define __PECI_INTERNAL_H
      6
      7#include <linux/device.h>
      8#include <linux/types.h>
      9
     10struct peci_controller;
     11struct attribute_group;
     12struct peci_device;
     13struct peci_request;
     14
     15/* PECI CPU address range 0x30-0x37 */
     16#define PECI_BASE_ADDR		0x30
     17#define PECI_DEVICE_NUM_MAX	8
     18
     19struct peci_request *peci_request_alloc(struct peci_device *device, u8 tx_len, u8 rx_len);
     20void peci_request_free(struct peci_request *req);
     21
     22int peci_request_status(struct peci_request *req);
     23
     24u64 peci_request_dib_read(struct peci_request *req);
     25s16 peci_request_temp_read(struct peci_request *req);
     26
     27u8 peci_request_data_readb(struct peci_request *req);
     28u16 peci_request_data_readw(struct peci_request *req);
     29u32 peci_request_data_readl(struct peci_request *req);
     30u64 peci_request_data_readq(struct peci_request *req);
     31
     32struct peci_request *peci_xfer_get_dib(struct peci_device *device);
     33struct peci_request *peci_xfer_get_temp(struct peci_device *device);
     34
     35struct peci_request *peci_xfer_pkg_cfg_readb(struct peci_device *device, u8 index, u16 param);
     36struct peci_request *peci_xfer_pkg_cfg_readw(struct peci_device *device, u8 index, u16 param);
     37struct peci_request *peci_xfer_pkg_cfg_readl(struct peci_device *device, u8 index, u16 param);
     38struct peci_request *peci_xfer_pkg_cfg_readq(struct peci_device *device, u8 index, u16 param);
     39
     40struct peci_request *peci_xfer_pci_cfg_local_readb(struct peci_device *device,
     41						   u8 bus, u8 dev, u8 func, u16 reg);
     42struct peci_request *peci_xfer_pci_cfg_local_readw(struct peci_device *device,
     43						   u8 bus, u8 dev, u8 func, u16 reg);
     44struct peci_request *peci_xfer_pci_cfg_local_readl(struct peci_device *device,
     45						   u8 bus, u8 dev, u8 func, u16 reg);
     46
     47struct peci_request *peci_xfer_ep_pci_cfg_local_readb(struct peci_device *device, u8 seg,
     48						      u8 bus, u8 dev, u8 func, u16 reg);
     49struct peci_request *peci_xfer_ep_pci_cfg_local_readw(struct peci_device *device, u8 seg,
     50						      u8 bus, u8 dev, u8 func, u16 reg);
     51struct peci_request *peci_xfer_ep_pci_cfg_local_readl(struct peci_device *device, u8 seg,
     52						      u8 bus, u8 dev, u8 func, u16 reg);
     53
     54struct peci_request *peci_xfer_ep_pci_cfg_readb(struct peci_device *device, u8 seg,
     55						u8 bus, u8 dev, u8 func, u16 reg);
     56struct peci_request *peci_xfer_ep_pci_cfg_readw(struct peci_device *device, u8 seg,
     57						u8 bus, u8 dev, u8 func, u16 reg);
     58struct peci_request *peci_xfer_ep_pci_cfg_readl(struct peci_device *device, u8 seg,
     59						u8 bus, u8 dev, u8 func, u16 reg);
     60
     61struct peci_request *peci_xfer_ep_mmio32_readl(struct peci_device *device, u8 bar, u8 seg,
     62					       u8 bus, u8 dev, u8 func, u64 offset);
     63
     64struct peci_request *peci_xfer_ep_mmio64_readl(struct peci_device *device, u8 bar, u8 seg,
     65					       u8 bus, u8 dev, u8 func, u64 offset);
     66/**
     67 * struct peci_device_id - PECI device data to match
     68 * @data: pointer to driver private data specific to device
     69 * @family: device family
     70 * @model: device model
     71 */
     72struct peci_device_id {
     73	const void *data;
     74	u16 family;
     75	u8 model;
     76};
     77
     78extern struct device_type peci_device_type;
     79extern const struct attribute_group *peci_device_groups[];
     80
     81int peci_device_create(struct peci_controller *controller, u8 addr);
     82void peci_device_destroy(struct peci_device *device);
     83
     84extern struct bus_type peci_bus_type;
     85extern const struct attribute_group *peci_bus_groups[];
     86
     87/**
     88 * struct peci_driver - PECI driver
     89 * @driver: inherit device driver
     90 * @probe: probe callback
     91 * @remove: remove callback
     92 * @id_table: PECI device match table to decide which device to bind
     93 */
     94struct peci_driver {
     95	struct device_driver driver;
     96	int (*probe)(struct peci_device *device, const struct peci_device_id *id);
     97	void (*remove)(struct peci_device *device);
     98	const struct peci_device_id *id_table;
     99};
    100
    101static inline struct peci_driver *to_peci_driver(struct device_driver *d)
    102{
    103	return container_of(d, struct peci_driver, driver);
    104}
    105
    106int __peci_driver_register(struct peci_driver *driver, struct module *owner,
    107			   const char *mod_name);
    108/**
    109 * peci_driver_register() - register PECI driver
    110 * @driver: the driver to be registered
    111 *
    112 * PECI drivers that don't need to do anything special in module init should
    113 * use the convenience "module_peci_driver" macro instead
    114 *
    115 * Return: zero on success, else a negative error code.
    116 */
    117#define peci_driver_register(driver) \
    118	__peci_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
    119void peci_driver_unregister(struct peci_driver *driver);
    120
    121/**
    122 * module_peci_driver() - helper macro for registering a modular PECI driver
    123 * @__peci_driver: peci_driver struct
    124 *
    125 * Helper macro for PECI drivers which do not do anything special in module
    126 * init/exit. This eliminates a lot of boilerplate. Each module may only
    127 * use this macro once, and calling it replaces module_init() and module_exit()
    128 */
    129#define module_peci_driver(__peci_driver) \
    130	module_driver(__peci_driver, peci_driver_register, peci_driver_unregister)
    131
    132extern struct device_type peci_controller_type;
    133
    134int peci_controller_scan_devices(struct peci_controller *controller);
    135
    136#endif /* __PECI_INTERNAL_H */