dfl.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Driver Header File for FPGA Device Feature List (DFL) Support
  4. *
  5. * Copyright (C) 2017-2018 Intel Corporation, Inc.
  6. *
  7. * Authors:
  8. * Kang Luwei <luwei.kang@intel.com>
  9. * Zhang Yi <yi.z.zhang@intel.com>
  10. * Wu Hao <hao.wu@intel.com>
  11. * Xiao Guangrong <guangrong.xiao@linux.intel.com>
  12. */
  13. #ifndef __FPGA_DFL_H
  14. #define __FPGA_DFL_H
  15. #include <linux/bitfield.h>
  16. #include <linux/cdev.h>
  17. #include <linux/delay.h>
  18. #include <linux/dfl.h>
  19. #include <linux/eventfd.h>
  20. #include <linux/fs.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/iopoll.h>
  23. #include <linux/io-64-nonatomic-lo-hi.h>
  24. #include <linux/mod_devicetable.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/slab.h>
  27. #include <linux/uuid.h>
  28. #include <linux/fpga/fpga-region.h>
  29. /* maximum supported number of ports */
  30. #define MAX_DFL_FPGA_PORT_NUM 4
  31. /* plus one for fme device */
  32. #define MAX_DFL_FEATURE_DEV_NUM (MAX_DFL_FPGA_PORT_NUM + 1)
  33. /* Reserved 0xfe for Header Group Register and 0xff for AFU */
  34. #define FEATURE_ID_FIU_HEADER 0xfe
  35. #define FEATURE_ID_AFU 0xff
  36. #define FME_FEATURE_ID_HEADER FEATURE_ID_FIU_HEADER
  37. #define FME_FEATURE_ID_THERMAL_MGMT 0x1
  38. #define FME_FEATURE_ID_POWER_MGMT 0x2
  39. #define FME_FEATURE_ID_GLOBAL_IPERF 0x3
  40. #define FME_FEATURE_ID_GLOBAL_ERR 0x4
  41. #define FME_FEATURE_ID_PR_MGMT 0x5
  42. #define FME_FEATURE_ID_HSSI 0x6
  43. #define FME_FEATURE_ID_GLOBAL_DPERF 0x7
  44. #define PORT_FEATURE_ID_HEADER FEATURE_ID_FIU_HEADER
  45. #define PORT_FEATURE_ID_AFU FEATURE_ID_AFU
  46. #define PORT_FEATURE_ID_ERROR 0x10
  47. #define PORT_FEATURE_ID_UMSG 0x11
  48. #define PORT_FEATURE_ID_UINT 0x12
  49. #define PORT_FEATURE_ID_STP 0x13
  50. /*
  51. * Device Feature Header Register Set
  52. *
  53. * For FIUs, they all have DFH + GUID + NEXT_AFU as common header registers.
  54. * For AFUs, they have DFH + GUID as common header registers.
  55. * For private features, they only have DFH register as common header.
  56. */
  57. #define DFH 0x0
  58. #define GUID_L 0x8
  59. #define GUID_H 0x10
  60. #define NEXT_AFU 0x18
  61. #define DFH_SIZE 0x8
  62. /* Device Feature Header Register Bitfield */
  63. #define DFH_ID GENMASK_ULL(11, 0) /* Feature ID */
  64. #define DFH_ID_FIU_FME 0
  65. #define DFH_ID_FIU_PORT 1
  66. #define DFH_REVISION GENMASK_ULL(15, 12) /* Feature revision */
  67. #define DFH_NEXT_HDR_OFST GENMASK_ULL(39, 16) /* Offset to next DFH */
  68. #define DFH_EOL BIT_ULL(40) /* End of list */
  69. #define DFH_VERSION GENMASK_ULL(59, 52) /* DFH version */
  70. #define DFH_TYPE GENMASK_ULL(63, 60) /* Feature type */
  71. #define DFH_TYPE_AFU 1
  72. #define DFH_TYPE_PRIVATE 3
  73. #define DFH_TYPE_FIU 4
  74. /*
  75. * DFHv1 Register Offset definitions
  76. * In DHFv1, DFH + GUID + CSR_START + CSR_SIZE_GROUP + PARAM_HDR + PARAM_DATA
  77. * as common header registers
  78. */
  79. #define DFHv1_CSR_ADDR 0x18 /* CSR Register start address */
  80. #define DFHv1_CSR_SIZE_GRP 0x20 /* Size of Reg Block and Group/tag */
  81. #define DFHv1_PARAM_HDR 0x28 /* Optional First Param header */
  82. /*
  83. * CSR Rel Bit, 1'b0 = relative (offset from feature DFH start),
  84. * 1'b1 = absolute (ARM or other non-PCIe use)
  85. */
  86. #define DFHv1_CSR_ADDR_REL BIT_ULL(0)
  87. /* CSR Header Register Bit Definitions */
  88. #define DFHv1_CSR_ADDR_MASK GENMASK_ULL(63, 1) /* 63:1 of CSR address */
  89. /* CSR SIZE Goup Register Bit Definitions */
  90. #define DFHv1_CSR_SIZE_GRP_INSTANCE_ID GENMASK_ULL(15, 0) /* Enumeration instantiated IP */
  91. #define DFHv1_CSR_SIZE_GRP_GROUPING_ID GENMASK_ULL(30, 16) /* Group Features/interfaces */
  92. #define DFHv1_CSR_SIZE_GRP_HAS_PARAMS BIT_ULL(31) /* Presence of Parameters */
  93. #define DFHv1_CSR_SIZE_GRP_SIZE GENMASK_ULL(63, 32) /* Size of CSR Block in bytes */
  94. /* PARAM Header Register Bit Definitions */
  95. #define DFHv1_PARAM_HDR_ID GENMASK_ULL(15, 0) /* Id of this Param */
  96. #define DFHv1_PARAM_HDR_VER GENMASK_ULL(31, 16) /* Version Param */
  97. #define DFHv1_PARAM_HDR_NEXT_OFFSET GENMASK_ULL(63, 35) /* Offset of next Param */
  98. #define DFHv1_PARAM_HDR_NEXT_EOP BIT_ULL(32)
  99. #define DFHv1_PARAM_DATA 0x08 /* Offset of Param data from Param header */
  100. #define DFHv1_PARAM_ID_MSI_X 0x1
  101. #define DFHv1_PARAM_MSI_X_NUMV GENMASK_ULL(63, 32)
  102. #define DFHv1_PARAM_MSI_X_STARTV GENMASK_ULL(31, 0)
  103. /* Next AFU Register Bitfield */
  104. #define NEXT_AFU_NEXT_DFH_OFST GENMASK_ULL(23, 0) /* Offset to next AFU */
  105. /* FME Header Register Set */
  106. #define FME_HDR_DFH DFH
  107. #define FME_HDR_GUID_L GUID_L
  108. #define FME_HDR_GUID_H GUID_H
  109. #define FME_HDR_NEXT_AFU NEXT_AFU
  110. #define FME_HDR_CAP 0x30
  111. #define FME_HDR_PORT_OFST(n) (0x38 + ((n) * 0x8))
  112. #define FME_PORT_OFST_BAR_SKIP 7
  113. #define FME_HDR_BITSTREAM_ID 0x60
  114. #define FME_HDR_BITSTREAM_MD 0x68
  115. /* FME Fab Capability Register Bitfield */
  116. #define FME_CAP_FABRIC_VERID GENMASK_ULL(7, 0) /* Fabric version ID */
  117. #define FME_CAP_SOCKET_ID BIT_ULL(8) /* Socket ID */
  118. #define FME_CAP_PCIE0_LINK_AVL BIT_ULL(12) /* PCIE0 Link */
  119. #define FME_CAP_PCIE1_LINK_AVL BIT_ULL(13) /* PCIE1 Link */
  120. #define FME_CAP_COHR_LINK_AVL BIT_ULL(14) /* Coherent Link */
  121. #define FME_CAP_IOMMU_AVL BIT_ULL(16) /* IOMMU available */
  122. #define FME_CAP_NUM_PORTS GENMASK_ULL(19, 17) /* Number of ports */
  123. #define FME_CAP_ADDR_WIDTH GENMASK_ULL(29, 24) /* Address bus width */
  124. #define FME_CAP_CACHE_SIZE GENMASK_ULL(43, 32) /* cache size in KB */
  125. #define FME_CAP_CACHE_ASSOC GENMASK_ULL(47, 44) /* Associativity */
  126. /* FME Port Offset Register Bitfield */
  127. /* Offset to port device feature header */
  128. #define FME_PORT_OFST_DFH_OFST GENMASK_ULL(23, 0)
  129. /* PCI Bar ID for this port */
  130. #define FME_PORT_OFST_BAR_ID GENMASK_ULL(34, 32)
  131. /* AFU MMIO access permission. 1 - VF, 0 - PF. */
  132. #define FME_PORT_OFST_ACC_CTRL BIT_ULL(55)
  133. #define FME_PORT_OFST_ACC_PF 0
  134. #define FME_PORT_OFST_ACC_VF 1
  135. #define FME_PORT_OFST_IMP BIT_ULL(60)
  136. /* FME Error Capability Register */
  137. #define FME_ERROR_CAP 0x70
  138. /* FME Error Capability Register Bitfield */
  139. #define FME_ERROR_CAP_SUPP_INT BIT_ULL(0) /* Interrupt Support */
  140. #define FME_ERROR_CAP_INT_VECT GENMASK_ULL(12, 1) /* Interrupt vector */
  141. /* PORT Header Register Set */
  142. #define PORT_HDR_DFH DFH
  143. #define PORT_HDR_GUID_L GUID_L
  144. #define PORT_HDR_GUID_H GUID_H
  145. #define PORT_HDR_NEXT_AFU NEXT_AFU
  146. #define PORT_HDR_CAP 0x30
  147. #define PORT_HDR_CTRL 0x38
  148. #define PORT_HDR_STS 0x40
  149. #define PORT_HDR_USRCLK_CMD0 0x50
  150. #define PORT_HDR_USRCLK_CMD1 0x58
  151. #define PORT_HDR_USRCLK_STS0 0x60
  152. #define PORT_HDR_USRCLK_STS1 0x68
  153. /* Port Capability Register Bitfield */
  154. #define PORT_CAP_PORT_NUM GENMASK_ULL(1, 0) /* ID of this port */
  155. #define PORT_CAP_MMIO_SIZE GENMASK_ULL(23, 8) /* MMIO size in KB */
  156. #define PORT_CAP_SUPP_INT_NUM GENMASK_ULL(35, 32) /* Interrupts num */
  157. /* Port Control Register Bitfield */
  158. #define PORT_CTRL_SFTRST BIT_ULL(0) /* Port soft reset */
  159. /* Latency tolerance reporting. '1' >= 40us, '0' < 40us.*/
  160. #define PORT_CTRL_LATENCY BIT_ULL(2)
  161. #define PORT_CTRL_SFTRST_ACK BIT_ULL(4) /* HW ack for reset */
  162. /* Port Status Register Bitfield */
  163. #define PORT_STS_AP2_EVT BIT_ULL(13) /* AP2 event detected */
  164. #define PORT_STS_AP1_EVT BIT_ULL(12) /* AP1 event detected */
  165. #define PORT_STS_PWR_STATE GENMASK_ULL(11, 8) /* AFU power states */
  166. #define PORT_STS_PWR_STATE_NORM 0
  167. #define PORT_STS_PWR_STATE_AP1 1 /* 50% throttling */
  168. #define PORT_STS_PWR_STATE_AP2 2 /* 90% throttling */
  169. #define PORT_STS_PWR_STATE_AP6 6 /* 100% throttling */
  170. /* Port Error Capability Register */
  171. #define PORT_ERROR_CAP 0x38
  172. /* Port Error Capability Register Bitfield */
  173. #define PORT_ERROR_CAP_SUPP_INT BIT_ULL(0) /* Interrupt Support */
  174. #define PORT_ERROR_CAP_INT_VECT GENMASK_ULL(12, 1) /* Interrupt vector */
  175. /* Port Uint Capability Register */
  176. #define PORT_UINT_CAP 0x8
  177. /* Port Uint Capability Register Bitfield */
  178. #define PORT_UINT_CAP_INT_NUM GENMASK_ULL(11, 0) /* Interrupts num */
  179. #define PORT_UINT_CAP_FST_VECT GENMASK_ULL(23, 12) /* First Vector */
  180. struct dfl_feature_dev_data;
  181. /**
  182. * struct dfl_fpga_port_ops - port ops
  183. *
  184. * @name: name of this port ops, to match with port platform device.
  185. * @owner: pointer to the module which owns this port ops.
  186. * @node: node to link port ops to global list.
  187. * @get_id: get port id from hardware.
  188. * @enable_set: enable/disable the port.
  189. */
  190. struct dfl_fpga_port_ops {
  191. const char *name;
  192. struct module *owner;
  193. struct list_head node;
  194. int (*get_id)(struct dfl_feature_dev_data *fdata);
  195. int (*enable_set)(struct dfl_feature_dev_data *fdata, bool enable);
  196. };
  197. void dfl_fpga_port_ops_add(struct dfl_fpga_port_ops *ops);
  198. void dfl_fpga_port_ops_del(struct dfl_fpga_port_ops *ops);
  199. struct dfl_fpga_port_ops *dfl_fpga_port_ops_get(struct dfl_feature_dev_data *fdata);
  200. void dfl_fpga_port_ops_put(struct dfl_fpga_port_ops *ops);
  201. int dfl_fpga_check_port_id(struct dfl_feature_dev_data *fdata, void *pport_id);
  202. /**
  203. * struct dfl_feature_id - dfl private feature id
  204. *
  205. * @id: unique dfl private feature id.
  206. */
  207. struct dfl_feature_id {
  208. u16 id;
  209. };
  210. /**
  211. * struct dfl_feature_driver - dfl private feature driver
  212. *
  213. * @id_table: id_table for dfl private features supported by this driver.
  214. * @ops: ops of this dfl private feature driver.
  215. */
  216. struct dfl_feature_driver {
  217. const struct dfl_feature_id *id_table;
  218. const struct dfl_feature_ops *ops;
  219. };
  220. /**
  221. * struct dfl_feature_irq_ctx - dfl private feature interrupt context
  222. *
  223. * @irq: Linux IRQ number of this interrupt.
  224. * @trigger: eventfd context to signal when interrupt happens.
  225. * @name: irq name needed when requesting irq.
  226. */
  227. struct dfl_feature_irq_ctx {
  228. int irq;
  229. struct eventfd_ctx *trigger;
  230. char *name;
  231. };
  232. /**
  233. * struct dfl_feature - sub feature of the feature devices
  234. *
  235. * @dev: ptr to pdev of the feature device which has the sub feature.
  236. * @id: sub feature id.
  237. * @revision: revision of this sub feature.
  238. * @resource_index: each sub feature has one mmio resource for its registers.
  239. * this index is used to find its mmio resource from the
  240. * feature dev (platform device)'s resources.
  241. * @ioaddr: mapped mmio resource address.
  242. * @irq_ctx: interrupt context list.
  243. * @nr_irqs: number of interrupt contexts.
  244. * @ops: ops of this sub feature.
  245. * @ddev: ptr to the dfl device of this sub feature.
  246. * @priv: priv data of this feature.
  247. * @dfh_version: version of the DFH
  248. * @param_size: size of dfh parameters
  249. * @params: point to memory copy of dfh parameters
  250. */
  251. struct dfl_feature {
  252. struct platform_device *dev;
  253. u16 id;
  254. u8 revision;
  255. int resource_index;
  256. void __iomem *ioaddr;
  257. struct dfl_feature_irq_ctx *irq_ctx;
  258. unsigned int nr_irqs;
  259. const struct dfl_feature_ops *ops;
  260. struct dfl_device *ddev;
  261. void *priv;
  262. u8 dfh_version;
  263. unsigned int param_size;
  264. void *params;
  265. };
  266. #define FEATURE_DEV_ID_UNUSED (-1)
  267. /**
  268. * struct dfl_feature_dev_data - dfl enumeration data for dfl feature dev.
  269. *
  270. * @node: node to link the data structure to container device's port_dev_list.
  271. * @lock: mutex to protect feature dev data.
  272. * @dev: ptr to the feature's platform device linked with this structure.
  273. * @type: type of DFL FIU for the feature dev. See enum dfl_id_type.
  274. * @pdev_id: platform device id for the feature dev.
  275. * @pdev_name: platform device name for the feature dev.
  276. * @dfl_cdev: ptr to container device.
  277. * @id: id used for the feature device.
  278. * @disable_count: count for port disable.
  279. * @excl_open: set on feature device exclusive open.
  280. * @open_count: count for feature device open.
  281. * @num: number for sub features.
  282. * @private: ptr to feature dev private data.
  283. * @features: sub features for the feature dev.
  284. * @resource_num: number of resources for the feature dev.
  285. * @resources: resources for the feature dev.
  286. */
  287. struct dfl_feature_dev_data {
  288. struct list_head node;
  289. struct mutex lock;
  290. struct platform_device *dev;
  291. enum dfl_id_type type;
  292. int pdev_id;
  293. const char *pdev_name;
  294. struct dfl_fpga_cdev *dfl_cdev;
  295. int id;
  296. unsigned int disable_count;
  297. bool excl_open;
  298. int open_count;
  299. void *private;
  300. int num;
  301. struct dfl_feature *features;
  302. int resource_num;
  303. struct resource *resources;
  304. };
  305. /**
  306. * struct dfl_feature_platform_data - platform data for feature devices
  307. *
  308. * @cdev: cdev of feature dev.
  309. * @fdata: dfl enumeration data for the dfl feature device.
  310. */
  311. struct dfl_feature_platform_data {
  312. struct cdev cdev;
  313. struct dfl_feature_dev_data *fdata;
  314. };
  315. static inline
  316. int dfl_feature_dev_use_begin(struct dfl_feature_dev_data *fdata,
  317. bool excl)
  318. {
  319. if (fdata->excl_open)
  320. return -EBUSY;
  321. if (excl) {
  322. if (fdata->open_count)
  323. return -EBUSY;
  324. fdata->excl_open = true;
  325. }
  326. fdata->open_count++;
  327. return 0;
  328. }
  329. static inline
  330. void dfl_feature_dev_use_end(struct dfl_feature_dev_data *fdata)
  331. {
  332. fdata->excl_open = false;
  333. if (WARN_ON(fdata->open_count <= 0))
  334. return;
  335. fdata->open_count--;
  336. }
  337. static inline
  338. int dfl_feature_dev_use_count(struct dfl_feature_dev_data *fdata)
  339. {
  340. return fdata->open_count;
  341. }
  342. static inline
  343. void dfl_fpga_fdata_set_private(struct dfl_feature_dev_data *fdata,
  344. void *private)
  345. {
  346. fdata->private = private;
  347. }
  348. static inline
  349. void *dfl_fpga_fdata_get_private(struct dfl_feature_dev_data *fdata)
  350. {
  351. return fdata->private;
  352. }
  353. struct dfl_feature_ops {
  354. int (*init)(struct platform_device *pdev, struct dfl_feature *feature);
  355. void (*uinit)(struct platform_device *pdev,
  356. struct dfl_feature *feature);
  357. long (*ioctl)(struct platform_device *pdev, struct dfl_feature *feature,
  358. unsigned int cmd, unsigned long arg);
  359. };
  360. #define DFL_FPGA_FEATURE_DEV_FME "dfl-fme"
  361. #define DFL_FPGA_FEATURE_DEV_PORT "dfl-port"
  362. void dfl_fpga_dev_feature_uinit(struct platform_device *pdev);
  363. int dfl_fpga_dev_feature_init(struct platform_device *pdev,
  364. struct dfl_feature_driver *feature_drvs);
  365. int dfl_fpga_dev_ops_register(struct platform_device *pdev,
  366. const struct file_operations *fops,
  367. struct module *owner);
  368. void dfl_fpga_dev_ops_unregister(struct platform_device *pdev);
  369. static inline struct dfl_feature_dev_data *
  370. dfl_fpga_inode_to_feature_dev_data(struct inode *inode)
  371. {
  372. struct dfl_feature_platform_data *pdata;
  373. pdata = container_of(inode->i_cdev, struct dfl_feature_platform_data,
  374. cdev);
  375. return pdata->fdata;
  376. }
  377. #define dfl_fpga_dev_for_each_feature(fdata, feature) \
  378. for ((feature) = (fdata)->features; \
  379. (feature) < (fdata)->features + (fdata)->num; (feature)++)
  380. static inline struct dfl_feature *
  381. dfl_get_feature_by_id(struct dfl_feature_dev_data *fdata, u16 id)
  382. {
  383. struct dfl_feature *feature;
  384. dfl_fpga_dev_for_each_feature(fdata, feature)
  385. if (feature->id == id)
  386. return feature;
  387. return NULL;
  388. }
  389. static inline void __iomem *
  390. dfl_get_feature_ioaddr_by_id(struct dfl_feature_dev_data *fdata, u16 id)
  391. {
  392. struct dfl_feature *feature = dfl_get_feature_by_id(fdata, id);
  393. if (feature && feature->ioaddr)
  394. return feature->ioaddr;
  395. WARN_ON(1);
  396. return NULL;
  397. }
  398. static inline struct dfl_feature_dev_data *
  399. to_dfl_feature_dev_data(struct device *dev)
  400. {
  401. struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
  402. return pdata->fdata;
  403. }
  404. static inline
  405. struct device *dfl_fpga_fdata_to_parent(struct dfl_feature_dev_data *fdata)
  406. {
  407. return fdata->dev->dev.parent->parent;
  408. }
  409. static inline bool dfl_feature_is_fme(void __iomem *base)
  410. {
  411. u64 v = readq(base + DFH);
  412. return (FIELD_GET(DFH_TYPE, v) == DFH_TYPE_FIU) &&
  413. (FIELD_GET(DFH_ID, v) == DFH_ID_FIU_FME);
  414. }
  415. static inline bool dfl_feature_is_port(void __iomem *base)
  416. {
  417. u64 v = readq(base + DFH);
  418. return (FIELD_GET(DFH_TYPE, v) == DFH_TYPE_FIU) &&
  419. (FIELD_GET(DFH_ID, v) == DFH_ID_FIU_PORT);
  420. }
  421. static inline u8 dfl_feature_revision(void __iomem *base)
  422. {
  423. return (u8)FIELD_GET(DFH_REVISION, readq(base + DFH));
  424. }
  425. /**
  426. * struct dfl_fpga_enum_info - DFL FPGA enumeration information
  427. *
  428. * @dev: parent device.
  429. * @dfls: list of device feature lists.
  430. * @nr_irqs: number of irqs for all feature devices.
  431. * @irq_table: Linux IRQ numbers for all irqs, indexed by hw irq numbers.
  432. */
  433. struct dfl_fpga_enum_info {
  434. struct device *dev;
  435. struct list_head dfls;
  436. unsigned int nr_irqs;
  437. int *irq_table;
  438. };
  439. /**
  440. * struct dfl_fpga_enum_dfl - DFL FPGA enumeration device feature list info
  441. *
  442. * @start: base address of this device feature list.
  443. * @len: size of this device feature list.
  444. * @node: node in list of device feature lists.
  445. */
  446. struct dfl_fpga_enum_dfl {
  447. resource_size_t start;
  448. resource_size_t len;
  449. struct list_head node;
  450. };
  451. struct dfl_fpga_enum_info *dfl_fpga_enum_info_alloc(struct device *dev);
  452. int dfl_fpga_enum_info_add_dfl(struct dfl_fpga_enum_info *info,
  453. resource_size_t start, resource_size_t len);
  454. int dfl_fpga_enum_info_add_irq(struct dfl_fpga_enum_info *info,
  455. unsigned int nr_irqs, int *irq_table);
  456. void dfl_fpga_enum_info_free(struct dfl_fpga_enum_info *info);
  457. /**
  458. * struct dfl_fpga_cdev - container device of DFL based FPGA
  459. *
  460. * @parent: parent device of this container device.
  461. * @region: base fpga region.
  462. * @fme_dev: FME feature device under this container device.
  463. * @lock: mutex lock to protect the port device list.
  464. * @port_dev_list: list of all port feature devices under this container device.
  465. * @released_port_num: released port number under this container device.
  466. */
  467. struct dfl_fpga_cdev {
  468. struct device *parent;
  469. struct fpga_region *region;
  470. struct device *fme_dev;
  471. struct mutex lock;
  472. struct list_head port_dev_list;
  473. int released_port_num;
  474. };
  475. struct dfl_fpga_cdev *
  476. dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info);
  477. void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev);
  478. struct dfl_feature_dev_data *
  479. __dfl_fpga_cdev_find_port_data(struct dfl_fpga_cdev *cdev, void *data,
  480. int (*match)(struct dfl_feature_dev_data *, void *));
  481. static inline struct dfl_feature_dev_data *
  482. dfl_fpga_cdev_find_port_data(struct dfl_fpga_cdev *cdev, void *data,
  483. int (*match)(struct dfl_feature_dev_data *, void *))
  484. {
  485. struct dfl_feature_dev_data *fdata;
  486. mutex_lock(&cdev->lock);
  487. fdata = __dfl_fpga_cdev_find_port_data(cdev, data, match);
  488. mutex_unlock(&cdev->lock);
  489. return fdata;
  490. }
  491. int dfl_fpga_cdev_release_port(struct dfl_fpga_cdev *cdev, int port_id);
  492. int dfl_fpga_cdev_assign_port(struct dfl_fpga_cdev *cdev, int port_id);
  493. void dfl_fpga_cdev_config_ports_pf(struct dfl_fpga_cdev *cdev);
  494. int dfl_fpga_cdev_config_ports_vf(struct dfl_fpga_cdev *cdev, int num_vf);
  495. int dfl_fpga_set_irq_triggers(struct dfl_feature *feature, unsigned int start,
  496. unsigned int count, int32_t *fds);
  497. long dfl_feature_ioctl_get_num_irqs(struct platform_device *pdev,
  498. struct dfl_feature *feature,
  499. unsigned long arg);
  500. long dfl_feature_ioctl_set_irq(struct platform_device *pdev,
  501. struct dfl_feature *feature,
  502. unsigned long arg);
  503. #endif /* __FPGA_DFL_H */