blob: 96561c1265ae81b9e2bdc195c54d74acdfb3be80 [file] [log] [blame]
Mika Westerbergcdae7c02017-10-02 13:38:30 +03001/*
2 * Thunderbolt service API
3 *
4 * Copyright (C) 2017, Intel Corporation
5 * Authors: Michael Jamet <michael.jamet@intel.com>
6 * Mika Westerberg <mika.westerberg@linux.intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#ifndef THUNDERBOLT_H_
14#define THUNDERBOLT_H_
15
16#include <linux/list.h>
17#include <linux/uuid.h>
18
19/**
20 * struct tb_property_dir - XDomain property directory
21 * @uuid: Directory UUID or %NULL if root directory
22 * @properties: List of properties in this directory
23 *
24 * User needs to provide serialization if needed.
25 */
26struct tb_property_dir {
27 const uuid_t *uuid;
28 struct list_head properties;
29};
30
31enum tb_property_type {
32 TB_PROPERTY_TYPE_UNKNOWN = 0x00,
33 TB_PROPERTY_TYPE_DIRECTORY = 0x44,
34 TB_PROPERTY_TYPE_DATA = 0x64,
35 TB_PROPERTY_TYPE_TEXT = 0x74,
36 TB_PROPERTY_TYPE_VALUE = 0x76,
37};
38
39#define TB_PROPERTY_KEY_SIZE 8
40
41/**
42 * struct tb_property - XDomain property
43 * @list: Used to link properties together in a directory
44 * @key: Key for the property (always terminated).
45 * @type: Type of the property
46 * @length: Length of the property data in dwords
47 * @value: Property value
48 *
49 * Users use @type to determine which field in @value is filled.
50 */
51struct tb_property {
52 struct list_head list;
53 char key[TB_PROPERTY_KEY_SIZE + 1];
54 enum tb_property_type type;
55 size_t length;
56 union {
57 struct tb_property_dir *dir;
58 u8 *data;
59 char *text;
60 u32 immediate;
61 } value;
62};
63
64struct tb_property_dir *tb_property_parse_dir(const u32 *block,
65 size_t block_len);
66ssize_t tb_property_format_dir(const struct tb_property_dir *dir, u32 *block,
67 size_t block_len);
68struct tb_property_dir *tb_property_create_dir(const uuid_t *uuid);
69void tb_property_free_dir(struct tb_property_dir *dir);
70int tb_property_add_immediate(struct tb_property_dir *parent, const char *key,
71 u32 value);
72int tb_property_add_data(struct tb_property_dir *parent, const char *key,
73 const void *buf, size_t buflen);
74int tb_property_add_text(struct tb_property_dir *parent, const char *key,
75 const char *text);
76int tb_property_add_dir(struct tb_property_dir *parent, const char *key,
77 struct tb_property_dir *dir);
78void tb_property_remove(struct tb_property *tb_property);
79struct tb_property *tb_property_find(struct tb_property_dir *dir,
80 const char *key, enum tb_property_type type);
81struct tb_property *tb_property_get_next(struct tb_property_dir *dir,
82 struct tb_property *prev);
83
84#define tb_property_for_each(dir, property) \
85 for (property = tb_property_get_next(dir, NULL); \
86 property; \
87 property = tb_property_get_next(dir, property))
88
89#endif /* THUNDERBOLT_H_ */