Lines Matching +full:protocol +full:- +full:node
1 // SPDX-License-Identifier: GPL-2.0
3 * System Control and Management Interface (SCMI) Message Protocol bus layer
5 * Copyright (C) 2018-2021 ARM Ltd.
31 struct list_head node; member
38 * scmi_protocol_device_request - Helper to request a device
40 * @id_table: A protocol/name pair descriptor for the device to be created.
45 * The requested device name MUST NOT be already existent for any protocol;
59 pr_debug("Requesting SCMI device (%s) for protocol %x\n", in scmi_protocol_device_request()
60 id_table->name, id_table->protocol_id); in scmi_protocol_device_request()
65 id_table->name, id_table->protocol_id); in scmi_protocol_device_request()
66 return -EINVAL; in scmi_protocol_device_request()
70 * Search for the matching protocol rdev list and then search in scmi_protocol_device_request()
78 node); in scmi_protocol_device_request()
79 if (rdev->id_table->protocol_id == in scmi_protocol_device_request()
80 id_table->protocol_id) in scmi_protocol_device_request()
83 list_for_each_entry(rdev, head, node) { in scmi_protocol_device_request()
84 if (!strcmp(rdev->id_table->name, id_table->name)) { in scmi_protocol_device_request()
86 rdev->id_table->protocol_id, in scmi_protocol_device_request()
87 rdev->id_table->name); in scmi_protocol_device_request()
88 ret = -EINVAL; in scmi_protocol_device_request()
100 ret = -ENOMEM; in scmi_protocol_device_request()
103 rdev->id_table = id_table; in scmi_protocol_device_request()
107 * related protocol list, eventually creating such head if not already in scmi_protocol_device_request()
114 ret = -ENOMEM; in scmi_protocol_device_request()
120 id_table->protocol_id, in scmi_protocol_device_request()
121 id_table->protocol_id + 1, GFP_KERNEL); in scmi_protocol_device_request()
122 if (ret != id_table->protocol_id) { in scmi_protocol_device_request()
123 pr_err("Failed to save SCMI device - ret:%d\n", ret); in scmi_protocol_device_request()
126 ret = -EINVAL; in scmi_protocol_device_request()
131 list_add(&rdev->node, phead); in scmi_protocol_device_request()
139 (void *)rdev->id_table); in scmi_protocol_device_request()
149 for (entry = id_table; entry->name && ret == 0; entry++) in scmi_protocol_table_register()
156 * scmi_protocol_device_unrequest - Helper to unrequest a device
158 * @id_table: A protocol/name pair descriptor for the device to be unrequested.
169 pr_debug("Unrequesting SCMI device (%s) for protocol %x\n", in scmi_protocol_device_unrequest()
170 id_table->name, id_table->protocol_id); in scmi_protocol_device_unrequest()
173 phead = idr_find(&scmi_requested_devices, id_table->protocol_id); in scmi_protocol_device_unrequest()
177 list_for_each_entry_safe(victim, tmp, phead, node) { in scmi_protocol_device_unrequest()
178 if (!strcmp(victim->id_table->name, id_table->name)) { in scmi_protocol_device_unrequest()
179 list_del(&victim->node); in scmi_protocol_device_unrequest()
184 (void *)victim->id_table); in scmi_protocol_device_unrequest()
193 id_table->protocol_id); in scmi_protocol_device_unrequest()
205 for (entry = id_table; entry->name; entry++) in scmi_protocol_table_unregister()
212 const struct scmi_device_id *id = scmi_drv->id_table; in scmi_dev_match_id()
217 for (; id->protocol_id; id++) in scmi_dev_match_id()
218 if (id->protocol_id == scmi_dev->protocol_id) { in scmi_dev_match_id()
219 if (!id->name) in scmi_dev_match_id()
221 else if (!strcmp(id->name, scmi_dev->name)) in scmi_dev_match_id()
246 return sdev->protocol_id == id_table->protocol_id && in scmi_match_by_id_table()
247 (id_table->name && !strcmp(sdev->name, id_table->name)); in scmi_match_by_id_table()
268 struct scmi_driver *scmi_drv = to_scmi_driver(dev->driver); in scmi_dev_probe()
271 if (!scmi_dev->handle) in scmi_dev_probe()
272 return -EPROBE_DEFER; in scmi_dev_probe()
274 return scmi_drv->probe(scmi_dev); in scmi_dev_probe()
279 struct scmi_driver *scmi_drv = to_scmi_driver(dev->driver); in scmi_dev_remove()
282 if (scmi_drv->remove) in scmi_dev_remove()
283 scmi_drv->remove(scmi_dev); in scmi_dev_remove()
299 if (!driver->probe) in scmi_driver_register()
300 return -EINVAL; in scmi_driver_register()
302 retval = scmi_protocol_table_register(driver->id_table); in scmi_driver_register()
306 driver->driver.bus = &scmi_bus_type; in scmi_driver_register()
307 driver->driver.name = driver->name; in scmi_driver_register()
308 driver->driver.owner = owner; in scmi_driver_register()
309 driver->driver.mod_name = mod_name; in scmi_driver_register()
311 retval = driver_register(&driver->driver); in scmi_driver_register()
313 pr_debug("Registered new scmi driver %s\n", driver->name); in scmi_driver_register()
321 driver_unregister(&driver->driver); in scmi_driver_unregister()
322 scmi_protocol_table_unregister(driver->id_table); in scmi_driver_unregister()
330 kfree_const(scmi_dev->name); in scmi_device_release()
336 pr_debug("(%s) Destroying SCMI device '%s' for protocol 0x%x (%s)\n", in __scmi_device_destroy()
337 of_node_full_name(scmi_dev->dev.parent->of_node), in __scmi_device_destroy()
338 dev_name(&scmi_dev->dev), scmi_dev->protocol_id, in __scmi_device_destroy()
339 scmi_dev->name); in __scmi_device_destroy()
341 if (scmi_dev->protocol_id == SCMI_PROTOCOL_SYSTEM) in __scmi_device_destroy()
344 ida_free(&scmi_bus_id, scmi_dev->id); in __scmi_device_destroy()
345 device_unregister(&scmi_dev->dev); in __scmi_device_destroy()
350 int protocol, const char *name) in __scmi_device_create() argument
356 * If the same protocol/name device already exist under the same parent in __scmi_device_create()
359 * each DT defined protocol at probe time, and the concurrent in __scmi_device_create()
362 scmi_dev = scmi_child_dev_find(parent, protocol, name); in __scmi_device_create()
373 if (protocol == SCMI_PROTOCOL_SYSTEM && in __scmi_device_create()
376 "SCMI SystemPower protocol device must be unique !\n"); in __scmi_device_create()
384 scmi_dev->name = kstrdup_const(name ?: "unknown", GFP_KERNEL); in __scmi_device_create()
385 if (!scmi_dev->name) { in __scmi_device_create()
392 kfree_const(scmi_dev->name); in __scmi_device_create()
397 scmi_dev->id = id; in __scmi_device_create()
398 scmi_dev->protocol_id = protocol; in __scmi_device_create()
399 scmi_dev->dev.parent = parent; in __scmi_device_create()
400 device_set_node(&scmi_dev->dev, of_fwnode_handle(np)); in __scmi_device_create()
401 scmi_dev->dev.bus = &scmi_bus_type; in __scmi_device_create()
402 scmi_dev->dev.release = scmi_device_release; in __scmi_device_create()
403 dev_set_name(&scmi_dev->dev, "scmi_dev.%d", id); in __scmi_device_create()
405 retval = device_register(&scmi_dev->dev); in __scmi_device_create()
409 pr_debug("(%s) Created SCMI device '%s' for protocol 0x%x (%s)\n", in __scmi_device_create()
410 of_node_full_name(parent->of_node), in __scmi_device_create()
411 dev_name(&scmi_dev->dev), protocol, name); in __scmi_device_create()
415 put_device(&scmi_dev->dev); in __scmi_device_create()
421 * scmi_device_create - A method to create one or more SCMI devices
423 * @np: A reference to the device node to use for the new device(s)
425 * @protocol: The SCMI protocol to be associated with this device
426 * @name: The requested-name of the device to be created; this is optional
428 * be requested on the SCMI bus for @protocol will be created.
430 * This method can be invoked to create a single well-defined device (like
434 * protocol (typically during SCMI core protocol enumeration at probe time).
440 * could have been potentially created for a whole protocol, unless no
441 * device was found to have been requested for that specific protocol.
444 struct device *parent, int protocol, in scmi_device_create() argument
452 return __scmi_device_create(np, parent, protocol, name); in scmi_device_create()
455 phead = idr_find(&scmi_requested_devices, protocol); in scmi_device_create()
462 /* Walk the list of requested devices for protocol and create them */ in scmi_device_create()
463 list_for_each_entry(rdev, phead, node) { in scmi_device_create()
467 rdev->id_table->protocol_id, in scmi_device_create()
468 rdev->id_table->name); in scmi_device_create()
473 pr_err("(%s) Failed to create device for protocol 0x%x (%s)\n", in scmi_device_create()
474 of_node_full_name(parent->of_node), in scmi_device_create()
475 rdev->id_table->protocol_id, in scmi_device_create()
476 rdev->id_table->name); in scmi_device_create()
484 void scmi_device_destroy(struct device *parent, int protocol, const char *name) in scmi_device_destroy() argument
488 scmi_dev = scmi_child_dev_find(parent, protocol, name); in scmi_device_destroy()
513 pr_err("SCMI protocol bus register failed (%d)\n", retval); in scmi_bus_init()
515 pr_info("SCMI protocol bus registered\n"); in scmi_bus_init()
533 MODULE_ALIAS("scmi-core");
535 MODULE_DESCRIPTION("ARM SCMI protocol bus");