4 * Copyright 2014 Google Inc.
6 * Released under the GPLv2 only.
11 /* XXX This could be per-host device or per-module */
12 static DEFINE_SPINLOCK(gb_interfaces_lock);
15 * A Greybus interface represents a UniPro device present on a
16 * module. For Project Ara, each active Interface Block on a module
17 * implements a UniPro device, and therefore a Greybus interface. A
18 * Greybus module has at least one interface, but can have two (or
21 * Create a gb_interface structure to represent a discovered
22 * interface. Returns a pointer to the new interface or a null
23 * pointer if a failure occurs due to memory exhaustion.
26 gb_interface_create(struct gb_module *gmod, u8 interface_id)
28 struct gb_interface *interface;
30 interface = kzalloc(sizeof(*interface), GFP_KERNEL);
34 interface->gmod = gmod; /* XXX refcount? */
35 interface->id = interface_id;
36 INIT_LIST_HEAD(&interface->connections);
38 spin_lock_irq(&gb_interfaces_lock);
39 list_add_tail(&interface->links, &gmod->interfaces);
40 spin_unlock_irq(&gb_interfaces_lock);
46 * Tear down a previously set up interface.
48 void gb_interface_destroy(struct gb_interface *interface)
50 if (WARN_ON(!interface))
53 spin_lock_irq(&gb_interfaces_lock);
54 list_del(&interface->links);
55 spin_unlock_irq(&gb_interfaces_lock);
57 gb_interface_connections_exit(interface);
63 struct gb_interface *gb_interface_find(struct gb_module *module,
66 struct gb_interface *interface;
68 list_for_each_entry(interface, &module->interfaces, links)
69 if (interface->id == interface_id)
75 int gb_interface_connections_init(struct gb_interface *interface)
77 struct gb_connection *connection;
80 list_for_each_entry(connection, &interface->connections,
82 ret = gb_connection_init(connection);
90 void gb_interface_connections_exit(struct gb_interface *interface)
92 struct gb_connection *connection;
93 struct gb_connection *next;
95 list_for_each_entry_safe(connection, next, &interface->connections,
97 gb_connection_exit(connection);
98 gb_connection_destroy(connection);