blob: b512b1e2b4f290ef5e0d121d765fc6ca71899e4b [file] [log] [blame]
Mika Westerbergcdae7c02017-10-02 13:38:30 +03001/*
2 * Thunderbolt service API
3 *
Mika Westerbergeaf8ff32017-10-02 13:38:31 +03004 * Copyright (C) 2014 Andreas Noever <andreas.noever@gmail.com>
Mika Westerbergcdae7c02017-10-02 13:38:30 +03005 * 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
17#include <linux/list.h>
18#include <linux/uuid.h>
19
Mika Westerbergeaf8ff32017-10-02 13:38:31 +030020enum tb_cfg_pkg_type {
21 TB_CFG_PKG_READ = 1,
22 TB_CFG_PKG_WRITE = 2,
23 TB_CFG_PKG_ERROR = 3,
24 TB_CFG_PKG_NOTIFY_ACK = 4,
25 TB_CFG_PKG_EVENT = 5,
26 TB_CFG_PKG_XDOMAIN_REQ = 6,
27 TB_CFG_PKG_XDOMAIN_RESP = 7,
28 TB_CFG_PKG_OVERRIDE = 8,
29 TB_CFG_PKG_RESET = 9,
30 TB_CFG_PKG_ICM_EVENT = 10,
31 TB_CFG_PKG_ICM_CMD = 11,
32 TB_CFG_PKG_ICM_RESP = 12,
33 TB_CFG_PKG_PREPARE_TO_SLEEP = 13,
34};
35
Mika Westerbergcdae7c02017-10-02 13:38:30 +030036/**
37 * struct tb_property_dir - XDomain property directory
38 * @uuid: Directory UUID or %NULL if root directory
39 * @properties: List of properties in this directory
40 *
41 * User needs to provide serialization if needed.
42 */
43struct tb_property_dir {
44 const uuid_t *uuid;
45 struct list_head properties;
46};
47
48enum tb_property_type {
49 TB_PROPERTY_TYPE_UNKNOWN = 0x00,
50 TB_PROPERTY_TYPE_DIRECTORY = 0x44,
51 TB_PROPERTY_TYPE_DATA = 0x64,
52 TB_PROPERTY_TYPE_TEXT = 0x74,
53 TB_PROPERTY_TYPE_VALUE = 0x76,
54};
55
56#define TB_PROPERTY_KEY_SIZE 8
57
58/**
59 * struct tb_property - XDomain property
60 * @list: Used to link properties together in a directory
61 * @key: Key for the property (always terminated).
62 * @type: Type of the property
63 * @length: Length of the property data in dwords
64 * @value: Property value
65 *
66 * Users use @type to determine which field in @value is filled.
67 */
68struct tb_property {
69 struct list_head list;
70 char key[TB_PROPERTY_KEY_SIZE + 1];
71 enum tb_property_type type;
72 size_t length;
73 union {
74 struct tb_property_dir *dir;
75 u8 *data;
76 char *text;
77 u32 immediate;
78 } value;
79};
80
81struct tb_property_dir *tb_property_parse_dir(const u32 *block,
82 size_t block_len);
83ssize_t tb_property_format_dir(const struct tb_property_dir *dir, u32 *block,
84 size_t block_len);
85struct tb_property_dir *tb_property_create_dir(const uuid_t *uuid);
86void tb_property_free_dir(struct tb_property_dir *dir);
87int tb_property_add_immediate(struct tb_property_dir *parent, const char *key,
88 u32 value);
89int tb_property_add_data(struct tb_property_dir *parent, const char *key,
90 const void *buf, size_t buflen);
91int tb_property_add_text(struct tb_property_dir *parent, const char *key,
92 const char *text);
93int tb_property_add_dir(struct tb_property_dir *parent, const char *key,
94 struct tb_property_dir *dir);
95void tb_property_remove(struct tb_property *tb_property);
96struct tb_property *tb_property_find(struct tb_property_dir *dir,
97 const char *key, enum tb_property_type type);
98struct tb_property *tb_property_get_next(struct tb_property_dir *dir,
99 struct tb_property *prev);
100
101#define tb_property_for_each(dir, property) \
102 for (property = tb_property_get_next(dir, NULL); \
103 property; \
104 property = tb_property_get_next(dir, property))
105
106#endif /* THUNDERBOLT_H_ */