Commit | Line | Data |
---|---|---|
cdae7c07 MW |
1 | /* |
2 | * Thunderbolt service API | |
3 | * | |
eaf8ff35 | 4 | * Copyright (C) 2014 Andreas Noever <andreas.noever@gmail.com> |
cdae7c07 MW |
5 | * Copyright (C) 2017, Intel Corporation |
6 | * Authors: Michael Jamet <michael.jamet@intel.com> | |
7 | * Mika Westerberg <mika.westerberg@linux.intel.com> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | */ | |
13 | ||
14 | #ifndef THUNDERBOLT_H_ | |
15 | #define THUNDERBOLT_H_ | |
16 | ||
9e99b9f4 | 17 | #include <linux/device.h> |
cdae7c07 | 18 | #include <linux/list.h> |
9e99b9f4 | 19 | #include <linux/mutex.h> |
cdae7c07 MW |
20 | #include <linux/uuid.h> |
21 | ||
eaf8ff35 MW |
22 | enum tb_cfg_pkg_type { |
23 | TB_CFG_PKG_READ = 1, | |
24 | TB_CFG_PKG_WRITE = 2, | |
25 | TB_CFG_PKG_ERROR = 3, | |
26 | TB_CFG_PKG_NOTIFY_ACK = 4, | |
27 | TB_CFG_PKG_EVENT = 5, | |
28 | TB_CFG_PKG_XDOMAIN_REQ = 6, | |
29 | TB_CFG_PKG_XDOMAIN_RESP = 7, | |
30 | TB_CFG_PKG_OVERRIDE = 8, | |
31 | TB_CFG_PKG_RESET = 9, | |
32 | TB_CFG_PKG_ICM_EVENT = 10, | |
33 | TB_CFG_PKG_ICM_CMD = 11, | |
34 | TB_CFG_PKG_ICM_RESP = 12, | |
35 | TB_CFG_PKG_PREPARE_TO_SLEEP = 13, | |
36 | }; | |
37 | ||
9e99b9f4 MW |
38 | /** |
39 | * enum tb_security_level - Thunderbolt security level | |
40 | * @TB_SECURITY_NONE: No security, legacy mode | |
41 | * @TB_SECURITY_USER: User approval required at minimum | |
42 | * @TB_SECURITY_SECURE: One time saved key required at minimum | |
43 | * @TB_SECURITY_DPONLY: Only tunnel Display port (and USB) | |
44 | */ | |
45 | enum tb_security_level { | |
46 | TB_SECURITY_NONE, | |
47 | TB_SECURITY_USER, | |
48 | TB_SECURITY_SECURE, | |
49 | TB_SECURITY_DPONLY, | |
50 | }; | |
51 | ||
52 | /** | |
53 | * struct tb - main thunderbolt bus structure | |
54 | * @dev: Domain device | |
55 | * @lock: Big lock. Must be held when accessing any struct | |
56 | * tb_switch / struct tb_port. | |
57 | * @nhi: Pointer to the NHI structure | |
58 | * @ctl: Control channel for this domain | |
59 | * @wq: Ordered workqueue for all domain specific work | |
60 | * @root_switch: Root switch of this domain | |
61 | * @cm_ops: Connection manager specific operations vector | |
62 | * @index: Linux assigned domain number | |
63 | * @security_level: Current security level | |
64 | * @privdata: Private connection manager specific data | |
65 | */ | |
66 | struct tb { | |
67 | struct device dev; | |
68 | struct mutex lock; | |
69 | struct tb_nhi *nhi; | |
70 | struct tb_ctl *ctl; | |
71 | struct workqueue_struct *wq; | |
72 | struct tb_switch *root_switch; | |
73 | const struct tb_cm_ops *cm_ops; | |
74 | int index; | |
75 | enum tb_security_level security_level; | |
76 | unsigned long privdata[0]; | |
77 | }; | |
78 | ||
79 | extern struct bus_type tb_bus_type; | |
80 | ||
cdae7c07 MW |
81 | /** |
82 | * struct tb_property_dir - XDomain property directory | |
83 | * @uuid: Directory UUID or %NULL if root directory | |
84 | * @properties: List of properties in this directory | |
85 | * | |
86 | * User needs to provide serialization if needed. | |
87 | */ | |
88 | struct tb_property_dir { | |
89 | const uuid_t *uuid; | |
90 | struct list_head properties; | |
91 | }; | |
92 | ||
93 | enum tb_property_type { | |
94 | TB_PROPERTY_TYPE_UNKNOWN = 0x00, | |
95 | TB_PROPERTY_TYPE_DIRECTORY = 0x44, | |
96 | TB_PROPERTY_TYPE_DATA = 0x64, | |
97 | TB_PROPERTY_TYPE_TEXT = 0x74, | |
98 | TB_PROPERTY_TYPE_VALUE = 0x76, | |
99 | }; | |
100 | ||
101 | #define TB_PROPERTY_KEY_SIZE 8 | |
102 | ||
103 | /** | |
104 | * struct tb_property - XDomain property | |
105 | * @list: Used to link properties together in a directory | |
106 | * @key: Key for the property (always terminated). | |
107 | * @type: Type of the property | |
108 | * @length: Length of the property data in dwords | |
109 | * @value: Property value | |
110 | * | |
111 | * Users use @type to determine which field in @value is filled. | |
112 | */ | |
113 | struct tb_property { | |
114 | struct list_head list; | |
115 | char key[TB_PROPERTY_KEY_SIZE + 1]; | |
116 | enum tb_property_type type; | |
117 | size_t length; | |
118 | union { | |
119 | struct tb_property_dir *dir; | |
120 | u8 *data; | |
121 | char *text; | |
122 | u32 immediate; | |
123 | } value; | |
124 | }; | |
125 | ||
126 | struct tb_property_dir *tb_property_parse_dir(const u32 *block, | |
127 | size_t block_len); | |
128 | ssize_t tb_property_format_dir(const struct tb_property_dir *dir, u32 *block, | |
129 | size_t block_len); | |
130 | struct tb_property_dir *tb_property_create_dir(const uuid_t *uuid); | |
131 | void tb_property_free_dir(struct tb_property_dir *dir); | |
132 | int tb_property_add_immediate(struct tb_property_dir *parent, const char *key, | |
133 | u32 value); | |
134 | int tb_property_add_data(struct tb_property_dir *parent, const char *key, | |
135 | const void *buf, size_t buflen); | |
136 | int tb_property_add_text(struct tb_property_dir *parent, const char *key, | |
137 | const char *text); | |
138 | int tb_property_add_dir(struct tb_property_dir *parent, const char *key, | |
139 | struct tb_property_dir *dir); | |
140 | void tb_property_remove(struct tb_property *tb_property); | |
141 | struct tb_property *tb_property_find(struct tb_property_dir *dir, | |
142 | const char *key, enum tb_property_type type); | |
143 | struct tb_property *tb_property_get_next(struct tb_property_dir *dir, | |
144 | struct tb_property *prev); | |
145 | ||
146 | #define tb_property_for_each(dir, property) \ | |
147 | for (property = tb_property_get_next(dir, NULL); \ | |
148 | property; \ | |
149 | property = tb_property_get_next(dir, property)) | |
150 | ||
151 | #endif /* THUNDERBOLT_H_ */ |