Mika Westerberg | cdae7c0 | 2017-10-02 13:38:30 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Thunderbolt service API |
| 3 | * |
Mika Westerberg | eaf8ff3 | 2017-10-02 13:38:31 +0300 | [diff] [blame] | 4 | * Copyright (C) 2014 Andreas Noever <andreas.noever@gmail.com> |
Mika Westerberg | cdae7c0 | 2017-10-02 13:38:30 +0300 | [diff] [blame] | 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 | |
Mika Westerberg | 9e99b9f | 2017-10-02 13:38:32 +0300 | [diff] [blame] | 17 | #include <linux/device.h> |
Mika Westerberg | cdae7c0 | 2017-10-02 13:38:30 +0300 | [diff] [blame] | 18 | #include <linux/list.h> |
Mika Westerberg | 9e99b9f | 2017-10-02 13:38:32 +0300 | [diff] [blame] | 19 | #include <linux/mutex.h> |
Mika Westerberg | cdae7c0 | 2017-10-02 13:38:30 +0300 | [diff] [blame] | 20 | #include <linux/uuid.h> |
| 21 | |
Mika Westerberg | eaf8ff3 | 2017-10-02 13:38:31 +0300 | [diff] [blame] | 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 | |
Mika Westerberg | cdae7c0 | 2017-10-02 13:38:30 +0300 | [diff] [blame] | 38 | /** |
Mika Westerberg | 9e99b9f | 2017-10-02 13:38:32 +0300 | [diff] [blame] | 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 | |
Mika Westerberg | e69b71f | 2017-10-02 13:38:33 +0300 | [diff] [blame^] | 81 | #define TB_LINKS_PER_PHY_PORT 2 |
| 82 | |
| 83 | static inline unsigned int tb_phy_port_from_link(unsigned int link) |
| 84 | { |
| 85 | return (link - 1) / TB_LINKS_PER_PHY_PORT; |
| 86 | } |
| 87 | |
Mika Westerberg | 9e99b9f | 2017-10-02 13:38:32 +0300 | [diff] [blame] | 88 | /** |
Mika Westerberg | cdae7c0 | 2017-10-02 13:38:30 +0300 | [diff] [blame] | 89 | * struct tb_property_dir - XDomain property directory |
| 90 | * @uuid: Directory UUID or %NULL if root directory |
| 91 | * @properties: List of properties in this directory |
| 92 | * |
| 93 | * User needs to provide serialization if needed. |
| 94 | */ |
| 95 | struct tb_property_dir { |
| 96 | const uuid_t *uuid; |
| 97 | struct list_head properties; |
| 98 | }; |
| 99 | |
| 100 | enum tb_property_type { |
| 101 | TB_PROPERTY_TYPE_UNKNOWN = 0x00, |
| 102 | TB_PROPERTY_TYPE_DIRECTORY = 0x44, |
| 103 | TB_PROPERTY_TYPE_DATA = 0x64, |
| 104 | TB_PROPERTY_TYPE_TEXT = 0x74, |
| 105 | TB_PROPERTY_TYPE_VALUE = 0x76, |
| 106 | }; |
| 107 | |
| 108 | #define TB_PROPERTY_KEY_SIZE 8 |
| 109 | |
| 110 | /** |
| 111 | * struct tb_property - XDomain property |
| 112 | * @list: Used to link properties together in a directory |
| 113 | * @key: Key for the property (always terminated). |
| 114 | * @type: Type of the property |
| 115 | * @length: Length of the property data in dwords |
| 116 | * @value: Property value |
| 117 | * |
| 118 | * Users use @type to determine which field in @value is filled. |
| 119 | */ |
| 120 | struct tb_property { |
| 121 | struct list_head list; |
| 122 | char key[TB_PROPERTY_KEY_SIZE + 1]; |
| 123 | enum tb_property_type type; |
| 124 | size_t length; |
| 125 | union { |
| 126 | struct tb_property_dir *dir; |
| 127 | u8 *data; |
| 128 | char *text; |
| 129 | u32 immediate; |
| 130 | } value; |
| 131 | }; |
| 132 | |
| 133 | struct tb_property_dir *tb_property_parse_dir(const u32 *block, |
| 134 | size_t block_len); |
| 135 | ssize_t tb_property_format_dir(const struct tb_property_dir *dir, u32 *block, |
| 136 | size_t block_len); |
| 137 | struct tb_property_dir *tb_property_create_dir(const uuid_t *uuid); |
| 138 | void tb_property_free_dir(struct tb_property_dir *dir); |
| 139 | int tb_property_add_immediate(struct tb_property_dir *parent, const char *key, |
| 140 | u32 value); |
| 141 | int tb_property_add_data(struct tb_property_dir *parent, const char *key, |
| 142 | const void *buf, size_t buflen); |
| 143 | int tb_property_add_text(struct tb_property_dir *parent, const char *key, |
| 144 | const char *text); |
| 145 | int tb_property_add_dir(struct tb_property_dir *parent, const char *key, |
| 146 | struct tb_property_dir *dir); |
| 147 | void tb_property_remove(struct tb_property *tb_property); |
| 148 | struct tb_property *tb_property_find(struct tb_property_dir *dir, |
| 149 | const char *key, enum tb_property_type type); |
| 150 | struct tb_property *tb_property_get_next(struct tb_property_dir *dir, |
| 151 | struct tb_property *prev); |
| 152 | |
| 153 | #define tb_property_for_each(dir, property) \ |
| 154 | for (property = tb_property_get_next(dir, NULL); \ |
| 155 | property; \ |
| 156 | property = tb_property_get_next(dir, property)) |
| 157 | |
| 158 | #endif /* THUNDERBOLT_H_ */ |