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()
364 .name = "host1x",
375 mutex_lock(&device->subdevs_lock); in __host1x_device_del()
378 list_for_each_entry_safe(subdev, sd, &device->active, list) { in __host1x_device_del()
388 client = subdev->client; in __host1x_device_del()
394 list_add_tail(&client->list, &clients); in __host1x_device_del()
399 list_for_each_entry_safe(subdev, sd, &device->subdevs, list) in __host1x_device_del()
402 mutex_unlock(&device->subdevs_lock); in __host1x_device_del()
406 mutex_lock(&device->clients_lock); in __host1x_device_del()
408 list_for_each_entry_safe(client, cl, &device->clients, list) in __host1x_device_del()
409 list_move_tail(&client->list, &clients); in __host1x_device_del()
411 mutex_unlock(&device->clients_lock); in __host1x_device_del()
415 list_del_init(&device->list); in __host1x_device_del()
426 static int host1x_device_add(struct host1x *host1x, in host1x_device_add() argument
436 return -ENOMEM; in host1x_device_add()
438 device_initialize(&device->dev); in host1x_device_add()
440 mutex_init(&device->subdevs_lock); in host1x_device_add()
441 INIT_LIST_HEAD(&device->subdevs); in host1x_device_add()
442 INIT_LIST_HEAD(&device->active); in host1x_device_add()
443 mutex_init(&device->clients_lock); in host1x_device_add()
444 INIT_LIST_HEAD(&device->clients); in host1x_device_add()
445 INIT_LIST_HEAD(&device->list); in host1x_device_add()
446 device->driver = driver; in host1x_device_add()
448 device->dev.coherent_dma_mask = host1x->dev->coherent_dma_mask; in host1x_device_add()
449 device->dev.dma_mask = &device->dev.coherent_dma_mask; in host1x_device_add()
450 dev_set_name(&device->dev, "%s", driver->driver.name); in host1x_device_add()
451 device->dev.release = host1x_device_release; in host1x_device_add()
452 device->dev.bus = &host1x_bus_type; in host1x_device_add()
453 device->dev.parent = host1x->dev; in host1x_device_add()
455 device->dev.dma_parms = &device->dma_parms; in host1x_device_add()
456 dma_set_max_seg_size(&device->dev, UINT_MAX); in host1x_device_add()
464 list_add_tail(&device->list, &host1x->devices); in host1x_device_add()
469 list_for_each_entry(subdev, &device->subdevs, list) { in host1x_device_add()
470 if (subdev->np == client->dev->of_node) { in host1x_device_add()
486 * This function must be called with the host1x->devices_lock held.
488 static void host1x_device_del(struct host1x *host1x, in host1x_device_del() argument
491 if (device->registered) { in host1x_device_del()
492 device->registered = false; in host1x_device_del()
493 device_del(&device->dev); in host1x_device_del()
496 put_device(&device->dev); in host1x_device_del()
499 static void host1x_attach_driver(struct host1x *host1x, in host1x_attach_driver() argument
505 mutex_lock(&host1x->devices_lock); in host1x_attach_driver()
507 list_for_each_entry(device, &host1x->devices, list) { in host1x_attach_driver()
508 if (device->driver == driver) { in host1x_attach_driver()
509 mutex_unlock(&host1x->devices_lock); in host1x_attach_driver()
514 err = host1x_device_add(host1x, driver); in host1x_attach_driver()
516 dev_err(host1x->dev, "failed to allocate device: %d\n", err); in host1x_attach_driver()
518 mutex_unlock(&host1x->devices_lock); in host1x_attach_driver()
521 static void host1x_detach_driver(struct host1x *host1x, in host1x_detach_driver() argument
526 mutex_lock(&host1x->devices_lock); in host1x_detach_driver()
528 list_for_each_entry_safe(device, tmp, &host1x->devices, list) in host1x_detach_driver()
529 if (device->driver == driver) in host1x_detach_driver()
530 host1x_device_del(host1x, device); in host1x_detach_driver()
532 mutex_unlock(&host1x->devices_lock); in host1x_detach_driver()
537 struct host1x *host1x = s->private; in host1x_devices_show() local
540 mutex_lock(&host1x->devices_lock); in host1x_devices_show()
542 list_for_each_entry(device, &host1x->devices, list) { in host1x_devices_show()
545 seq_printf(s, "%s\n", dev_name(&device->dev)); in host1x_devices_show()
547 mutex_lock(&device->subdevs_lock); in host1x_devices_show()
549 list_for_each_entry(subdev, &device->active, list) in host1x_devices_show()
550 seq_printf(s, " %pOFf: %s\n", subdev->np, in host1x_devices_show()
551 dev_name(subdev->client->dev)); in host1x_devices_show()
553 list_for_each_entry(subdev, &device->subdevs, list) in host1x_devices_show()
554 seq_printf(s, " %pOFf:\n", subdev->np); in host1x_devices_show()
556 mutex_unlock(&device->subdevs_lock); in host1x_devices_show()
559 mutex_unlock(&host1x->devices_lock); in host1x_devices_show()
566 * host1x_register() - register a host1x controller
567 * @host1x: host1x controller
569 * The host1x controller driver uses this to register a host1x controller with
571 * with a single host1x instance, so this function is somewhat academic.
573 int host1x_register(struct host1x *host1x) in host1x_register() argument
578 list_add_tail(&host1x->list, &devices); in host1x_register()
584 host1x_attach_driver(host1x, driver); in host1x_register()
588 debugfs_create_file("devices", S_IRUGO, host1x->debugfs, host1x, in host1x_register()
595 * host1x_unregister() - unregister a host1x controller
596 * @host1x: host1x controller
598 * The host1x controller driver uses this to remove a host1x controller from
601 int host1x_unregister(struct host1x *host1x) in host1x_unregister() argument
608 host1x_detach_driver(host1x, driver); in host1x_unregister()
613 list_del_init(&host1x->list); in host1x_unregister()
621 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_probe()
624 if (driver->probe) in host1x_device_probe()
625 return driver->probe(device); in host1x_device_probe()
632 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_remove()
635 if (driver->remove) in host1x_device_remove()
636 return driver->remove(device); in host1x_device_remove()
643 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_shutdown()
646 if (driver->shutdown) in host1x_device_shutdown()
647 driver->shutdown(device); in host1x_device_shutdown()
651 * host1x_driver_register_full() - register a host1x driver
652 * @driver: host1x driver
655 * Drivers for host1x logical devices call this function to register a driver
658 * A logical device will be created for each host1x instance.
663 struct host1x *host1x; in host1x_driver_register_full() local
665 INIT_LIST_HEAD(&driver->list); in host1x_driver_register_full()
668 list_add_tail(&driver->list, &drivers); in host1x_driver_register_full()
673 list_for_each_entry(host1x, &devices, list) in host1x_driver_register_full()
674 host1x_attach_driver(host1x, driver); in host1x_driver_register_full()
678 driver->driver.bus = &host1x_bus_type; in host1x_driver_register_full()
679 driver->driver.owner = owner; in host1x_driver_register_full()
680 driver->driver.probe = host1x_device_probe; in host1x_driver_register_full()
681 driver->driver.remove = host1x_device_remove; in host1x_driver_register_full()
682 driver->driver.shutdown = host1x_device_shutdown; in host1x_driver_register_full()
684 return driver_register(&driver->driver); in host1x_driver_register_full()
689 * host1x_driver_unregister() - unregister a host1x driver
690 * @driver: host1x driver
692 * Unbinds the driver from each of the host1x logical devices that it is
697 struct host1x *host1x; in host1x_driver_unregister() local
699 driver_unregister(&driver->driver); in host1x_driver_unregister()
703 list_for_each_entry(host1x, &devices, list) in host1x_driver_unregister()
704 host1x_detach_driver(host1x, driver); in host1x_driver_unregister()
709 list_del_init(&driver->list); in host1x_driver_unregister()
715 * __host1x_client_init() - initialize a host1x client
716 * @client: host1x client
717 * @key: lock class key for the client-specific mutex
721 host1x_bo_cache_init(&client->cache); in __host1x_client_init()
722 INIT_LIST_HEAD(&client->list); in __host1x_client_init()
723 __mutex_init(&client->lock, "host1x client lock", key); in __host1x_client_init()
724 client->usecount = 0; in __host1x_client_init()
729 * host1x_client_exit() - uninitialize a host1x client
730 * @client: host1x client
734 mutex_destroy(&client->lock); in host1x_client_exit()
739 * __host1x_client_register() - register a host1x client
740 * @client: host1x client
742 * Registers a host1x client with each host1x controller instance. Note that
743 * each client will only match their parent host1x controller and will only be
745 * their parent host1x controller, the infrastructure will set up the logical
751 struct host1x *host1x; in __host1x_client_register() local
756 list_for_each_entry(host1x, &devices, list) { in __host1x_client_register()
757 err = host1x_add_client(host1x, client); in __host1x_client_register()
767 list_add_tail(&client->list, &clients); in __host1x_client_register()
775 * host1x_client_unregister() - unregister a host1x client
776 * @client: host1x client
778 * Removes a host1x client from its host1x controller instance. If a logical
784 struct host1x *host1x; in host1x_client_unregister() local
789 list_for_each_entry(host1x, &devices, list) { in host1x_client_unregister()
790 err = host1x_del_client(host1x, client); in host1x_client_unregister()
802 list_del_init(&c->list); in host1x_client_unregister()
809 host1x_bo_cache_destroy(&client->cache); in host1x_client_unregister()
817 mutex_lock(&client->lock); in host1x_client_suspend()
819 if (client->usecount == 1) { in host1x_client_suspend()
820 if (client->ops && client->ops->suspend) { in host1x_client_suspend()
821 err = client->ops->suspend(client); in host1x_client_suspend()
827 client->usecount--; in host1x_client_suspend()
828 dev_dbg(client->dev, "use count: %u\n", client->usecount); in host1x_client_suspend()
830 if (client->parent) { in host1x_client_suspend()
831 err = host1x_client_suspend(client->parent); in host1x_client_suspend()
839 if (client->usecount == 0) in host1x_client_suspend()
840 if (client->ops && client->ops->resume) in host1x_client_suspend()
841 client->ops->resume(client); in host1x_client_suspend()
843 client->usecount++; in host1x_client_suspend()
845 mutex_unlock(&client->lock); in host1x_client_suspend()
854 mutex_lock(&client->lock); in host1x_client_resume()
856 if (client->parent) { in host1x_client_resume()
857 err = host1x_client_resume(client->parent); in host1x_client_resume()
862 if (client->usecount == 0) { in host1x_client_resume()
863 if (client->ops && client->ops->resume) { in host1x_client_resume()
864 err = client->ops->resume(client); in host1x_client_resume()
870 client->usecount++; in host1x_client_resume()
871 dev_dbg(client->dev, "use count: %u\n", client->usecount); in host1x_client_resume()
876 if (client->parent) in host1x_client_resume()
877 host1x_client_suspend(client->parent); in host1x_client_resume()
879 mutex_unlock(&client->lock); in host1x_client_resume()
891 mutex_lock(&cache->lock); in host1x_bo_pin()
893 list_for_each_entry(mapping, &cache->mappings, entry) { in host1x_bo_pin()
894 if (mapping->bo == bo && mapping->direction == dir) { in host1x_bo_pin()
895 kref_get(&mapping->ref); in host1x_bo_pin()
901 mapping = bo->ops->pin(dev, bo, dir); in host1x_bo_pin()
905 spin_lock(&mapping->bo->lock); in host1x_bo_pin()
906 list_add_tail(&mapping->list, &bo->mappings); in host1x_bo_pin()
907 spin_unlock(&mapping->bo->lock); in host1x_bo_pin()
910 INIT_LIST_HEAD(&mapping->entry); in host1x_bo_pin()
911 mapping->cache = cache; in host1x_bo_pin()
913 list_add_tail(&mapping->entry, &cache->mappings); in host1x_bo_pin()
916 kref_get(&mapping->ref); in host1x_bo_pin()
921 mutex_unlock(&cache->lock); in host1x_bo_pin()
935 if (mapping->cache) in __host1x_bo_unpin()
936 list_del(&mapping->entry); in __host1x_bo_unpin()
938 spin_lock(&mapping->bo->lock); in __host1x_bo_unpin()
939 list_del(&mapping->list); in __host1x_bo_unpin()
940 spin_unlock(&mapping->bo->lock); in __host1x_bo_unpin()
942 mapping->bo->ops->unpin(mapping); in __host1x_bo_unpin()
947 struct host1x_bo_cache *cache = mapping->cache; in host1x_bo_unpin()
950 mutex_lock(&cache->lock); in host1x_bo_unpin()
952 kref_put(&mapping->ref, __host1x_bo_unpin); in host1x_bo_unpin()
955 mutex_unlock(&cache->lock); in host1x_bo_unpin()