Lines Matching +full:host1x +full:- +full:class

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2012-2013, NVIDIA Corporation
8 #include <linux/dma-mapping.h>
9 #include <linux/host1x.h>
34 * host1x_subdev_add() - add a new subdevice with an associated device node
35 * @device: host1x device to add the subdevice to
36 * @driver: host1x driver containing the subdevices
49 return -ENOMEM; in host1x_subdev_add()
51 INIT_LIST_HEAD(&subdev->list); in host1x_subdev_add()
52 subdev->np = of_node_get(np); in host1x_subdev_add()
54 mutex_lock(&device->subdevs_lock); in host1x_subdev_add()
55 list_add_tail(&subdev->list, &device->subdevs); in host1x_subdev_add()
56 mutex_unlock(&device->subdevs_lock); in host1x_subdev_add()
60 if (of_match_node(driver->subdevs, child) && in host1x_subdev_add()
75 * host1x_subdev_del() - remove subdevice
80 list_del(&subdev->list); in host1x_subdev_del()
81 of_node_put(subdev->np); in host1x_subdev_del()
86 * host1x_device_parse_dt() - scan device tree and add matching subdevices
87 * @device: host1x logical device
88 * @driver: host1x driver
96 for_each_child_of_node(device->dev.parent->of_node, np) { in host1x_device_parse_dt()
97 if (of_match_node(driver->subdevs, np) && in host1x_device_parse_dt()
121 mutex_lock(&device->subdevs_lock); in host1x_subdev_register()
122 mutex_lock(&device->clients_lock); in host1x_subdev_register()
123 list_move_tail(&client->list, &device->clients); in host1x_subdev_register()
124 list_move_tail(&subdev->list, &device->active); in host1x_subdev_register()
125 client->host = &device->dev; in host1x_subdev_register()
126 subdev->client = client; in host1x_subdev_register()
127 mutex_unlock(&device->clients_lock); in host1x_subdev_register()
128 mutex_unlock(&device->subdevs_lock); in host1x_subdev_register()
130 if (list_empty(&device->subdevs)) { in host1x_subdev_register()
131 err = device_add(&device->dev); in host1x_subdev_register()
133 dev_err(&device->dev, "failed to add: %d\n", err); in host1x_subdev_register()
135 device->registered = true; in host1x_subdev_register()
142 struct host1x_client *client = subdev->client; in __host1x_subdev_unregister()
148 if (list_empty(&device->subdevs)) { in __host1x_subdev_unregister()
149 if (device->registered) { in __host1x_subdev_unregister()
150 device->registered = false; in __host1x_subdev_unregister()
151 device_del(&device->dev); in __host1x_subdev_unregister()
159 mutex_lock(&device->clients_lock); in __host1x_subdev_unregister()
160 subdev->client = NULL; in __host1x_subdev_unregister()
161 client->host = NULL; in __host1x_subdev_unregister()
162 list_move_tail(&subdev->list, &device->subdevs); in __host1x_subdev_unregister()
171 list_del_init(&client->list); in __host1x_subdev_unregister()
172 mutex_unlock(&device->clients_lock); in __host1x_subdev_unregister()
178 mutex_lock(&device->subdevs_lock); in host1x_subdev_unregister()
180 mutex_unlock(&device->subdevs_lock); in host1x_subdev_unregister()
184 * host1x_device_init() - initialize a host1x logical device
185 * @device: host1x logical device
187 * The driver for the host1x logical device can call this during execution of
198 mutex_lock(&device->clients_lock); in host1x_device_init()
200 list_for_each_entry(client, &device->clients, list) { in host1x_device_init()
201 if (client->ops && client->ops->early_init) { in host1x_device_init()
202 err = client->ops->early_init(client); in host1x_device_init()
204 dev_err(&device->dev, "failed to early initialize %s: %d\n", in host1x_device_init()
205 dev_name(client->dev), err); in host1x_device_init()
211 list_for_each_entry(client, &device->clients, list) { in host1x_device_init()
212 if (client->ops && client->ops->init) { in host1x_device_init()
213 err = client->ops->init(client); in host1x_device_init()
215 dev_err(&device->dev, in host1x_device_init()
217 dev_name(client->dev), err); in host1x_device_init()
223 mutex_unlock(&device->clients_lock); in host1x_device_init()
228 list_for_each_entry_continue_reverse(client, &device->clients, list) in host1x_device_init()
229 if (client->ops->exit) in host1x_device_init()
230 client->ops->exit(client); in host1x_device_init()
233 client = list_entry(&device->clients, struct host1x_client, list); in host1x_device_init()
236 list_for_each_entry_continue_reverse(client, &device->clients, list) in host1x_device_init()
237 if (client->ops->late_exit) in host1x_device_init()
238 client->ops->late_exit(client); in host1x_device_init()
240 mutex_unlock(&device->clients_lock); in host1x_device_init()
246 * host1x_device_exit() - uninitialize host1x logical device
247 * @device: host1x logical device
249 * When the driver for a host1x logical device is unloaded, it can call this
251 * subsystem-specific data structure is removed and the functionality can no
259 mutex_lock(&device->clients_lock); in host1x_device_exit()
261 list_for_each_entry_reverse(client, &device->clients, list) { in host1x_device_exit()
262 if (client->ops && client->ops->exit) { in host1x_device_exit()
263 err = client->ops->exit(client); in host1x_device_exit()
265 dev_err(&device->dev, in host1x_device_exit()
267 dev_name(client->dev), err); in host1x_device_exit()
268 mutex_unlock(&device->clients_lock); in host1x_device_exit()
274 list_for_each_entry_reverse(client, &device->clients, list) { in host1x_device_exit()
275 if (client->ops && client->ops->late_exit) { in host1x_device_exit()
276 err = client->ops->late_exit(client); in host1x_device_exit()
278 dev_err(&device->dev, "failed to late cleanup %s: %d\n", in host1x_device_exit()
279 dev_name(client->dev), err); in host1x_device_exit()
280 mutex_unlock(&device->clients_lock); in host1x_device_exit()
286 mutex_unlock(&device->clients_lock); in host1x_device_exit()
292 static int host1x_add_client(struct host1x *host1x, in host1x_add_client() argument
298 mutex_lock(&host1x->devices_lock); in host1x_add_client()
300 list_for_each_entry(device, &host1x->devices, list) { in host1x_add_client()
301 list_for_each_entry(subdev, &device->subdevs, list) { in host1x_add_client()
302 if (subdev->np == client->dev->of_node) { in host1x_add_client()
304 mutex_unlock(&host1x->devices_lock); in host1x_add_client()
310 mutex_unlock(&host1x->devices_lock); in host1x_add_client()
311 return -ENODEV; in host1x_add_client()
314 static int host1x_del_client(struct host1x *host1x, in host1x_del_client() argument
320 mutex_lock(&host1x->devices_lock); in host1x_del_client()
322 list_for_each_entry_safe(device, dt, &host1x->devices, list) { in host1x_del_client()
323 list_for_each_entry(subdev, &device->active, list) { in host1x_del_client()
324 if (subdev->client == client) { in host1x_del_client()
326 mutex_unlock(&host1x->devices_lock); in host1x_del_client()
332 mutex_unlock(&host1x->devices_lock); in host1x_del_client()
333 return -ENODEV; in host1x_del_client()
338 return strcmp(dev_name(dev), drv->name) == 0; in host1x_device_match()
344 struct device_node *np = dev->parent->of_node; in host1x_device_uevent()
351 * be called from modules and operates on dev->of_node, which is not in host1x_device_uevent()
373 return of_dma_configure(dev, dev->of_node, true); in host1x_dma_configure()
386 .name = "host1x",
398 mutex_lock(&device->subdevs_lock); in __host1x_device_del()
401 list_for_each_entry_safe(subdev, sd, &device->active, list) { in __host1x_device_del()
411 client = subdev->client; in __host1x_device_del()
417 list_add_tail(&client->list, &clients); in __host1x_device_del()
422 list_for_each_entry_safe(subdev, sd, &device->subdevs, list) in __host1x_device_del()
425 mutex_unlock(&device->subdevs_lock); in __host1x_device_del()
429 mutex_lock(&device->clients_lock); in __host1x_device_del()
431 list_for_each_entry_safe(client, cl, &device->clients, list) in __host1x_device_del()
432 list_move_tail(&client->list, &clients); in __host1x_device_del()
434 mutex_unlock(&device->clients_lock); in __host1x_device_del()
438 list_del_init(&device->list); in __host1x_device_del()
449 static int host1x_device_add(struct host1x *host1x, in host1x_device_add() argument
459 return -ENOMEM; in host1x_device_add()
461 device_initialize(&device->dev); in host1x_device_add()
463 mutex_init(&device->subdevs_lock); in host1x_device_add()
464 INIT_LIST_HEAD(&device->subdevs); in host1x_device_add()
465 INIT_LIST_HEAD(&device->active); in host1x_device_add()
466 mutex_init(&device->clients_lock); in host1x_device_add()
467 INIT_LIST_HEAD(&device->clients); in host1x_device_add()
468 INIT_LIST_HEAD(&device->list); in host1x_device_add()
469 device->driver = driver; in host1x_device_add()
471 device->dev.coherent_dma_mask = host1x->dev->coherent_dma_mask; in host1x_device_add()
472 device->dev.dma_mask = &device->dev.coherent_dma_mask; in host1x_device_add()
473 dev_set_name(&device->dev, "%s", driver->driver.name); in host1x_device_add()
474 device->dev.release = host1x_device_release; in host1x_device_add()
475 device->dev.bus = &host1x_bus_type; in host1x_device_add()
476 device->dev.parent = host1x->dev; in host1x_device_add()
478 of_dma_configure(&device->dev, host1x->dev->of_node, true); in host1x_device_add()
480 device->dev.dma_parms = &device->dma_parms; in host1x_device_add()
481 dma_set_max_seg_size(&device->dev, UINT_MAX); in host1x_device_add()
489 list_add_tail(&device->list, &host1x->devices); in host1x_device_add()
494 list_for_each_entry(subdev, &device->subdevs, list) { in host1x_device_add()
495 if (subdev->np == client->dev->of_node) { in host1x_device_add()
511 * This function must be called with the host1x->devices_lock held.
513 static void host1x_device_del(struct host1x *host1x, in host1x_device_del() argument
516 if (device->registered) { in host1x_device_del()
517 device->registered = false; in host1x_device_del()
518 device_del(&device->dev); in host1x_device_del()
521 put_device(&device->dev); in host1x_device_del()
524 static void host1x_attach_driver(struct host1x *host1x, in host1x_attach_driver() argument
530 mutex_lock(&host1x->devices_lock); in host1x_attach_driver()
532 list_for_each_entry(device, &host1x->devices, list) { in host1x_attach_driver()
533 if (device->driver == driver) { in host1x_attach_driver()
534 mutex_unlock(&host1x->devices_lock); in host1x_attach_driver()
539 err = host1x_device_add(host1x, driver); in host1x_attach_driver()
541 dev_err(host1x->dev, "failed to allocate device: %d\n", err); in host1x_attach_driver()
543 mutex_unlock(&host1x->devices_lock); in host1x_attach_driver()
546 static void host1x_detach_driver(struct host1x *host1x, in host1x_detach_driver() argument
551 mutex_lock(&host1x->devices_lock); in host1x_detach_driver()
553 list_for_each_entry_safe(device, tmp, &host1x->devices, list) in host1x_detach_driver()
554 if (device->driver == driver) in host1x_detach_driver()
555 host1x_device_del(host1x, device); in host1x_detach_driver()
557 mutex_unlock(&host1x->devices_lock); in host1x_detach_driver()
562 struct host1x *host1x = s->private; in host1x_devices_show() local
565 mutex_lock(&host1x->devices_lock); in host1x_devices_show()
567 list_for_each_entry(device, &host1x->devices, list) { in host1x_devices_show()
570 seq_printf(s, "%s\n", dev_name(&device->dev)); in host1x_devices_show()
572 mutex_lock(&device->subdevs_lock); in host1x_devices_show()
574 list_for_each_entry(subdev, &device->active, list) in host1x_devices_show()
575 seq_printf(s, " %pOFf: %s\n", subdev->np, in host1x_devices_show()
576 dev_name(subdev->client->dev)); in host1x_devices_show()
578 list_for_each_entry(subdev, &device->subdevs, list) in host1x_devices_show()
579 seq_printf(s, " %pOFf:\n", subdev->np); in host1x_devices_show()
581 mutex_unlock(&device->subdevs_lock); in host1x_devices_show()
584 mutex_unlock(&host1x->devices_lock); in host1x_devices_show()
591 * host1x_register() - register a host1x controller
592 * @host1x: host1x controller
594 * The host1x controller driver uses this to register a host1x controller with
596 * with a single host1x instance, so this function is somewhat academic.
598 int host1x_register(struct host1x *host1x) in host1x_register() argument
603 list_add_tail(&host1x->list, &devices); in host1x_register()
609 host1x_attach_driver(host1x, driver); in host1x_register()
613 debugfs_create_file("devices", S_IRUGO, host1x->debugfs, host1x, in host1x_register()
620 * host1x_unregister() - unregister a host1x controller
621 * @host1x: host1x controller
623 * The host1x controller driver uses this to remove a host1x controller from
626 int host1x_unregister(struct host1x *host1x) in host1x_unregister() argument
633 host1x_detach_driver(host1x, driver); in host1x_unregister()
638 list_del_init(&host1x->list); in host1x_unregister()
646 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_probe()
649 if (driver->probe) in host1x_device_probe()
650 return driver->probe(device); in host1x_device_probe()
657 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_remove()
660 if (driver->remove) in host1x_device_remove()
661 return driver->remove(device); in host1x_device_remove()
668 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_shutdown()
671 if (driver->shutdown) in host1x_device_shutdown()
672 driver->shutdown(device); in host1x_device_shutdown()
676 * host1x_driver_register_full() - register a host1x driver
677 * @driver: host1x driver
680 * Drivers for host1x logical devices call this function to register a driver
683 * A logical device will be created for each host1x instance.
688 struct host1x *host1x; in host1x_driver_register_full() local
690 INIT_LIST_HEAD(&driver->list); in host1x_driver_register_full()
693 list_add_tail(&driver->list, &drivers); in host1x_driver_register_full()
698 list_for_each_entry(host1x, &devices, list) in host1x_driver_register_full()
699 host1x_attach_driver(host1x, driver); in host1x_driver_register_full()
703 driver->driver.bus = &host1x_bus_type; in host1x_driver_register_full()
704 driver->driver.owner = owner; in host1x_driver_register_full()
705 driver->driver.probe = host1x_device_probe; in host1x_driver_register_full()
706 driver->driver.remove = host1x_device_remove; in host1x_driver_register_full()
707 driver->driver.shutdown = host1x_device_shutdown; in host1x_driver_register_full()
709 return driver_register(&driver->driver); in host1x_driver_register_full()
714 * host1x_driver_unregister() - unregister a host1x driver
715 * @driver: host1x driver
717 * Unbinds the driver from each of the host1x logical devices that it is
722 struct host1x *host1x; in host1x_driver_unregister() local
724 driver_unregister(&driver->driver); in host1x_driver_unregister()
728 list_for_each_entry(host1x, &devices, list) in host1x_driver_unregister()
729 host1x_detach_driver(host1x, driver); in host1x_driver_unregister()
734 list_del_init(&driver->list); in host1x_driver_unregister()
740 * __host1x_client_init() - initialize a host1x client
741 * @client: host1x client
742 * @key: lock class key for the client-specific mutex
746 host1x_bo_cache_init(&client->cache); in __host1x_client_init()
747 INIT_LIST_HEAD(&client->list); in __host1x_client_init()
748 __mutex_init(&client->lock, "host1x client lock", key); in __host1x_client_init()
749 client->usecount = 0; in __host1x_client_init()
754 * host1x_client_exit() - uninitialize a host1x client
755 * @client: host1x client
759 mutex_destroy(&client->lock); in host1x_client_exit()
764 * __host1x_client_register() - register a host1x client
765 * @client: host1x client
767 * Registers a host1x client with each host1x controller instance. Note that
768 * each client will only match their parent host1x controller and will only be
770 * their parent host1x controller, the infrastructure will set up the logical
776 struct host1x *host1x; in __host1x_client_register() local
781 list_for_each_entry(host1x, &devices, list) { in __host1x_client_register()
782 err = host1x_add_client(host1x, client); in __host1x_client_register()
792 list_add_tail(&client->list, &clients); in __host1x_client_register()
800 * host1x_client_unregister() - unregister a host1x client
801 * @client: host1x client
803 * Removes a host1x client from its host1x controller instance. If a logical
809 struct host1x *host1x; in host1x_client_unregister() local
814 list_for_each_entry(host1x, &devices, list) { in host1x_client_unregister()
815 err = host1x_del_client(host1x, client); in host1x_client_unregister()
827 list_del_init(&c->list); in host1x_client_unregister()
834 host1x_bo_cache_destroy(&client->cache); in host1x_client_unregister()
844 mutex_lock(&client->lock); in host1x_client_suspend()
846 if (client->usecount == 1) { in host1x_client_suspend()
847 if (client->ops && client->ops->suspend) { in host1x_client_suspend()
848 err = client->ops->suspend(client); in host1x_client_suspend()
854 client->usecount--; in host1x_client_suspend()
855 dev_dbg(client->dev, "use count: %u\n", client->usecount); in host1x_client_suspend()
857 if (client->parent) { in host1x_client_suspend()
858 err = host1x_client_suspend(client->parent); in host1x_client_suspend()
866 if (client->usecount == 0) in host1x_client_suspend()
867 if (client->ops && client->ops->resume) in host1x_client_suspend()
868 client->ops->resume(client); in host1x_client_suspend()
870 client->usecount++; in host1x_client_suspend()
872 mutex_unlock(&client->lock); in host1x_client_suspend()
881 mutex_lock(&client->lock); in host1x_client_resume()
883 if (client->parent) { in host1x_client_resume()
884 err = host1x_client_resume(client->parent); in host1x_client_resume()
889 if (client->usecount == 0) { in host1x_client_resume()
890 if (client->ops && client->ops->resume) { in host1x_client_resume()
891 err = client->ops->resume(client); in host1x_client_resume()
897 client->usecount++; in host1x_client_resume()
898 dev_dbg(client->dev, "use count: %u\n", client->usecount); in host1x_client_resume()
903 if (client->parent) in host1x_client_resume()
904 host1x_client_suspend(client->parent); in host1x_client_resume()
906 mutex_unlock(&client->lock); in host1x_client_resume()
918 mutex_lock(&cache->lock); in host1x_bo_pin()
920 list_for_each_entry(mapping, &cache->mappings, entry) { in host1x_bo_pin()
921 if (mapping->bo == bo && mapping->direction == dir) { in host1x_bo_pin()
922 kref_get(&mapping->ref); in host1x_bo_pin()
928 mapping = bo->ops->pin(dev, bo, dir); in host1x_bo_pin()
932 spin_lock(&mapping->bo->lock); in host1x_bo_pin()
933 list_add_tail(&mapping->list, &bo->mappings); in host1x_bo_pin()
934 spin_unlock(&mapping->bo->lock); in host1x_bo_pin()
937 INIT_LIST_HEAD(&mapping->entry); in host1x_bo_pin()
938 mapping->cache = cache; in host1x_bo_pin()
940 list_add_tail(&mapping->entry, &cache->mappings); in host1x_bo_pin()
943 kref_get(&mapping->ref); in host1x_bo_pin()
948 mutex_unlock(&cache->lock); in host1x_bo_pin()
962 if (mapping->cache) in __host1x_bo_unpin()
963 list_del(&mapping->entry); in __host1x_bo_unpin()
965 spin_lock(&mapping->bo->lock); in __host1x_bo_unpin()
966 list_del(&mapping->list); in __host1x_bo_unpin()
967 spin_unlock(&mapping->bo->lock); in __host1x_bo_unpin()
969 mapping->bo->ops->unpin(mapping); in __host1x_bo_unpin()
974 struct host1x_bo_cache *cache = mapping->cache; in host1x_bo_unpin()
977 mutex_lock(&cache->lock); in host1x_bo_unpin()
979 kref_put(&mapping->ref, __host1x_bo_unpin); in host1x_bo_unpin()
982 mutex_unlock(&cache->lock); in host1x_bo_unpin()