Skip to content

Commit 16b61c3

Browse files
authored
Merge pull request #5 from houlz0507/v5
V5 add xrt_bus_type
2 parents b18124b + b8a1aff commit 16b61c3

34 files changed

Lines changed: 1712 additions & 1666 deletions

Documentation/fpga/xrt.rst

Lines changed: 164 additions & 139 deletions
Large diffs are not rendered by default.

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6916,7 +6916,7 @@ M: Lizhi Hou <lizhi.hou@xilinx.com>
69166916
R: Max Zhen <max.zhen@xilinx.com>
69176917
R: Sonal Santan <sonal.santan@xilinx.com>
69186918
L: linux-fpga@vger.kernel.org
6919-
S: Maintained
6919+
S: Supported
69206920
W: https://github.com/Xilinx/XRT
69216921
F: Documentation/fpga/xrt.rst
69226922
F: drivers/fpga/xrt/

drivers/fpga/xrt/include/metadata.h

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <linux/vmalloc.h>
1414
#include <linux/uuid.h>
1515

16-
#define XRT_MD_INVALID_LENGTH (~0UL)
16+
#define XRT_MD_INVALID_LENGTH (~0U)
1717

1818
/* metadata properties */
1919
#define XRT_MD_PROP_BAR_IDX "pcie_bar_mapping"
@@ -38,6 +38,7 @@
3838
* AF: AXI Firewall
3939
* CMC: Card Management Controller
4040
* ERT: Embedded Runtime
41+
* EP: End Point
4142
* PLP: Provider Reconfigurable Partition
4243
* ULP: User Reconfigurable Partition
4344
*/
@@ -47,11 +48,11 @@
4748
#define XRT_MD_NODE_AF_CTRL_DEBUG "ep_firewall_ctrl_debug_00"
4849
#define XRT_MD_NODE_AF_CTRL_MGMT "ep_firewall_ctrl_mgmt_00"
4950
#define XRT_MD_NODE_AF_CTRL_USER "ep_firewall_ctrl_user_00"
50-
#define XRT_MD_NODE_AF_DATA_C2H "ep_firewall_data_c2h_00"
51-
#define XRT_MD_NODE_AF_DATA_H2C "ep_firewall_data_h2c_00"
51+
#define XRT_MD_NODE_AF_DATA_C2H "ep_firewall_data_c2h_00" /* c2h: card to host */
52+
#define XRT_MD_NODE_AF_DATA_H2C "ep_firewall_data_h2c_00" /* h2c: host to card */
5253
#define XRT_MD_NODE_AF_DATA_M2M "ep_firewall_data_m2m_00"
5354
#define XRT_MD_NODE_AF_DATA_P2P "ep_firewall_data_p2p_00"
54-
#define XRT_MD_NODE_CLKFREQ_HBM "ep_freq_cnt_aclk_hbm_00"
55+
#define XRT_MD_NODE_CLKFREQ_HBM "ep_freq_cnt_aclk_hbm_00" /* hbm: High Bandwidth Memory */
5556
#define XRT_MD_NODE_CLKFREQ_K1 "ep_freq_cnt_aclk_kernel_00"
5657
#define XRT_MD_NODE_CLKFREQ_K2 "ep_freq_cnt_aclk_kernel_01"
5758
#define XRT_MD_NODE_CLK_KERNEL1 "ep_aclk_kernel_00"
@@ -95,9 +96,9 @@
9596
#define XRT_MD_NODE_XVC_PRI "ep_debug_bscan_mgmt_00"
9697
#define XRT_MD_NODE_UCS_CONTROL_STATUS "ep_ucs_control_status_00"
9798

98-
/* endpoint regmaps */
99-
#define XRT_MD_REGMAP_DDR_SRSR "drv_ddr_srsr"
100-
#define XRT_MD_REGMAP_CLKFREQ "freq_cnt"
99+
/* endpoint compatible string */
100+
#define XRT_MD_COMPAT_DDR_SRSR "drv_ddr_srsr"
101+
#define XRT_MD_COMPAT_CLKFREQ "freq_cnt"
101102

102103
/* driver defined endpoints */
103104
#define XRT_MD_NODE_BLP_ROM "drv_ep_blp_rom_00"
@@ -123,11 +124,11 @@
123124

124125
struct xrt_md_endpoint {
125126
const char *ep_name;
126-
u32 bar;
127+
u32 bar_index;
127128
u64 bar_off;
128-
ulong size;
129-
char *regmap;
130-
char *regmap_ver;
129+
u64 size;
130+
char *compat;
131+
char *compat_ver;
131132
};
132133

133134
/* Note: res_id is defined by leaf driver and must start with 0. */
@@ -162,29 +163,29 @@ xrt_md_res_id2name(const struct xrt_iores_map *res_map, int entry_num, int id)
162163
return NULL;
163164
}
164165

165-
unsigned long xrt_md_size(struct device *dev, const char *blob);
166+
u32 xrt_md_size(struct device *dev, const char *blob);
166167
int xrt_md_create(struct device *dev, char **blob);
167168
char *xrt_md_dup(struct device *dev, const char *blob);
168169
int xrt_md_add_endpoint(struct device *dev, char *blob,
169170
struct xrt_md_endpoint *ep);
170171
int xrt_md_del_endpoint(struct device *dev, char *blob, const char *ep_name,
171-
const char *regmap_name);
172+
const char *compat);
172173
int xrt_md_get_prop(struct device *dev, const char *blob, const char *ep_name,
173-
const char *regmap_name, const char *prop,
174+
const char *compat, const char *prop,
174175
const void **val, int *size);
175176
int xrt_md_set_prop(struct device *dev, char *blob, const char *ep_name,
176-
const char *regmap_name, const char *prop,
177+
const char *compat, const char *prop,
177178
const void *val, int size);
178179
int xrt_md_copy_endpoint(struct device *dev, char *blob, const char *src_blob,
179-
const char *ep_name, const char *regmap_name,
180+
const char *ep_name, const char *compat,
180181
const char *new_ep_name);
181182
int xrt_md_get_next_endpoint(struct device *dev, const char *blob,
182-
const char *ep_name, const char *regmap_name,
183-
char **next_ep, char **next_regmap);
183+
const char *ep_name, const char *compat,
184+
char **next_ep, char **next_compat);
184185
int xrt_md_get_compatible_endpoint(struct device *dev, const char *blob,
185-
const char *regmap_name, const char **ep_name);
186+
const char *compat, const char **ep_name);
186187
int xrt_md_find_endpoint(struct device *dev, const char *blob,
187-
const char *ep_name, const char *regmap_name,
188+
const char *ep_name, const char *compat,
188189
const char **epname);
189190
int xrt_md_pack(struct device *dev, char *blob);
190191
int xrt_md_get_interface_uuids(struct device *dev, const char *blob,
@@ -214,7 +215,9 @@ static inline int xrt_md_trans_str2uuid(struct device *dev, const char *uuidstr,
214215
char tmp[3] = { 0 };
215216
int i, ret;
216217

217-
BUILD_BUG_ON(UUID_SIZE != 16);
218+
if (strlen(uuidstr) != UUID_SIZE * 2)
219+
return -EINVAL;
220+
218221
str = uuidstr + strlen(uuidstr) - 2;
219222

220223
for (i = 0; i < sizeof(*p_uuid) && str >= uuidstr; i++) {

drivers/fpga/xrt/include/subdev_id.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@
1515
* of a specific instance of a subdev driver.
1616
*/
1717
enum xrt_subdev_id {
18-
XRT_SUBDEV_GRP = 0,
19-
XRT_SUBDEV_VSEC = 1,
20-
XRT_SUBDEV_VSEC_GOLDEN = 2,
21-
XRT_SUBDEV_DEVCTL = 3,
22-
XRT_SUBDEV_AXIGATE = 4,
23-
XRT_SUBDEV_ICAP = 5,
24-
XRT_SUBDEV_TEST = 6,
25-
XRT_SUBDEV_MGMT_MAIN = 7,
26-
XRT_SUBDEV_QSPI = 8,
27-
XRT_SUBDEV_MAILBOX = 9,
28-
XRT_SUBDEV_CMC = 10,
29-
XRT_SUBDEV_CALIB = 11,
30-
XRT_SUBDEV_CLKFREQ = 12,
31-
XRT_SUBDEV_CLOCK = 13,
32-
XRT_SUBDEV_SRSR = 14,
33-
XRT_SUBDEV_UCS = 15,
34-
XRT_SUBDEV_NUM = 16, /* Total number of subdevs. */
18+
XRT_SUBDEV_INVALID = 0,
19+
XRT_SUBDEV_GRP,
20+
XRT_SUBDEV_VSEC,
21+
XRT_SUBDEV_VSEC_GOLDEN,
22+
XRT_SUBDEV_DEVCTL,
23+
XRT_SUBDEV_AXIGATE,
24+
XRT_SUBDEV_ICAP,
25+
XRT_SUBDEV_TEST,
26+
XRT_SUBDEV_MGMT_MAIN,
27+
XRT_SUBDEV_QSPI,
28+
XRT_SUBDEV_MAILBOX,
29+
XRT_SUBDEV_CMC,
30+
XRT_SUBDEV_CALIB,
31+
XRT_SUBDEV_CLKFREQ,
32+
XRT_SUBDEV_CLOCK,
33+
XRT_SUBDEV_SRSR,
34+
XRT_SUBDEV_UCS,
35+
XRT_SUBDEV_NUM, /* Total number of subdevs. */
3536
XRT_ROOT = -1, /* Special ID for root driver. */
3637
};
3738

drivers/fpga/xrt/include/xclbin-helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#define XCLBIN_VERSION2 "xclbin2"
1818
#define XCLBIN_HWICAP_BITFILE_BUF_SZ 1024
19-
#define XCLBIN_MAX_SIZE (1024 * 1024 * 1024) /* Assuming xclbin <= 1G, always */
19+
#define XCLBIN_MAX_SZ_1G (1024 * 1024 * 1024) /* Assuming xclbin <= 1G, always */
2020

2121
enum axlf_section_kind;
2222
struct axlf;

drivers/fpga/xrt/include/xdevice.h

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (C) 2020-2021 Xilinx, Inc.
4+
*
5+
* Authors:
6+
* Lizhi Hou <lizhi.hou@xilinx.com>
7+
*/
8+
9+
#ifndef _XRT_DEVICE_H_
10+
#define _XRT_DEVICE_H_
11+
12+
#include <linux/fs.h>
13+
#include <linux/cdev.h>
14+
15+
#define XRT_MAX_DEVICE_NODES 128
16+
#define XRT_INVALID_DEVICE_INST (XRT_MAX_DEVICE_NODES + 1)
17+
18+
enum {
19+
XRT_DEVICE_STATE_NONE = 0,
20+
XRT_DEVICE_STATE_ADDED
21+
};
22+
23+
/*
24+
* struct xrt_device - represent an xrt device on xrt bus
25+
*
26+
* dev: generic device interface.
27+
* id: id of the xrt device.
28+
*/
29+
struct xrt_device {
30+
struct device dev;
31+
u32 subdev_id;
32+
const char *name;
33+
u32 instance;
34+
u32 state;
35+
u32 num_resources;
36+
struct resource *resource;
37+
void *sdev_data;
38+
};
39+
40+
/*
41+
* If populated by xrt device driver, infra will handle the mechanics of
42+
* char device (un)registration.
43+
*/
44+
enum xrt_dev_file_mode {
45+
/* Infra create cdev, default file name */
46+
XRT_DEV_FILE_DEFAULT = 0,
47+
/* Infra create cdev, need to encode inst num in file name */
48+
XRT_DEV_FILE_MULTI_INST,
49+
/* No auto creation of cdev by infra, leaf handles it by itself */
50+
XRT_DEV_FILE_NO_AUTO,
51+
};
52+
53+
struct xrt_dev_file_ops {
54+
const struct file_operations xsf_ops;
55+
dev_t xsf_dev_t;
56+
const char *xsf_dev_name;
57+
enum xrt_dev_file_mode xsf_mode;
58+
};
59+
60+
/*
61+
* this struct define the endpoints belong to the same xrt device
62+
*/
63+
struct xrt_dev_ep_names {
64+
const char *ep_name;
65+
const char *compat;
66+
};
67+
68+
struct xrt_dev_endpoints {
69+
struct xrt_dev_ep_names *xse_names;
70+
/* minimum number of endpoints to support the subdevice */
71+
u32 xse_min_ep;
72+
};
73+
74+
/*
75+
* struct xrt_driver - represent a xrt device driver
76+
*
77+
* drv: driver model structure.
78+
* id_table: pointer to table of device IDs the driver is interested in.
79+
* { } member terminated.
80+
* probe: mandatory callback for device binding.
81+
* remove: callback for device unbinding.
82+
*/
83+
struct xrt_driver {
84+
struct device_driver driver;
85+
u32 subdev_id;
86+
struct xrt_dev_file_ops file_ops;
87+
struct xrt_dev_endpoints *endpoints;
88+
89+
/*
90+
* Subdev driver callbacks populated by subdev driver.
91+
*/
92+
int (*probe)(struct xrt_device *xrt_dev);
93+
void (*remove)(struct xrt_device *xrt_dev);
94+
/*
95+
* If leaf_call is defined, these are called by other leaf drivers.
96+
* Note that root driver may call into leaf_call of a group driver.
97+
*/
98+
int (*leaf_call)(struct xrt_device *xrt_dev, u32 cmd, void *arg);
99+
};
100+
101+
#define to_xrt_dev(d) container_of(d, struct xrt_device, dev)
102+
#define to_xrt_drv(d) container_of(d, struct xrt_driver, driver)
103+
104+
static inline void *xrt_get_drvdata(const struct xrt_device *xdev)
105+
{
106+
return dev_get_drvdata(&xdev->dev);
107+
}
108+
109+
static inline void xrt_set_drvdata(struct xrt_device *xdev, void *data)
110+
{
111+
dev_set_drvdata(&xdev->dev, data);
112+
}
113+
114+
static inline void *xrt_get_xdev_data(struct device *dev)
115+
{
116+
struct xrt_device *xdev = to_xrt_dev(dev);
117+
118+
return xdev->sdev_data;
119+
}
120+
121+
struct xrt_device *
122+
xrt_device_register(struct device *parent, u32 id,
123+
struct resource *res, u32 res_num,
124+
void *pdata, size_t data_sz);
125+
void xrt_device_unregister(struct xrt_device *xdev);
126+
int xrt_register_driver(struct xrt_driver *drv);
127+
void xrt_unregister_driver(struct xrt_driver *drv);
128+
void *xrt_get_xdev_data(struct device *dev);
129+
struct resource *xrt_get_resource(struct xrt_device *xdev, u32 type, u32 num);
130+
131+
#endif /* _XRT_DEVICE_H_ */

0 commit comments

Comments
 (0)