Something went wrong. Try again.
(I'm so sorry!) Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345// SPDX-License-Identifier: GPL-2.0-only// Copyright (c) 2021 Intel Corporation
#include <linux/auxiliary_bus.h>#include <linux/module.h>#include <linux/peci.h>#include <linux/peci-cpu.h>#include <linux/slab.h>
#include "internal.h"
/** * peci_temp_read() - read the maximum die temperature from PECI target device * @device: PECI device to which request is going to be sent * @temp_raw: where to store the read temperature * * It uses GetTemp PECI command. * * Return: 0 if succeeded, other values in case errors. */int peci_temp_read(struct peci_device *device, s16 *temp_raw){ struct peci_request *req;
req = peci_xfer_get_temp(device); if (IS_ERR(req)) return PTR_ERR(req);
*temp_raw = peci_request_temp_read(req);
peci_request_free(req);
return 0;}EXPORT_SYMBOL_NS_GPL(peci_temp_read, "PECI_CPU");
/** * peci_pcs_read() - read PCS register * @device: PECI device to which request is going to be sent * @index: PCS index * @param: PCS parameter * @data: where to store the read data * * It uses RdPkgConfig PECI command. * * Return: 0 if succeeded, other values in case errors. */int peci_pcs_read(struct peci_device *device, u8 index, u16 param, u32 *data){ struct peci_request *req; int ret;
req = peci_xfer_pkg_cfg_readl(device, index, param); if (IS_ERR(req)) return PTR_ERR(req);
ret = peci_request_status(req); if (ret) goto out_req_free;
*data = peci_request_data_readl(req);out_req_free: peci_request_free(req);
return ret;}EXPORT_SYMBOL_NS_GPL(peci_pcs_read, "PECI_CPU");
/** * peci_pci_local_read() - read 32-bit memory location using raw address * @device: PECI device to which request is going to be sent * @bus: bus * @dev: device * @func: function * @reg: register * @data: where to store the read data * * It uses RdPCIConfigLocal PECI command. * * Return: 0 if succeeded, other values in case errors. */int peci_pci_local_read(struct peci_device *device, u8 bus, u8 dev, u8 func, u16 reg, u32 *data){ struct peci_request *req; int ret;
req = peci_xfer_pci_cfg_local_readl(device, bus, dev, func, reg); if (IS_ERR(req)) return PTR_ERR(req);
ret = peci_request_status(req); if (ret) goto out_req_free;
*data = peci_request_data_readl(req);out_req_free: peci_request_free(req);
return ret;}EXPORT_SYMBOL_NS_GPL(peci_pci_local_read, "PECI_CPU");
/** * peci_ep_pci_local_read() - read 32-bit memory location using raw address * @device: PECI device to which request is going to be sent * @seg: PCI segment * @bus: bus * @dev: device * @func: function * @reg: register * @data: where to store the read data * * Like &peci_pci_local_read, but it uses RdEndpointConfig PECI command. * * Return: 0 if succeeded, other values in case errors. */int peci_ep_pci_local_read(struct peci_device *device, u8 seg, u8 bus, u8 dev, u8 func, u16 reg, u32 *data){ struct peci_request *req; int ret;
req = peci_xfer_ep_pci_cfg_local_readl(device, seg, bus, dev, func, reg); if (IS_ERR(req)) return PTR_ERR(req);
ret = peci_request_status(req); if (ret) goto out_req_free;
*data = peci_request_data_readl(req);out_req_free: peci_request_free(req);
return ret;}EXPORT_SYMBOL_NS_GPL(peci_ep_pci_local_read, "PECI_CPU");
/** * peci_mmio_read() - read 32-bit memory location using 64-bit bar offset address * @device: PECI device to which request is going to be sent * @bar: PCI bar * @seg: PCI segment * @bus: bus * @dev: device * @func: function * @address: 64-bit MMIO address * @data: where to store the read data * * It uses RdEndpointConfig PECI command. * * Return: 0 if succeeded, other values in case errors. */int peci_mmio_read(struct peci_device *device, u8 bar, u8 seg, u8 bus, u8 dev, u8 func, u64 address, u32 *data){ struct peci_request *req; int ret;
req = peci_xfer_ep_mmio64_readl(device, bar, seg, bus, dev, func, address); if (IS_ERR(req)) return PTR_ERR(req);
ret = peci_request_status(req); if (ret) goto out_req_free;
*data = peci_request_data_readl(req);out_req_free: peci_request_free(req);
return ret;}EXPORT_SYMBOL_NS_GPL(peci_mmio_read, "PECI_CPU");
static const char * const peci_adev_types[] = { "cputemp", "dimmtemp",};
struct peci_cpu { struct peci_device *device; const struct peci_device_id *id;};
static void adev_release(struct device *dev){ struct auxiliary_device *adev = to_auxiliary_dev(dev);
kfree(adev->name); kfree(adev);}
static struct auxiliary_device *adev_alloc(struct peci_cpu *priv, int idx){ struct peci_controller *controller = to_peci_controller(priv->device->dev.parent); struct auxiliary_device *adev; const char *name; int ret;
adev = kzalloc_obj(*adev); if (!adev) return ERR_PTR(-ENOMEM);
name = kasprintf(GFP_KERNEL, "%s.%s", peci_adev_types[idx], (const char *)priv->id->data); if (!name) { ret = -ENOMEM; goto free_adev; }
adev->name = name; adev->dev.parent = &priv->device->dev; adev->dev.release = adev_release; adev->id = (controller->id << 16) | (priv->device->addr);
ret = auxiliary_device_init(adev); if (ret) goto free_name;
return adev;
free_name: kfree(name);free_adev: kfree(adev); return ERR_PTR(ret);}
static void unregister_adev(void *_adev){ struct auxiliary_device *adev = _adev;
auxiliary_device_delete(adev); auxiliary_device_uninit(adev);}
static int devm_adev_add(struct device *dev, int idx){ struct peci_cpu *priv = dev_get_drvdata(dev); struct auxiliary_device *adev; int ret;
adev = adev_alloc(priv, idx); if (IS_ERR(adev)) return PTR_ERR(adev);
ret = auxiliary_device_add(adev); if (ret) { auxiliary_device_uninit(adev); return ret; }
ret = devm_add_action_or_reset(&priv->device->dev, unregister_adev, adev); if (ret) return ret;
return 0;}
static void peci_cpu_add_adevices(struct peci_cpu *priv){ struct device *dev = &priv->device->dev; int ret, i;
for (i = 0; i < ARRAY_SIZE(peci_adev_types); i++) { ret = devm_adev_add(dev, i); if (ret) { dev_warn(dev, "Failed to register PECI auxiliary: %s, ret = %d\n", peci_adev_types[i], ret); continue; } }}
static intpeci_cpu_probe(struct peci_device *device, const struct peci_device_id *id){ struct device *dev = &device->dev; struct peci_cpu *priv;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM;
dev_set_drvdata(dev, priv); priv->device = device; priv->id = id;
peci_cpu_add_adevices(priv);
return 0;}
static const struct peci_device_id peci_cpu_device_ids[] = { { /* Haswell Xeon */ .x86_vfm = INTEL_HASWELL_X, .data = "hsx", }, { /* Broadwell Xeon */ .x86_vfm = INTEL_BROADWELL_X, .data = "bdx", }, { /* Broadwell Xeon D */ .x86_vfm = INTEL_BROADWELL_D, .data = "bdxd", }, { /* Skylake Xeon */ .x86_vfm = INTEL_SKYLAKE_X, .data = "skx", }, { /* Icelake Xeon */ .x86_vfm = INTEL_ICELAKE_X, .data = "icx", }, { /* Icelake Xeon D */ .x86_vfm = INTEL_ICELAKE_D, .data = "icxd", }, { /* Sapphire Rapids Xeon */ .x86_vfm = INTEL_SAPPHIRERAPIDS_X, .data = "spr", }, { /* Emerald Rapids Xeon */ .x86_vfm = INTEL_EMERALDRAPIDS_X, .data = "emr", }, { }};MODULE_DEVICE_TABLE(peci, peci_cpu_device_ids);
static struct peci_driver peci_cpu_driver = { .probe = peci_cpu_probe, .id_table = peci_cpu_device_ids, .driver = { .name = "peci-cpu", },};module_peci_driver(peci_cpu_driver);
MODULE_AUTHOR("Iwona Winiarska <iwona.winiarska@intel.com>");MODULE_DESCRIPTION("PECI CPU driver");MODULE_LICENSE("GPL");MODULE_IMPORT_NS("PECI");