This repository was archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtarget_device_table_i.h
136 lines (121 loc) · 7.82 KB
/
target_device_table_i.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/***************************************************************************
USBI3C - Library to talk to I3C devices via USB.
-------------------
copyright : (C) 2022 Intel Corporation
SPDX-License-Identifier: LGPL-2.1-only
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License *
* version 2.1 as published by the Free Software Foundation. *
* *
***************************************************************************/
#ifndef __TARGET_DEVICE_TABLE_I_H__
#define __TARGET_DEVICE_TABLE_I_H__
#include <pthread.h>
#include <stdint.h>
#include "usbi3c_i.h"
#include "usbi3c_spec_i.h"
#define ADDRESS_LEN UINT8_MAX + 1
#define ADDRESS_BLOCK_SIZE (sizeof(uint64_t) * 8)
#define ADDRESS_MASK_LEN (ADDRESS_LEN / ADDRESS_BLOCK_SIZE)
#define USB_MAX_CONTROL_BUFFER_SIZE (CAPABILITY_HEADER_SIZE + CAPABILITY_BUS_SIZE + (ADDRESS_LEN * CAPABILITY_DEVICE_SIZE))
#define TARGET_INTERRUPT_REQUEST_MASK 0b001
#define CONTROLLER_ROLE_REQUEST_MASK 0b010
#define IBI_TIMESTAMP_REQUEST_MASK 0b100
/**
* @brief Function to be called when a device is inserted into the table.
*/
typedef void (*on_insert_fn)(uint8_t, void *);
/**
* @brief Structure representing the capabilities of an I3C device.
*/
struct target_device_capability {
uint8_t static_address; ///< the static address of the device (optional for I3C target devices)
uint8_t ibi_prioritization; ///< indicates the priority of the IBI generated by this device (lower values = higher priority)
uint16_t disco_minor_ver; ///< the minor version number of MIPI discovery protocol the device complies with
uint16_t disco_major_ver; ///< the major version number of MIPI discovery protocol the device complies with
uint32_t max_ibi_pending_read_size; ///< indicates the max size of data this device is allowed to send as pending read for an IBI
};
/**
* @brief Structure representing data to be sent to/from a USB device.
*/
struct target_device_data {
uint8_t target_interrupt_request; ///< indicates if the I3C controller accepts interrupts from this target device
uint8_t controller_role_request; ///< indicates if the I3C controller accepts controller role requests from this target device
uint8_t ibi_timestamp; ///< enables or disables time-stamping of IBIs from the target device
uint8_t asa; ///< configures wether this device supports assignment from static address
uint8_t daa; ///< configures wether this device should use dynamic address assignment with ENTDAA
uint8_t change_flags; ///< indicate if there is a change in R/W fields
uint8_t target_type; ///< indicates if the target device is an I2C or I3C device
uint8_t pending_read_capability; ///< indicates if the target device supports IBI pending read capability
uint8_t valid_pid; ///< indicates if the Target device has a valid 48-bit PID (in PID_HI + PID_LO)
uint32_t max_ibi_payload_size; ///< Max IBI payload to send to I3C Controller
uint8_t bus_characteristic_register; ///< Bus Characteristic Register
uint8_t device_characteristic_register; ///< Device Characteristic Register
};
/**
* @brief A struct that represents an I3C device.
*/
struct target_device {
uint8_t target_address; ///< address assigned to the target device (can be changed in I3C devices)
uint16_t pid_lo; ///< device’s provisional ID low
uint32_t pid_hi; ///< device’s provisional ID high
struct target_device_capability device_capability;
struct target_device_data device_data;
};
/**
* @brief Structs that holds the tracking data of in progress address change requests.
*/
struct address_change_request {
uint16_t request_id; ///< The ID of the request: current address (bits 15:8) + new address (bits 7:0)
on_address_change_fn on_address_change_cb; ///< The callback function to be called when the address change request is processed
void *user_data; ///< User data to be shared with the on_address_change_cb callback function
};
/**
* @brief Structs that holds data related to the known I3C devices in the bus.
*/
struct target_device_table {
struct usb_device *usb_dev; ///< USB session
struct list *target_devices; ///< The list of target devices in the I3C bus
struct list *address_change_tracker; ///< Tracks the submitted address change requests until they are processed
pthread_mutex_t *mutex; ///< Safe thread for table
int enable_events; ///< Enable events
on_insert_fn on_insert_cb; ///< callback function for on_insert event
void *user_data; ///< data to share with on_insert event
};
/* Target device table */
struct target_device_table *table_init(struct usb_device *usb_dev);
void table_destroy(struct target_device_table **table);
void target_device_table_notification_handle(struct notification *notification, void *user_data);
void table_enable_events(struct target_device_table *table);
void table_on_insert_device(struct target_device_table *table, on_insert_fn callback, void *user_data);
int table_insert_device(struct target_device_table *table, struct target_device *device);
int table_address_list(struct target_device_table *table, uint8_t **list);
int table_change_device_address(struct target_device_table *table, uint8_t addr_src, uint8_t addr_dest);
struct target_device *table_remove_device(struct target_device_table *table, uint8_t address);
struct target_device *table_get_device(struct target_device_table *table, uint8_t address);
struct list *table_get_devices(struct target_device_table *table);
struct target_device *table_get_device_by_pid(struct target_device_table *table, uint64_t pid);
int table_fill_from_capability_buffer(struct target_device_table *table, uint8_t *buffer, const uint16_t buffer_size);
int table_fill_from_device_table_buffer(struct target_device_table *table, uint8_t *buffer, const uint16_t buffer_size);
int table_create_device_table_buffer(struct target_device_table *table, uint8_t **buffer);
int table_create_set_target_config_buffer(struct target_device_table *table, uint8_t config, uint32_t max_ibi_payload_size, uint8_t **buffer);
int table_update_target_device_info(struct target_device_table *table);
void table_free_address_change_request_tracker(struct list **tracker);
int table_identify_devices(struct target_device_table *table, int *support_static, int *support_dynamic);
/* Target device */
struct device_event_handler;
struct target_device *device_create_from_capability_entry(struct capability_device_entry *entry);
void device_update_from_capability_entry(struct target_device *device, struct capability_device_entry *entry);
struct target_device *device_create_from_device_table_entry(struct target_device_table_entry *entry);
void device_update_from_device_table_entry(struct target_device *device, struct target_device_table_entry *entry);
int device_create_set_configuration_buffer(uint8_t address, uint8_t config, uint32_t max_ibi_payload_size, uint8_t **buffer);
uint16_t device_create_address_change_buffer(struct target_device *device, uint8_t address, uint8_t new_address, uint8_t **buffer);
int device_send_request_to_i3c_controller(struct usbi3c_device *usbi3c_dev, uint8_t target_address, uint8_t read_n_write);
struct device_event_handler *device_event_handler_init(void);
void device_destroy_event_handler(struct device_event_handler **device_event_handler);
void device_handle_event(struct notification *notification, void *user_data);
void device_add_event_callback(struct device_event_handler *device_event_handler, on_controller_event_fn on_controller_event_cb, void *data);
#endif /* end of include guard: __TARGET_DEVICE_TABLE_I_H__ */