• Home
  • Raw
  • Download

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()
349 of_device_uevent(dev->parent, env); in host1x_device_uevent()
356 return of_dma_configure(dev, dev->of_node, true); in host1x_dma_configure()
369 .name = "host1x",
381 mutex_lock(&device->subdevs_lock); in __host1x_device_del()
384 list_for_each_entry_safe(subdev, sd, &device->active, list) { in __host1x_device_del()
394 client = subdev->client; in __host1x_device_del()
400 list_add_tail(&client->list, &clients); in __host1x_device_del()
405 list_for_each_entry_safe(subdev, sd, &device->subdevs, list) in __host1x_device_del()
408 mutex_unlock(&device->subdevs_lock); in __host1x_device_del()
412 mutex_lock(&device->clients_lock); in __host1x_device_del()
414 list_for_each_entry_safe(client, cl, &device->clients, list) in __host1x_device_del()
415 list_move_tail(&client->list, &clients); in __host1x_device_del()
417 mutex_unlock(&device->clients_lock); in __host1x_device_del()
421 list_del_init(&device->list); in __host1x_device_del()
432 static int host1x_device_add(struct host1x *host1x, in host1x_device_add() argument
442 return -ENOMEM; in host1x_device_add()
444 device_initialize(&device->dev); in host1x_device_add()
446 mutex_init(&device->subdevs_lock); in host1x_device_add()
447 INIT_LIST_HEAD(&device->subdevs); in host1x_device_add()
448 INIT_LIST_HEAD(&device->active); in host1x_device_add()
449 mutex_init(&device->clients_lock); in host1x_device_add()
450 INIT_LIST_HEAD(&device->clients); in host1x_device_add()
451 INIT_LIST_HEAD(&device->list); in host1x_device_add()
452 device->driver = driver; in host1x_device_add()
454 device->dev.coherent_dma_mask = host1x->dev->coherent_dma_mask; in host1x_device_add()
455 device->dev.dma_mask = &device->dev.coherent_dma_mask; in host1x_device_add()
456 dev_set_name(&device->dev, "%s", driver->driver.name); in host1x_device_add()
457 device->dev.release = host1x_device_release; in host1x_device_add()
458 device->dev.bus = &host1x_bus_type; in host1x_device_add()
459 device->dev.parent = host1x->dev; in host1x_device_add()
461 of_dma_configure(&device->dev, host1x->dev->of_node, true); in host1x_device_add()
463 device->dev.dma_parms = &device->dma_parms; in host1x_device_add()
464 dma_set_max_seg_size(&device->dev, UINT_MAX); in host1x_device_add()
472 list_add_tail(&device->list, &host1x->devices); in host1x_device_add()
477 list_for_each_entry(subdev, &device->subdevs, list) { in host1x_device_add()
478 if (subdev->np == client->dev->of_node) { in host1x_device_add()
494 * This function must be called with the host1x->devices_lock held.
496 static void host1x_device_del(struct host1x *host1x, in host1x_device_del() argument
499 if (device->registered) { in host1x_device_del()
500 device->registered = false; in host1x_device_del()
501 device_del(&device->dev); in host1x_device_del()
504 put_device(&device->dev); in host1x_device_del()
507 static void host1x_attach_driver(struct host1x *host1x, in host1x_attach_driver() argument
513 mutex_lock(&host1x->devices_lock); in host1x_attach_driver()
515 list_for_each_entry(device, &host1x->devices, list) { in host1x_attach_driver()
516 if (device->driver == driver) { in host1x_attach_driver()
517 mutex_unlock(&host1x->devices_lock); in host1x_attach_driver()
522 err = host1x_device_add(host1x, driver); in host1x_attach_driver()
524 dev_err(host1x->dev, "failed to allocate device: %d\n", err); in host1x_attach_driver()
526 mutex_unlock(&host1x->devices_lock); in host1x_attach_driver()
529 static void host1x_detach_driver(struct host1x *host1x, in host1x_detach_driver() argument
534 mutex_lock(&host1x->devices_lock); in host1x_detach_driver()
536 list_for_each_entry_safe(device, tmp, &host1x->devices, list) in host1x_detach_driver()
537 if (device->driver == driver) in host1x_detach_driver()
538 host1x_device_del(host1x, device); in host1x_detach_driver()
540 mutex_unlock(&host1x->devices_lock); in host1x_detach_driver()
545 struct host1x *host1x = s->private; in host1x_devices_show() local
548 mutex_lock(&host1x->devices_lock); in host1x_devices_show()
550 list_for_each_entry(device, &host1x->devices, list) { in host1x_devices_show()
553 seq_printf(s, "%s\n", dev_name(&device->dev)); in host1x_devices_show()
555 mutex_lock(&device->subdevs_lock); in host1x_devices_show()
557 list_for_each_entry(subdev, &device->active, list) in host1x_devices_show()
558 seq_printf(s, " %pOFf: %s\n", subdev->np, in host1x_devices_show()
559 dev_name(subdev->client->dev)); in host1x_devices_show()
561 list_for_each_entry(subdev, &device->subdevs, list) in host1x_devices_show()
562 seq_printf(s, " %pOFf:\n", subdev->np); in host1x_devices_show()
564 mutex_unlock(&device->subdevs_lock); in host1x_devices_show()
567 mutex_unlock(&host1x->devices_lock); in host1x_devices_show()
574 * host1x_register() - register a host1x controller
575 * @host1x: host1x controller
577 * The host1x controller driver uses this to register a host1x controller with
579 * with a single host1x instance, so this function is somewhat academic.
581 int host1x_register(struct host1x *host1x) in host1x_register() argument
586 list_add_tail(&host1x->list, &devices); in host1x_register()
592 host1x_attach_driver(host1x, driver); in host1x_register()
596 debugfs_create_file("devices", S_IRUGO, host1x->debugfs, host1x, in host1x_register()
603 * host1x_unregister() - unregister a host1x controller
604 * @host1x: host1x controller
606 * The host1x controller driver uses this to remove a host1x controller from
609 int host1x_unregister(struct host1x *host1x) in host1x_unregister() argument
616 host1x_detach_driver(host1x, driver); in host1x_unregister()
621 list_del_init(&host1x->list); in host1x_unregister()
629 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_probe()
632 if (driver->probe) in host1x_device_probe()
633 return driver->probe(device); in host1x_device_probe()
640 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_remove()
643 if (driver->remove) in host1x_device_remove()
644 return driver->remove(device); in host1x_device_remove()
651 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_shutdown()
654 if (driver->shutdown) in host1x_device_shutdown()
655 driver->shutdown(device); in host1x_device_shutdown()
659 * host1x_driver_register_full() - register a host1x driver
660 * @driver: host1x driver
663 * Drivers for host1x logical devices call this function to register a driver
666 * A logical device will be created for each host1x instance.
671 struct host1x *host1x; in host1x_driver_register_full() local
673 INIT_LIST_HEAD(&driver->list); in host1x_driver_register_full()
676 list_add_tail(&driver->list, &drivers); in host1x_driver_register_full()
681 list_for_each_entry(host1x, &devices, list) in host1x_driver_register_full()
682 host1x_attach_driver(host1x, driver); in host1x_driver_register_full()
686 driver->driver.bus = &host1x_bus_type; in host1x_driver_register_full()
687 driver->driver.owner = owner; in host1x_driver_register_full()
688 driver->driver.probe = host1x_device_probe; in host1x_driver_register_full()
689 driver->driver.remove = host1x_device_remove; in host1x_driver_register_full()
690 driver->driver.shutdown = host1x_device_shutdown; in host1x_driver_register_full()
692 return driver_register(&driver->driver); in host1x_driver_register_full()
697 * host1x_driver_unregister() - unregister a host1x driver
698 * @driver: host1x driver
700 * Unbinds the driver from each of the host1x logical devices that it is
705 struct host1x *host1x; in host1x_driver_unregister() local
707 driver_unregister(&driver->driver); in host1x_driver_unregister()
711 list_for_each_entry(host1x, &devices, list) in host1x_driver_unregister()
712 host1x_detach_driver(host1x, driver); in host1x_driver_unregister()
717 list_del_init(&driver->list); in host1x_driver_unregister()
723 * __host1x_client_init() - initialize a host1x client
724 * @client: host1x client
725 * @key: lock class key for the client-specific mutex
729 host1x_bo_cache_init(&client->cache); in __host1x_client_init()
730 INIT_LIST_HEAD(&client->list); in __host1x_client_init()
731 __mutex_init(&client->lock, "host1x client lock", key); in __host1x_client_init()
732 client->usecount = 0; in __host1x_client_init()
737 * host1x_client_exit() - uninitialize a host1x client
738 * @client: host1x client
742 mutex_destroy(&client->lock); in host1x_client_exit()
747 * __host1x_client_register() - register a host1x client
748 * @client: host1x client
750 * Registers a host1x client with each host1x controller instance. Note that
751 * each client will only match their parent host1x controller and will only be
753 * their parent host1x controller, the infrastructure will set up the logical
759 struct host1x *host1x; in __host1x_client_register() local
764 list_for_each_entry(host1x, &devices, list) { in __host1x_client_register()
765 err = host1x_add_client(host1x, client); in __host1x_client_register()
775 list_add_tail(&client->list, &clients); in __host1x_client_register()
783 * host1x_client_unregister() - unregister a host1x client
784 * @client: host1x client
786 * Removes a host1x client from its host1x controller instance. If a logical
792 struct host1x *host1x; in host1x_client_unregister() local
797 list_for_each_entry(host1x, &devices, list) { in host1x_client_unregister()
798 err = host1x_del_client(host1x, client); in host1x_client_unregister()
810 list_del_init(&c->list); in host1x_client_unregister()
817 host1x_bo_cache_destroy(&client->cache); in host1x_client_unregister()
825 mutex_lock(&client->lock); in host1x_client_suspend()
827 if (client->usecount == 1) { in host1x_client_suspend()
828 if (client->ops && client->ops->suspend) { in host1x_client_suspend()
829 err = client->ops->suspend(client); in host1x_client_suspend()
835 client->usecount--; in host1x_client_suspend()
836 dev_dbg(client->dev, "use count: %u\n", client->usecount); in host1x_client_suspend()
838 if (client->parent) { in host1x_client_suspend()
839 err = host1x_client_suspend(client->parent); in host1x_client_suspend()
847 if (client->usecount == 0) in host1x_client_suspend()
848 if (client->ops && client->ops->resume) in host1x_client_suspend()
849 client->ops->resume(client); in host1x_client_suspend()
851 client->usecount++; in host1x_client_suspend()
853 mutex_unlock(&client->lock); in host1x_client_suspend()
862 mutex_lock(&client->lock); in host1x_client_resume()
864 if (client->parent) { in host1x_client_resume()
865 err = host1x_client_resume(client->parent); in host1x_client_resume()
870 if (client->usecount == 0) { in host1x_client_resume()
871 if (client->ops && client->ops->resume) { in host1x_client_resume()
872 err = client->ops->resume(client); in host1x_client_resume()
878 client->usecount++; in host1x_client_resume()
879 dev_dbg(client->dev, "use count: %u\n", client->usecount); in host1x_client_resume()
884 if (client->parent) in host1x_client_resume()
885 host1x_client_suspend(client->parent); in host1x_client_resume()
887 mutex_unlock(&client->lock); in host1x_client_resume()
899 mutex_lock(&cache->lock); in host1x_bo_pin()
901 list_for_each_entry(mapping, &cache->mappings, entry) { in host1x_bo_pin()
902 if (mapping->bo == bo && mapping->direction == dir) { in host1x_bo_pin()
903 kref_get(&mapping->ref); in host1x_bo_pin()
909 mapping = bo->ops->pin(dev, bo, dir); in host1x_bo_pin()
913 spin_lock(&mapping->bo->lock); in host1x_bo_pin()
914 list_add_tail(&mapping->list, &bo->mappings); in host1x_bo_pin()
915 spin_unlock(&mapping->bo->lock); in host1x_bo_pin()
918 INIT_LIST_HEAD(&mapping->entry); in host1x_bo_pin()
919 mapping->cache = cache; in host1x_bo_pin()
921 list_add_tail(&mapping->entry, &cache->mappings); in host1x_bo_pin()
924 kref_get(&mapping->ref); in host1x_bo_pin()
929 mutex_unlock(&cache->lock); in host1x_bo_pin()
943 if (mapping->cache) in __host1x_bo_unpin()
944 list_del(&mapping->entry); in __host1x_bo_unpin()
946 spin_lock(&mapping->bo->lock); in __host1x_bo_unpin()
947 list_del(&mapping->list); in __host1x_bo_unpin()
948 spin_unlock(&mapping->bo->lock); in __host1x_bo_unpin()
950 mapping->bo->ops->unpin(mapping); in __host1x_bo_unpin()
955 struct host1x_bo_cache *cache = mapping->cache; in host1x_bo_unpin()
958 mutex_lock(&cache->lock); in host1x_bo_unpin()
960 kref_put(&mapping->ref, __host1x_bo_unpin); in host1x_bo_unpin()
963 mutex_unlock(&cache->lock); in host1x_bo_unpin()