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->functions);
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);