greybus: hd: generalise cport allocation
[cascardo/linux.git] / drivers / staging / greybus / hd.h
1 /*
2  * Greybus Host Device
3  *
4  * Copyright 2014-2015 Google Inc.
5  * Copyright 2014-2015 Linaro Ltd.
6  *
7  * Released under the GPLv2 only.
8  */
9
10 #ifndef __HD_H
11 #define __HD_H
12
13 struct gb_host_device;
14 struct gb_message;
15
16 struct gb_hd_driver {
17         size_t  hd_priv_size;
18
19         int (*cport_allocate)(struct gb_host_device *hd, int cport_id,
20                                 unsigned long flags);
21         void (*cport_release)(struct gb_host_device *hd, u16 cport_id);
22         int (*cport_enable)(struct gb_host_device *hd, u16 cport_id);
23         int (*cport_disable)(struct gb_host_device *hd, u16 cport_id);
24         int (*message_send)(struct gb_host_device *hd, u16 dest_cport_id,
25                         struct gb_message *message, gfp_t gfp_mask);
26         void (*message_cancel)(struct gb_message *message);
27         int (*latency_tag_enable)(struct gb_host_device *hd, u16 cport_id);
28         int (*latency_tag_disable)(struct gb_host_device *hd, u16 cport_id);
29         int (*output)(struct gb_host_device *hd, void *req, u16 size, u8 cmd,
30                       bool async);
31         int (*cport_features_enable)(struct gb_host_device *hd, u16 cport_id);
32         int (*cport_features_disable)(struct gb_host_device *hd, u16 cport_id);
33 };
34
35 struct gb_host_device {
36         struct device dev;
37         int bus_id;
38         const struct gb_hd_driver *driver;
39
40         struct list_head modules;
41         struct list_head connections;
42         struct ida cport_id_map;
43
44         /* Number of CPorts supported by the UniPro IP */
45         size_t num_cports;
46
47         /* Host device buffer constraints */
48         size_t buffer_size_max;
49
50         struct gb_svc *svc;
51         /* Private data for the host driver */
52         unsigned long hd_priv[0] __aligned(sizeof(s64));
53 };
54 #define to_gb_host_device(d) container_of(d, struct gb_host_device, dev)
55
56 int gb_hd_cport_reserve(struct gb_host_device *hd, u16 cport_id);
57 int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id,
58                                         unsigned long flags);
59 void gb_hd_cport_release(struct gb_host_device *hd, u16 cport_id);
60
61 struct gb_host_device *gb_hd_create(struct gb_hd_driver *driver,
62                                         struct device *parent,
63                                         size_t buffer_size_max,
64                                         size_t num_cports);
65 int gb_hd_add(struct gb_host_device *hd);
66 void gb_hd_del(struct gb_host_device *hd);
67 void gb_hd_put(struct gb_host_device *hd);
68 int gb_hd_output(struct gb_host_device *hd, void *req, u16 size, u8 cmd,
69                  bool in_irq);
70
71 int gb_hd_init(void);
72 void gb_hd_exit(void);
73
74 #endif  /* __HD_H */