Skip to content

Commit b15d97d

Browse files
jhovoldgregkh
authored andcommitted
greybus: core: add module abstraction
Add Greybus module abstraction that will be used to implement controlled module removal (eject) and represent module geometry. Greybus module devices correspond to physical modules and have one or more interfaces. Modules have an id that is identical to the id of their primary interface, which in turn is the interface with lowest numbered id. The module name is constructed from the bus and module id: <bus_id>-<module_id> Interfaces, bundles, and control devices are consequently renamed as <bus_id>-<module_id>.<interface_id> <bus_id>-<module_id>.<interface_id>.<bundle_id> <bus_id>-<module_id>.<interface_id>.ctrl As before, interface ids (and therefore in a sense now also module ids) correspond to physical interface positions on the frame. Modules have the following attributes: module_id num_interfaces where module_id is the id of the module and num_interface the number of interfaces the module has. Note that until SVC module-size detection has been implemented, all interfaces are considered to be part of 1x2 modules. Specifically, the two interfaces of a 2x2 module will be presented as two 1x2 modules for now. Signed-off-by: Johan Hovold <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 844fcbf commit b15d97d

File tree

11 files changed

+333
-96
lines changed

11 files changed

+333
-96
lines changed

drivers/staging/greybus/Documentation/sysfs-bus-greybus

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,133 +6,156 @@ Description:
66
The "root" greybus device for the Greybus device tree, or bus,
77
where N is a dynamically assigned 1-based id.
88

9-
What: /sys/bus/greybus/device/N-I
9+
What: /sys/bus/greybus/device/N-M
10+
Date: March 2016
11+
KernelVersion: 4.XX
12+
Contact: Greg Kroah-Hartman <[email protected]>
13+
Description:
14+
A Module M on the bus N, where M is the 1-byte interface
15+
ID of the module's primary interface.
16+
17+
What: /sys/bus/greybus/device/N-M/module_id
18+
Date: March 2016
19+
KernelVersion: 4.XX
20+
Contact: Greg Kroah-Hartman <[email protected]>
21+
Description:
22+
The ID of a Greybus module, corresponding to the ID of its
23+
primary interface.
24+
25+
What: /sys/bus/greybus/device/N-M/num_interfaces
26+
Date: March 2016
27+
KernelVersion: 4.XX
28+
Contact: Greg Kroah-Hartman <[email protected]>
29+
Description:
30+
The number of interfaces of a module.
31+
32+
What: /sys/bus/greybus/device/N-M.I
1033
Date: October 2015
1134
KernelVersion: 4.XX
1235
Contact: Greg Kroah-Hartman <[email protected]>
1336
Description:
14-
An Interface I on the bus N, where I is the 1-byte interface
15-
ID.
37+
An Interface I on the bus N and module N-M, where I is the
38+
1-byte interface ID.
1639

17-
What: /sys/bus/greybus/device/N-I/current_now
40+
What: /sys/bus/greybus/device/N-M.I/current_now
1841
Date: March 2016
1942
KernelVersion: 4.XX
2043
Contact: Greg Kroah-Hartman <[email protected]>
2144
Description:
2245
Current measurement of the interface in microamps (uA)
2346

24-
What: /sys/bus/greybus/device/N-I/ddbl1_manufacturer_id
47+
What: /sys/bus/greybus/device/N-M.I/ddbl1_manufacturer_id
2548
Date: October 2015
2649
KernelVersion: 4.XX
2750
Contact: Greg Kroah-Hartman <[email protected]>
2851
Description:
2952
Unipro Device Descriptor Block Level 1 manufacturer ID for the
3053
greybus Interface.
3154

32-
What: /sys/bus/greybus/device/N-I/ddbl1_product_id
55+
What: /sys/bus/greybus/device/N-M.I/ddbl1_product_id
3356
Date: October 2015
3457
KernelVersion: 4.XX
3558
Contact: Greg Kroah-Hartman <[email protected]>
3659
Description:
3760
Unipro Device Descriptor Block Level 1 product ID for the
3861
greybus Interface.
3962

40-
What: /sys/bus/greybus/device/N-I/interface_id
63+
What: /sys/bus/greybus/device/N-M.I/interface_id
4164
Date: October 2015
4265
KernelVersion: 4.XX
4366
Contact: Greg Kroah-Hartman <[email protected]>
4467
Description:
4568
The ID of a Greybus interface.
4669

47-
What: /sys/bus/greybus/device/N-I/power_now
70+
What: /sys/bus/greybus/device/N-M.I/power_now
4871
Date: March 2016
4972
KernelVersion: 4.XX
5073
Contact: Greg Kroah-Hartman <[email protected]>
5174
Description:
5275
Power measurement of the interface in microwatts (uW)
5376

54-
What: /sys/bus/greybus/device/N-I/product_id
77+
What: /sys/bus/greybus/device/N-M.I/product_id
5578
Date: October 2015
5679
KernelVersion: 4.XX
5780
Contact: Greg Kroah-Hartman <[email protected]>
5881
Description:
5982
Product ID of a Greybus interface.
6083

61-
What: /sys/bus/greybus/device/N-I/serial_number
84+
What: /sys/bus/greybus/device/N-M.I/serial_number
6285
Date: October 2015
6386
KernelVersion: 4.XX
6487
Contact: Greg Kroah-Hartman <[email protected]>
6588
Description:
6689
Serial Number of the Greybus interface, represented by a 64 bit
6790
hexadecimal number.
6891

69-
What: /sys/bus/greybus/device/N-I/vendor_id
92+
What: /sys/bus/greybus/device/N-M.I/vendor_id
7093
Date: October 2015
7194
KernelVersion: 4.XX
7295
Contact: Greg Kroah-Hartman <[email protected]>
7396
Description:
7497
Vendor ID of a Greybus interface.
7598

76-
What: /sys/bus/greybus/device/N-I/version
99+
What: /sys/bus/greybus/device/N-M.I/version
77100
Date: October 2015
78101
KernelVersion: 4.XX
79102
Contact: Greg Kroah-Hartman <[email protected]>
80103
Description:
81104
Interface version represented as <16 bit major number>.<16 bit
82105
minor number>.
83106

84-
What: /sys/bus/greybus/device/N-I/voltage_now
107+
What: /sys/bus/greybus/device/N-M.I/voltage_now
85108
Date: March 2016
86109
KernelVersion: 4.XX
87110
Contact: Greg Kroah-Hartman <[email protected]>
88111
Description:
89112
Voltage measurement of the interface in microvolts (uV)
90113

91-
What: /sys/bus/greybus/device/N-I.ctrl
114+
What: /sys/bus/greybus/device/N-M.I.ctrl
92115
Date: October 2015
93116
KernelVersion: 4.XX
94117
Contact: Greg Kroah-Hartman <[email protected]>
95118
Description:
96119
Abstract control device for interface I that represents the
97120
current mode of an enumerated Greybus interface.
98121

99-
What: /sys/bus/greybus/device/N-I.ctrl/product_string
122+
What: /sys/bus/greybus/device/N-M.I.ctrl/product_string
100123
Date: October 2015
101124
KernelVersion: 4.XX
102125
Contact: Greg Kroah-Hartman <[email protected]>
103126
Description:
104127
Product ID string of a Greybus interface.
105128

106-
What: /sys/bus/greybus/device/N-I.ctrl/vendor_string
129+
What: /sys/bus/greybus/device/N-M.I.ctrl/vendor_string
107130
Date: October 2015
108131
KernelVersion: 4.XX
109132
Contact: Greg Kroah-Hartman <[email protected]>
110133
Description:
111134
Vendor ID string of a Greybus interface.
112135

113-
What: /sys/bus/greybus/device/N-I.B
136+
What: /sys/bus/greybus/device/N-M.I.B
114137
Date: October 2015
115138
KernelVersion: 4.XX
116139
Contact: Greg Kroah-Hartman <[email protected]>
117140
Description:
118141
A bundle B on the Interface I, B is replaced by a 1-byte
119142
number representing the bundle.
120143

121-
What: /sys/bus/greybus/device/N-I.B/bundle_class
144+
What: /sys/bus/greybus/device/N-M.I.B/bundle_class
122145
Date: October 2015
123146
KernelVersion: 4.XX
124147
Contact: Greg Kroah-Hartman <[email protected]>
125148
Description:
126149
The greybus class of the bundle B.
127150

128-
What: /sys/bus/greybus/device/N-I.B/bundle_id
151+
What: /sys/bus/greybus/device/N-M.I.B/bundle_id
129152
Date: October 2015
130153
KernelVersion: 4.XX
131154
Contact: Greg Kroah-Hartman <[email protected]>
132155
Description:
133156
The interface-unique id of the bundle B.
134157

135-
What: /sys/bus/greybus/device/N-I.B/state
158+
What: /sys/bus/greybus/device/N-M.I.B/state
136159
Date: October 2015
137160
KernelVersion: 4.XX
138161
Contact: Greg Kroah-Hartman <[email protected]>

drivers/staging/greybus/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ greybus-y := core.o \
22
debugfs.o \
33
hd.o \
44
manifest.o \
5+
module.o \
56
interface.o \
67
bundle.o \
78
connection.o \

drivers/staging/greybus/core.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,20 @@ static int greybus_module_match(struct device *dev, struct device_driver *drv)
8585
static int greybus_uevent(struct device *dev, struct kobj_uevent_env *env)
8686
{
8787
struct gb_host_device *hd;
88+
struct gb_module *module = NULL;
8889
struct gb_interface *intf = NULL;
8990
struct gb_control *control = NULL;
9091
struct gb_bundle *bundle = NULL;
9192
struct gb_svc *svc = NULL;
9293

9394
if (is_gb_host_device(dev)) {
9495
hd = to_gb_host_device(dev);
96+
} else if (is_gb_module(dev)) {
97+
module = to_gb_module(dev);
98+
hd = module->hd;
9599
} else if (is_gb_interface(dev)) {
96100
intf = to_gb_interface(dev);
101+
module = intf->module;
97102
hd = intf->hd;
98103
} else if (is_gb_control(dev)) {
99104
control = to_gb_control(dev);
@@ -102,6 +107,7 @@ static int greybus_uevent(struct device *dev, struct kobj_uevent_env *env)
102107
} else if (is_gb_bundle(dev)) {
103108
bundle = to_gb_bundle(dev);
104109
intf = bundle->intf;
110+
module = intf->module;
105111
hd = intf->hd;
106112
} else if (is_gb_svc(dev)) {
107113
svc = to_gb_svc(dev);
@@ -114,6 +120,11 @@ static int greybus_uevent(struct device *dev, struct kobj_uevent_env *env)
114120
if (add_uevent_var(env, "BUS=%u", hd->bus_id))
115121
return -ENOMEM;
116122

123+
if (module) {
124+
if (add_uevent_var(env, "MODULE=%u", module->module_id))
125+
return -ENOMEM;
126+
}
127+
117128
if (intf) {
118129
if (add_uevent_var(env, "INTERFACE=%u", intf->interface_id))
119130
return -ENOMEM;

drivers/staging/greybus/greybus.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "hd.h"
2929
#include "svc.h"
3030
#include "control.h"
31+
#include "module.h"
3132
#include "interface.h"
3233
#include "bundle.h"
3334
#include "connection.h"
@@ -112,6 +113,7 @@ struct dentry *gb_debugfs_get(void);
112113
extern struct bus_type greybus_bus_type;
113114

114115
extern struct device_type greybus_hd_type;
116+
extern struct device_type greybus_module_type;
115117
extern struct device_type greybus_interface_type;
116118
extern struct device_type greybus_control_type;
117119
extern struct device_type greybus_bundle_type;
@@ -122,6 +124,11 @@ static inline int is_gb_host_device(const struct device *dev)
122124
return dev->type == &greybus_hd_type;
123125
}
124126

127+
static inline int is_gb_module(const struct device *dev)
128+
{
129+
return dev->type == &greybus_module_type;
130+
}
131+
125132
static inline int is_gb_interface(const struct device *dev)
126133
{
127134
return dev->type == &greybus_interface_type;

drivers/staging/greybus/hd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct gb_host_device *gb_hd_create(struct gb_hd_driver *driver,
8989
hd->bus_id = ret;
9090

9191
hd->driver = driver;
92-
INIT_LIST_HEAD(&hd->interfaces);
92+
INIT_LIST_HEAD(&hd->modules);
9393
INIT_LIST_HEAD(&hd->connections);
9494
ida_init(&hd->cport_id_map);
9595
hd->buffer_size_max = buffer_size_max;

drivers/staging/greybus/hd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct gb_host_device {
3434
int bus_id;
3535
const struct gb_hd_driver *driver;
3636

37-
struct list_head interfaces;
37+
struct list_head modules;
3838
struct list_head connections;
3939
struct ida cport_id_map;
4040

drivers/staging/greybus/interface.c

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -333,21 +333,6 @@ static struct attribute *interface_attrs[] = {
333333
};
334334
ATTRIBUTE_GROUPS(interface);
335335

336-
337-
// FIXME, odds are you don't want to call this function, rework the caller to
338-
// not need it please.
339-
struct gb_interface *gb_interface_find(struct gb_host_device *hd,
340-
u8 interface_id)
341-
{
342-
struct gb_interface *intf;
343-
344-
list_for_each_entry(intf, &hd->interfaces, links)
345-
if (intf->interface_id == interface_id)
346-
return intf;
347-
348-
return NULL;
349-
}
350-
351336
static void gb_interface_release(struct device *dev)
352337
{
353338
struct gb_interface *intf = to_gb_interface(dev);
@@ -371,36 +356,34 @@ struct device_type greybus_interface_type = {
371356
*
372357
* Returns a pointer to the new interfce or a null pointer if a
373358
* failure occurs due to memory exhaustion.
374-
*
375-
* Locking: Caller ensures serialisation with gb_interface_remove and
376-
* gb_interface_find.
377359
*/
378-
struct gb_interface *gb_interface_create(struct gb_host_device *hd,
360+
struct gb_interface *gb_interface_create(struct gb_module *module,
379361
u8 interface_id)
380362
{
363+
struct gb_host_device *hd = module->hd;
381364
struct gb_interface *intf;
382365

383366
intf = kzalloc(sizeof(*intf), GFP_KERNEL);
384367
if (!intf)
385368
return NULL;
386369

387370
intf->hd = hd; /* XXX refcount? */
371+
intf->module = module;
388372
intf->interface_id = interface_id;
389373
INIT_LIST_HEAD(&intf->bundles);
390374
INIT_LIST_HEAD(&intf->manifest_descs);
391375

392376
/* Invalid device id to start with */
393377
intf->device_id = GB_INTERFACE_DEVICE_ID_BAD;
394378

395-
intf->dev.parent = &hd->dev;
379+
intf->dev.parent = &module->dev;
396380
intf->dev.bus = &greybus_bus_type;
397381
intf->dev.type = &greybus_interface_type;
398382
intf->dev.groups = interface_groups;
399-
intf->dev.dma_mask = hd->dev.dma_mask;
383+
intf->dev.dma_mask = module->dev.dma_mask;
400384
device_initialize(&intf->dev);
401-
dev_set_name(&intf->dev, "%d-%d", hd->bus_id, interface_id);
402-
403-
list_add(&intf->links, &hd->interfaces);
385+
dev_set_name(&intf->dev, "%s.%u", dev_name(&module->dev),
386+
interface_id);
404387

405388
return intf;
406389
}
@@ -579,15 +562,16 @@ int gb_interface_add(struct gb_interface *intf)
579562
return 0;
580563
}
581564

582-
/* Deregister an interface and drop its reference. */
583-
void gb_interface_remove(struct gb_interface *intf)
565+
/* Deregister an interface. */
566+
void gb_interface_del(struct gb_interface *intf)
584567
{
585568
if (device_is_registered(&intf->dev)) {
586569
device_del(&intf->dev);
587570
dev_info(&intf->dev, "Interface removed\n");
588571
}
572+
}
589573

590-
list_del(&intf->links);
591-
574+
void gb_interface_put(struct gb_interface *intf)
575+
{
592576
put_device(&intf->dev);
593577
}

drivers/staging/greybus/interface.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct gb_interface {
2020
struct gb_control *control;
2121

2222
struct list_head bundles;
23-
struct list_head links; /* gb_host_device->interfaces */
23+
struct list_head module_node;
2424
struct list_head manifest_descs;
2525
u8 interface_id; /* Physical location within the Endo */
2626
u8 device_id;
@@ -35,6 +35,7 @@ struct gb_interface {
3535
u16 version_minor;
3636

3737
struct gb_host_device *hd;
38+
struct gb_module *module;
3839

3940
unsigned long quirks;
4041

@@ -46,13 +47,14 @@ struct gb_interface {
4647
struct gb_interface *gb_interface_find(struct gb_host_device *hd,
4748
u8 interface_id);
4849

49-
struct gb_interface *gb_interface_create(struct gb_host_device *hd,
50+
struct gb_interface *gb_interface_create(struct gb_module *module,
5051
u8 interface_id);
5152
int gb_interface_activate(struct gb_interface *intf);
5253
void gb_interface_deactivate(struct gb_interface *intf);
5354
int gb_interface_enable(struct gb_interface *intf);
5455
void gb_interface_disable(struct gb_interface *intf);
5556
int gb_interface_add(struct gb_interface *intf);
56-
void gb_interface_remove(struct gb_interface *intf);
57+
void gb_interface_del(struct gb_interface *intf);
58+
void gb_interface_put(struct gb_interface *intf);
5759

5860
#endif /* __INTERFACE_H */

0 commit comments

Comments
 (0)