greybus: es2: clean up CDSI CPort reservation
[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_enable)(struct gb_host_device *hd, u16 cport_id);
20         int (*cport_disable)(struct gb_host_device *hd, u16 cport_id);
21         int (*message_send)(struct gb_host_device *hd, u16 dest_cport_id,
22                         struct gb_message *message, gfp_t gfp_mask);
23         void (*message_cancel)(struct gb_message *message);
24         int (*latency_tag_enable)(struct gb_host_device *hd, u16 cport_id);
25         int (*latency_tag_disable)(struct gb_host_device *hd, u16 cport_id);
26         int (*output)(struct gb_host_device *hd, void *req, u16 size, u8 cmd,
27                       bool async);
28         int (*cport_features_enable)(struct gb_host_device *hd, u16 cport_id);
29         int (*cport_features_disable)(struct gb_host_device *hd, u16 cport_id);
30 };
31
32 struct gb_host_device {
33         struct device dev;
34         int bus_id;
35         const struct gb_hd_driver *driver;
36
37         struct list_head modules;
38         struct list_head connections;
39         struct ida cport_id_map;
40
41         /* Number of CPorts supported by the UniPro IP */
42         size_t num_cports;
43
44         /* Host device buffer constraints */
45         size_t buffer_size_max;
46
47         struct gb_svc *svc;
48         /* Private data for the host driver */
49         unsigned long hd_priv[0] __aligned(sizeof(s64));
50 };
51 #define to_gb_host_device(d) container_of(d, struct gb_host_device, dev)
52
53 int gb_hd_cport_reserve(struct gb_host_device *hd, u16 cport_id);
54 int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id);
55 void gb_hd_cport_release(struct gb_host_device *hd, u16 cport_id);
56
57 struct gb_host_device *gb_hd_create(struct gb_hd_driver *driver,
58                                         struct device *parent,
59                                         size_t buffer_size_max,
60                                         size_t num_cports);
61 int gb_hd_add(struct gb_host_device *hd);
62 void gb_hd_del(struct gb_host_device *hd);
63 void gb_hd_put(struct gb_host_device *hd);
64 int gb_hd_output(struct gb_host_device *hd, void *req, u16 size, u8 cmd,
65                  bool in_irq);
66
67 int gb_hd_init(void);
68 void gb_hd_exit(void);
69
70 #endif  /* __HD_H */