| 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | |
| 3 | #ifndef _FPGA_REGION_H |
| 4 | #define _FPGA_REGION_H |
| 5 | |
| 6 | #include <linux/device.h> |
| 7 | #include <linux/fpga/fpga-mgr.h> |
| 8 | #include <linux/fpga/fpga-bridge.h> |
| 9 | |
| 10 | struct fpga_region; |
| 11 | |
| 12 | /** |
| 13 | * struct fpga_region_info - collection of parameters an FPGA Region |
| 14 | * @mgr: fpga region manager |
| 15 | * @compat_id: FPGA region id for compatibility check. |
| 16 | * @priv: fpga region private data |
| 17 | * @get_bridges: optional function to get bridges to a list |
| 18 | * |
| 19 | * fpga_region_info contains parameters for the register_full function. |
| 20 | * These are separated into an info structure because they some are optional |
| 21 | * others could be added to in the future. The info structure facilitates |
| 22 | * maintaining a stable API. |
| 23 | */ |
| 24 | struct fpga_region_info { |
| 25 | struct fpga_manager *mgr; |
| 26 | struct fpga_compat_id *compat_id; |
| 27 | void *priv; |
| 28 | int (*get_bridges)(struct fpga_region *region); |
| 29 | }; |
| 30 | |
| 31 | /** |
| 32 | * struct fpga_region - FPGA Region structure |
| 33 | * @dev: FPGA Region device |
| 34 | * @mutex: enforces exclusive reference to region |
| 35 | * @bridge_list: list of FPGA bridges specified in region |
| 36 | * @mgr: FPGA manager |
| 37 | * @info: FPGA image info |
| 38 | * @compat_id: FPGA region id for compatibility check. |
| 39 | * @ops_owner: module containing the get_bridges function |
| 40 | * @priv: private data |
| 41 | * @get_bridges: optional function to get bridges to a list |
| 42 | */ |
| 43 | struct fpga_region { |
| 44 | struct device dev; |
| 45 | struct mutex mutex; /* for exclusive reference to region */ |
| 46 | struct list_head bridge_list; |
| 47 | struct fpga_manager *mgr; |
| 48 | struct fpga_image_info *info; |
| 49 | struct fpga_compat_id *compat_id; |
| 50 | struct module *ops_owner; |
| 51 | void *priv; |
| 52 | int (*get_bridges)(struct fpga_region *region); |
| 53 | }; |
| 54 | |
| 55 | #define to_fpga_region(d) container_of(d, struct fpga_region, dev) |
| 56 | |
| 57 | struct fpga_region * |
| 58 | fpga_region_class_find(struct device *start, const void *data, |
| 59 | int (*match)(struct device *, const void *)); |
| 60 | |
| 61 | int fpga_region_program_fpga(struct fpga_region *region); |
| 62 | |
| 63 | #define fpga_region_register_full(parent, info) \ |
| 64 | __fpga_region_register_full(parent, info, THIS_MODULE) |
| 65 | struct fpga_region * |
| 66 | __fpga_region_register_full(struct device *parent, const struct fpga_region_info *info, |
| 67 | struct module *owner); |
| 68 | |
| 69 | #define fpga_region_register(parent, mgr, get_bridges) \ |
| 70 | __fpga_region_register(parent, mgr, get_bridges, THIS_MODULE) |
| 71 | struct fpga_region * |
| 72 | __fpga_region_register(struct device *parent, struct fpga_manager *mgr, |
| 73 | int (*get_bridges)(struct fpga_region *), struct module *owner); |
| 74 | void fpga_region_unregister(struct fpga_region *region); |
| 75 | |
| 76 | #endif /* _FPGA_REGION_H */ |
| 77 | |