Lines Matching +full:device +full:- +full:addr
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2018-2021 Intel Corporation
6 #include <linux/peci-cpu.h>
12 * PECI device can be removed using sysfs, but the removal can also happen as
14 * Mutex is used to protect PECI device from being double-deleted.
19 static int peci_get_revision(struct peci_device *device, u8 *revision) in peci_get_revision() argument
24 req = peci_xfer_get_dib(device); in peci_get_revision()
29 * PECI device may be in a state where it is unable to return a proper in peci_get_revision()
37 return -EIO; in peci_get_revision()
47 static int peci_get_cpu_id(struct peci_device *device, u32 *cpu_id) in peci_get_cpu_id() argument
52 req = peci_xfer_pkg_cfg_readl(device, PECI_PCS_PKG_ID, PECI_PKG_ID_CPU_ID); in peci_get_cpu_id()
93 static int peci_device_info_init(struct peci_device *device) in peci_device_info_init() argument
99 ret = peci_get_cpu_id(device, &cpu_id); in peci_device_info_init()
103 device->info.x86_vfm = IFM(peci_x86_cpu_family(cpu_id), peci_x86_cpu_model(cpu_id)); in peci_device_info_init()
105 ret = peci_get_revision(device, &revision); in peci_device_info_init()
108 device->info.peci_revision = revision; in peci_device_info_init()
110 device->info.socket_id = device->addr - PECI_BASE_ADDR; in peci_device_info_init()
115 static int peci_detect(struct peci_controller *controller, u8 addr) in peci_detect() argument
119 * We expect correct Write FCS if the device at the target address in peci_detect()
125 mutex_lock(&controller->bus_lock); in peci_detect()
126 ret = controller->ops->xfer(controller, addr, &req); in peci_detect()
127 mutex_unlock(&controller->bus_lock); in peci_detect()
132 static bool peci_addr_valid(u8 addr) in peci_addr_valid() argument
134 return addr >= PECI_BASE_ADDR && addr < PECI_BASE_ADDR + PECI_DEVICE_NUM_MAX; in peci_addr_valid()
137 static int peci_dev_exists(struct device *dev, void *data) in peci_dev_exists()
139 struct peci_device *device = to_peci_device(dev); in peci_dev_exists() local
140 u8 *addr = data; in peci_dev_exists() local
142 if (device->addr == *addr) in peci_dev_exists()
143 return -EBUSY; in peci_dev_exists()
148 int peci_device_create(struct peci_controller *controller, u8 addr) in peci_device_create() argument
150 struct peci_device *device; in peci_device_create() local
153 if (!peci_addr_valid(addr)) in peci_device_create()
154 return -EINVAL; in peci_device_create()
156 /* Check if we have already detected this device before. */ in peci_device_create()
157 ret = device_for_each_child(&controller->dev, &addr, peci_dev_exists); in peci_device_create()
161 ret = peci_detect(controller, addr); in peci_device_create()
164 * Device not present or host state doesn't allow successful in peci_device_create()
167 if (ret == -EIO || ret == -ETIMEDOUT) in peci_device_create()
173 device = kzalloc(sizeof(*device), GFP_KERNEL); in peci_device_create()
174 if (!device) in peci_device_create()
175 return -ENOMEM; in peci_device_create()
177 device_initialize(&device->dev); in peci_device_create()
179 device->addr = addr; in peci_device_create()
180 device->dev.parent = &controller->dev; in peci_device_create()
181 device->dev.bus = &peci_bus_type; in peci_device_create()
182 device->dev.type = &peci_device_type; in peci_device_create()
184 ret = peci_device_info_init(device); in peci_device_create()
188 ret = dev_set_name(&device->dev, "%d-%02x", controller->id, device->addr); in peci_device_create()
192 ret = device_add(&device->dev); in peci_device_create()
199 put_device(&device->dev); in peci_device_create()
204 void peci_device_destroy(struct peci_device *device) in peci_device_destroy() argument
207 if (!device->deleted) { in peci_device_destroy()
208 device_unregister(&device->dev); in peci_device_destroy()
209 device->deleted = true; in peci_device_destroy()
217 driver->driver.bus = &peci_bus_type; in __peci_driver_register()
218 driver->driver.owner = owner; in __peci_driver_register()
219 driver->driver.mod_name = mod_name; in __peci_driver_register()
221 if (!driver->probe) { in __peci_driver_register()
223 return -EINVAL; in __peci_driver_register()
226 if (!driver->id_table) { in __peci_driver_register()
227 pr_err("peci: trying to register driver without device id table\n"); in __peci_driver_register()
228 return -EINVAL; in __peci_driver_register()
231 return driver_register(&driver->driver); in __peci_driver_register()
237 driver_unregister(&driver->driver); in peci_driver_unregister()
241 static void peci_device_release(struct device *dev) in peci_device_release()
243 struct peci_device *device = to_peci_device(dev); in peci_device_release() local
245 kfree(device); in peci_device_release()