• 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/host1x.h>
33 * host1x_subdev_add() - add a new subdevice with an associated device node
34 * @device: host1x device to add the subdevice to
47 return -ENOMEM; in host1x_subdev_add()
49 INIT_LIST_HEAD(&subdev->list); in host1x_subdev_add()
50 subdev->np = of_node_get(np); in host1x_subdev_add()
52 mutex_lock(&device->subdevs_lock); in host1x_subdev_add()
53 list_add_tail(&subdev->list, &device->subdevs); in host1x_subdev_add()
54 mutex_unlock(&device->subdevs_lock); in host1x_subdev_add()
58 if (of_match_node(driver->subdevs, child) && in host1x_subdev_add()
73 * host1x_subdev_del() - remove subdevice
78 list_del(&subdev->list); in host1x_subdev_del()
79 of_node_put(subdev->np); in host1x_subdev_del()
84 * host1x_device_parse_dt() - scan device tree and add matching subdevices
85 * @device: host1x logical device
86 * @driver: host1x driver
94 for_each_child_of_node(device->dev.parent->of_node, np) { in host1x_device_parse_dt()
95 if (of_match_node(driver->subdevs, np) && in host1x_device_parse_dt()
119 mutex_lock(&device->subdevs_lock); in host1x_subdev_register()
120 mutex_lock(&device->clients_lock); in host1x_subdev_register()
121 list_move_tail(&client->list, &device->clients); in host1x_subdev_register()
122 list_move_tail(&subdev->list, &device->active); in host1x_subdev_register()
123 client->host = &device->dev; in host1x_subdev_register()
124 subdev->client = client; in host1x_subdev_register()
125 mutex_unlock(&device->clients_lock); in host1x_subdev_register()
126 mutex_unlock(&device->subdevs_lock); in host1x_subdev_register()
128 if (list_empty(&device->subdevs)) { in host1x_subdev_register()
129 err = device_add(&device->dev); in host1x_subdev_register()
131 dev_err(&device->dev, "failed to add: %d\n", err); in host1x_subdev_register()
133 device->registered = true; in host1x_subdev_register()
140 struct host1x_client *client = subdev->client; in __host1x_subdev_unregister()
146 if (list_empty(&device->subdevs)) { in __host1x_subdev_unregister()
147 if (device->registered) { in __host1x_subdev_unregister()
148 device->registered = false; in __host1x_subdev_unregister()
149 device_del(&device->dev); in __host1x_subdev_unregister()
157 mutex_lock(&device->clients_lock); in __host1x_subdev_unregister()
158 subdev->client = NULL; in __host1x_subdev_unregister()
159 client->host = NULL; in __host1x_subdev_unregister()
160 list_move_tail(&subdev->list, &device->subdevs); in __host1x_subdev_unregister()
169 list_del_init(&client->list); in __host1x_subdev_unregister()
170 mutex_unlock(&device->clients_lock); in __host1x_subdev_unregister()
176 mutex_lock(&device->subdevs_lock); in host1x_subdev_unregister()
178 mutex_unlock(&device->subdevs_lock); in host1x_subdev_unregister()
182 * host1x_device_init() - initialize a host1x logical device
183 * @device: host1x logical device
185 * The driver for the host1x logical device can call this during execution of
196 mutex_lock(&device->clients_lock); in host1x_device_init()
198 list_for_each_entry(client, &device->clients, list) { in host1x_device_init()
199 if (client->ops && client->ops->init) { in host1x_device_init()
200 err = client->ops->init(client); in host1x_device_init()
202 dev_err(&device->dev, in host1x_device_init()
204 dev_name(client->dev), err); in host1x_device_init()
210 mutex_unlock(&device->clients_lock); in host1x_device_init()
215 list_for_each_entry_continue_reverse(client, &device->clients, list) in host1x_device_init()
216 if (client->ops->exit) in host1x_device_init()
217 client->ops->exit(client); in host1x_device_init()
219 mutex_unlock(&device->clients_lock); in host1x_device_init()
225 * host1x_device_exit() - uninitialize host1x logical device
226 * @device: host1x logical device
228 * When the driver for a host1x logical device is unloaded, it can call this
230 * subsystem-specific data structure is removed and the functionality can no
238 mutex_lock(&device->clients_lock); in host1x_device_exit()
240 list_for_each_entry_reverse(client, &device->clients, list) { in host1x_device_exit()
241 if (client->ops && client->ops->exit) { in host1x_device_exit()
242 err = client->ops->exit(client); in host1x_device_exit()
244 dev_err(&device->dev, in host1x_device_exit()
246 dev_name(client->dev), err); in host1x_device_exit()
247 mutex_unlock(&device->clients_lock); in host1x_device_exit()
253 mutex_unlock(&device->clients_lock); in host1x_device_exit()
259 static int host1x_add_client(struct host1x *host1x, in host1x_add_client() argument
265 mutex_lock(&host1x->devices_lock); in host1x_add_client()
267 list_for_each_entry(device, &host1x->devices, list) { in host1x_add_client()
268 list_for_each_entry(subdev, &device->subdevs, list) { in host1x_add_client()
269 if (subdev->np == client->dev->of_node) { in host1x_add_client()
271 mutex_unlock(&host1x->devices_lock); in host1x_add_client()
277 mutex_unlock(&host1x->devices_lock); in host1x_add_client()
278 return -ENODEV; in host1x_add_client()
281 static int host1x_del_client(struct host1x *host1x, in host1x_del_client() argument
287 mutex_lock(&host1x->devices_lock); in host1x_del_client()
289 list_for_each_entry_safe(device, dt, &host1x->devices, list) { in host1x_del_client()
290 list_for_each_entry(subdev, &device->active, list) { in host1x_del_client()
291 if (subdev->client == client) { in host1x_del_client()
293 mutex_unlock(&host1x->devices_lock); in host1x_del_client()
299 mutex_unlock(&host1x->devices_lock); in host1x_del_client()
300 return -ENODEV; in host1x_del_client()
305 return strcmp(dev_name(dev), drv->name) == 0; in host1x_device_match()
311 struct device_node *np = dev->parent->of_node; in host1x_device_uevent()
318 * be called from modules and operates on dev->of_node, which is not in host1x_device_uevent()
340 return of_dma_configure(dev, dev->of_node, true); in host1x_dma_configure()
353 .name = "host1x",
365 mutex_lock(&device->subdevs_lock); in __host1x_device_del()
368 list_for_each_entry_safe(subdev, sd, &device->active, list) { in __host1x_device_del()
378 client = subdev->client; in __host1x_device_del()
384 list_add_tail(&client->list, &clients); in __host1x_device_del()
389 list_for_each_entry_safe(subdev, sd, &device->subdevs, list) in __host1x_device_del()
392 mutex_unlock(&device->subdevs_lock); in __host1x_device_del()
396 mutex_lock(&device->clients_lock); in __host1x_device_del()
398 list_for_each_entry_safe(client, cl, &device->clients, list) in __host1x_device_del()
399 list_move_tail(&client->list, &clients); in __host1x_device_del()
401 mutex_unlock(&device->clients_lock); in __host1x_device_del()
405 list_del_init(&device->list); in __host1x_device_del()
416 static int host1x_device_add(struct host1x *host1x, in host1x_device_add() argument
426 return -ENOMEM; in host1x_device_add()
428 device_initialize(&device->dev); in host1x_device_add()
430 mutex_init(&device->subdevs_lock); in host1x_device_add()
431 INIT_LIST_HEAD(&device->subdevs); in host1x_device_add()
432 INIT_LIST_HEAD(&device->active); in host1x_device_add()
433 mutex_init(&device->clients_lock); in host1x_device_add()
434 INIT_LIST_HEAD(&device->clients); in host1x_device_add()
435 INIT_LIST_HEAD(&device->list); in host1x_device_add()
436 device->driver = driver; in host1x_device_add()
438 device->dev.coherent_dma_mask = host1x->dev->coherent_dma_mask; in host1x_device_add()
439 device->dev.dma_mask = &device->dev.coherent_dma_mask; in host1x_device_add()
440 dev_set_name(&device->dev, "%s", driver->driver.name); in host1x_device_add()
441 device->dev.release = host1x_device_release; in host1x_device_add()
442 device->dev.bus = &host1x_bus_type; in host1x_device_add()
443 device->dev.parent = host1x->dev; in host1x_device_add()
445 of_dma_configure(&device->dev, host1x->dev->of_node, true); in host1x_device_add()
447 device->dev.dma_parms = &device->dma_parms; in host1x_device_add()
448 dma_set_max_seg_size(&device->dev, UINT_MAX); in host1x_device_add()
456 list_add_tail(&device->list, &host1x->devices); in host1x_device_add()
461 list_for_each_entry(subdev, &device->subdevs, list) { in host1x_device_add()
462 if (subdev->np == client->dev->of_node) { in host1x_device_add()
478 * This function must be called with the host1x->devices_lock held.
480 static void host1x_device_del(struct host1x *host1x, in host1x_device_del() argument
483 if (device->registered) { in host1x_device_del()
484 device->registered = false; in host1x_device_del()
485 device_del(&device->dev); in host1x_device_del()
488 put_device(&device->dev); in host1x_device_del()
491 static void host1x_attach_driver(struct host1x *host1x, in host1x_attach_driver() argument
497 mutex_lock(&host1x->devices_lock); in host1x_attach_driver()
499 list_for_each_entry(device, &host1x->devices, list) { in host1x_attach_driver()
500 if (device->driver == driver) { in host1x_attach_driver()
501 mutex_unlock(&host1x->devices_lock); in host1x_attach_driver()
506 err = host1x_device_add(host1x, driver); in host1x_attach_driver()
508 dev_err(host1x->dev, "failed to allocate device: %d\n", err); in host1x_attach_driver()
510 mutex_unlock(&host1x->devices_lock); in host1x_attach_driver()
513 static void host1x_detach_driver(struct host1x *host1x, in host1x_detach_driver() argument
518 mutex_lock(&host1x->devices_lock); in host1x_detach_driver()
520 list_for_each_entry_safe(device, tmp, &host1x->devices, list) in host1x_detach_driver()
521 if (device->driver == driver) in host1x_detach_driver()
522 host1x_device_del(host1x, device); in host1x_detach_driver()
524 mutex_unlock(&host1x->devices_lock); in host1x_detach_driver()
529 struct host1x *host1x = s->private; in host1x_devices_show() local
532 mutex_lock(&host1x->devices_lock); in host1x_devices_show()
534 list_for_each_entry(device, &host1x->devices, list) { in host1x_devices_show()
537 seq_printf(s, "%s\n", dev_name(&device->dev)); in host1x_devices_show()
539 mutex_lock(&device->subdevs_lock); in host1x_devices_show()
541 list_for_each_entry(subdev, &device->active, list) in host1x_devices_show()
542 seq_printf(s, " %pOFf: %s\n", subdev->np, in host1x_devices_show()
543 dev_name(subdev->client->dev)); in host1x_devices_show()
545 list_for_each_entry(subdev, &device->subdevs, list) in host1x_devices_show()
546 seq_printf(s, " %pOFf:\n", subdev->np); in host1x_devices_show()
548 mutex_unlock(&device->subdevs_lock); in host1x_devices_show()
551 mutex_unlock(&host1x->devices_lock); in host1x_devices_show()
558 * host1x_register() - register a host1x controller
559 * @host1x: host1x controller
561 * The host1x controller driver uses this to register a host1x controller with
563 * with a single host1x instance, so this function is somewhat academic.
565 int host1x_register(struct host1x *host1x) in host1x_register() argument
570 list_add_tail(&host1x->list, &devices); in host1x_register()
576 host1x_attach_driver(host1x, driver); in host1x_register()
580 debugfs_create_file("devices", S_IRUGO, host1x->debugfs, host1x, in host1x_register()
587 * host1x_unregister() - unregister a host1x controller
588 * @host1x: host1x controller
590 * The host1x controller driver uses this to remove a host1x controller from
593 int host1x_unregister(struct host1x *host1x) in host1x_unregister() argument
600 host1x_detach_driver(host1x, driver); in host1x_unregister()
605 list_del_init(&host1x->list); in host1x_unregister()
613 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_probe()
616 if (driver->probe) in host1x_device_probe()
617 return driver->probe(device); in host1x_device_probe()
624 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_remove()
627 if (driver->remove) in host1x_device_remove()
628 return driver->remove(device); in host1x_device_remove()
635 struct host1x_driver *driver = to_host1x_driver(dev->driver); in host1x_device_shutdown()
638 if (driver->shutdown) in host1x_device_shutdown()
639 driver->shutdown(device); in host1x_device_shutdown()
643 * host1x_driver_register_full() - register a host1x driver
644 * @driver: host1x driver
647 * Drivers for host1x logical devices call this function to register a driver
650 * A logical device will be created for each host1x instance.
655 struct host1x *host1x; in host1x_driver_register_full() local
657 INIT_LIST_HEAD(&driver->list); in host1x_driver_register_full()
660 list_add_tail(&driver->list, &drivers); in host1x_driver_register_full()
665 list_for_each_entry(host1x, &devices, list) in host1x_driver_register_full()
666 host1x_attach_driver(host1x, driver); in host1x_driver_register_full()
670 driver->driver.bus = &host1x_bus_type; in host1x_driver_register_full()
671 driver->driver.owner = owner; in host1x_driver_register_full()
672 driver->driver.probe = host1x_device_probe; in host1x_driver_register_full()
673 driver->driver.remove = host1x_device_remove; in host1x_driver_register_full()
674 driver->driver.shutdown = host1x_device_shutdown; in host1x_driver_register_full()
676 return driver_register(&driver->driver); in host1x_driver_register_full()
681 * host1x_driver_unregister() - unregister a host1x driver
682 * @driver: host1x driver
684 * Unbinds the driver from each of the host1x logical devices that it is
689 struct host1x *host1x; in host1x_driver_unregister() local
691 driver_unregister(&driver->driver); in host1x_driver_unregister()
695 list_for_each_entry(host1x, &devices, list) in host1x_driver_unregister()
696 host1x_detach_driver(host1x, driver); in host1x_driver_unregister()
701 list_del_init(&driver->list); in host1x_driver_unregister()
707 * __host1x_client_init() - initialize a host1x client
708 * @client: host1x client
709 * @key: lock class key for the client-specific mutex
713 INIT_LIST_HEAD(&client->list); in __host1x_client_init()
714 __mutex_init(&client->lock, "host1x client lock", key); in __host1x_client_init()
715 client->usecount = 0; in __host1x_client_init()
720 * host1x_client_exit() - uninitialize a host1x client
721 * @client: host1x client
725 mutex_destroy(&client->lock); in host1x_client_exit()
730 * __host1x_client_register() - register a host1x client
731 * @client: host1x client
732 * @key: lock class key for the client-specific mutex
734 * Registers a host1x client with each host1x controller instance. Note that
735 * each client will only match their parent host1x controller and will only be
737 * their parent host1x controller, the infrastructure will set up the logical
743 struct host1x *host1x; in __host1x_client_register() local
748 list_for_each_entry(host1x, &devices, list) { in __host1x_client_register()
749 err = host1x_add_client(host1x, client); in __host1x_client_register()
759 list_add_tail(&client->list, &clients); in __host1x_client_register()
767 * host1x_client_unregister() - unregister a host1x client
768 * @client: host1x client
770 * Removes a host1x client from its host1x controller instance. If a logical
776 struct host1x *host1x; in host1x_client_unregister() local
781 list_for_each_entry(host1x, &devices, list) { in host1x_client_unregister()
782 err = host1x_del_client(host1x, client); in host1x_client_unregister()
794 list_del_init(&c->list); in host1x_client_unregister()
809 mutex_lock(&client->lock); in host1x_client_suspend()
811 if (client->usecount == 1) { in host1x_client_suspend()
812 if (client->ops && client->ops->suspend) { in host1x_client_suspend()
813 err = client->ops->suspend(client); in host1x_client_suspend()
819 client->usecount--; in host1x_client_suspend()
820 dev_dbg(client->dev, "use count: %u\n", client->usecount); in host1x_client_suspend()
822 if (client->parent) { in host1x_client_suspend()
823 err = host1x_client_suspend(client->parent); in host1x_client_suspend()
831 if (client->usecount == 0) in host1x_client_suspend()
832 if (client->ops && client->ops->resume) in host1x_client_suspend()
833 client->ops->resume(client); in host1x_client_suspend()
835 client->usecount++; in host1x_client_suspend()
837 mutex_unlock(&client->lock); in host1x_client_suspend()
846 mutex_lock(&client->lock); in host1x_client_resume()
848 if (client->parent) { in host1x_client_resume()
849 err = host1x_client_resume(client->parent); in host1x_client_resume()
854 if (client->usecount == 0) { in host1x_client_resume()
855 if (client->ops && client->ops->resume) { in host1x_client_resume()
856 err = client->ops->resume(client); in host1x_client_resume()
862 client->usecount++; in host1x_client_resume()
863 dev_dbg(client->dev, "use count: %u\n", client->usecount); in host1x_client_resume()
868 if (client->parent) in host1x_client_resume()
869 host1x_client_suspend(client->parent); in host1x_client_resume()
871 mutex_unlock(&client->lock); in host1x_client_resume()