Lines Matching full:region
3 * FPGA Region - Support for FPGA programming under Linux
10 #include <linux/fpga/fpga-region.h>
36 * fpga_region_get - get an exclusive reference to an fpga region
37 * @region: FPGA Region struct
39 * Caller should call fpga_region_put() when done with region.
43 * * -EBUSY if someone already has a reference to the region.
46 static struct fpga_region *fpga_region_get(struct fpga_region *region) in fpga_region_get() argument
48 struct device *dev = ®ion->dev; in fpga_region_get()
50 if (!mutex_trylock(®ion->mutex)) { in fpga_region_get()
51 dev_dbg(dev, "%s: FPGA Region already in use\n", __func__); in fpga_region_get()
56 if (!try_module_get(region->ops_owner)) { in fpga_region_get()
58 mutex_unlock(®ion->mutex); in fpga_region_get()
64 return region; in fpga_region_get()
68 * fpga_region_put - release a reference to a region
70 * @region: FPGA region
72 static void fpga_region_put(struct fpga_region *region) in fpga_region_put() argument
74 struct device *dev = ®ion->dev; in fpga_region_put()
78 module_put(region->ops_owner); in fpga_region_put()
80 mutex_unlock(®ion->mutex); in fpga_region_put()
86 * @region: FPGA region
88 * Program an FPGA using fpga image info (region->info).
89 * If the region has a get_bridges function, the exclusive reference for the
91 * reprogramming the region until the caller considers it safe to do so.
93 * reprogram the region.
97 int fpga_region_program_fpga(struct fpga_region *region) in fpga_region_program_fpga() argument
99 struct device *dev = ®ion->dev; in fpga_region_program_fpga()
100 struct fpga_image_info *info = region->info; in fpga_region_program_fpga()
103 region = fpga_region_get(region); in fpga_region_program_fpga()
104 if (IS_ERR(region)) { in fpga_region_program_fpga()
105 dev_err(dev, "failed to get FPGA region\n"); in fpga_region_program_fpga()
106 return PTR_ERR(region); in fpga_region_program_fpga()
109 ret = fpga_mgr_lock(region->mgr); in fpga_region_program_fpga()
117 * fpga region struct. Or we don't have any bridges. in fpga_region_program_fpga()
119 if (region->get_bridges) { in fpga_region_program_fpga()
120 ret = region->get_bridges(region); in fpga_region_program_fpga()
122 dev_err(dev, "failed to get fpga region bridges\n"); in fpga_region_program_fpga()
127 ret = fpga_bridges_disable(®ion->bridge_list); in fpga_region_program_fpga()
133 ret = fpga_mgr_load(region->mgr, info); in fpga_region_program_fpga()
139 ret = fpga_bridges_enable(®ion->bridge_list); in fpga_region_program_fpga()
141 dev_err(dev, "failed to enable region bridges\n"); in fpga_region_program_fpga()
145 fpga_mgr_unlock(region->mgr); in fpga_region_program_fpga()
146 fpga_region_put(region); in fpga_region_program_fpga()
151 if (region->get_bridges) in fpga_region_program_fpga()
152 fpga_bridges_put(®ion->bridge_list); in fpga_region_program_fpga()
154 fpga_mgr_unlock(region->mgr); in fpga_region_program_fpga()
156 fpga_region_put(region); in fpga_region_program_fpga()
165 struct fpga_region *region = to_fpga_region(dev); in compat_id_show() local
167 if (!region->compat_id) in compat_id_show()
171 (unsigned long long)region->compat_id->id_h, in compat_id_show()
172 (unsigned long long)region->compat_id->id_l); in compat_id_show()
184 * __fpga_region_register_full - create and register an FPGA Region device
186 * @info: parameters for FPGA Region
195 struct fpga_region *region; in __fpga_region_register_full() local
204 region = kzalloc(sizeof(*region), GFP_KERNEL); in __fpga_region_register_full()
205 if (!region) in __fpga_region_register_full()
214 region->mgr = info->mgr; in __fpga_region_register_full()
215 region->compat_id = info->compat_id; in __fpga_region_register_full()
216 region->priv = info->priv; in __fpga_region_register_full()
217 region->get_bridges = info->get_bridges; in __fpga_region_register_full()
218 region->ops_owner = owner; in __fpga_region_register_full()
220 mutex_init(®ion->mutex); in __fpga_region_register_full()
221 INIT_LIST_HEAD(®ion->bridge_list); in __fpga_region_register_full()
223 region->dev.class = &fpga_region_class; in __fpga_region_register_full()
224 region->dev.parent = parent; in __fpga_region_register_full()
225 region->dev.of_node = parent->of_node; in __fpga_region_register_full()
226 region->dev.id = id; in __fpga_region_register_full()
228 ret = dev_set_name(®ion->dev, "region%d", id); in __fpga_region_register_full()
232 ret = device_register(®ion->dev); in __fpga_region_register_full()
234 put_device(®ion->dev); in __fpga_region_register_full()
238 return region; in __fpga_region_register_full()
243 kfree(region); in __fpga_region_register_full()
250 * __fpga_region_register - create and register an FPGA Region device
252 * @mgr: manager that programs this region
276 * fpga_region_unregister - unregister an FPGA region
277 * @region: FPGA region
279 * This function is intended for use in an FPGA region driver's remove function.
281 void fpga_region_unregister(struct fpga_region *region) in fpga_region_unregister() argument
283 device_unregister(®ion->dev); in fpga_region_unregister()
289 struct fpga_region *region = to_fpga_region(dev); in fpga_region_dev_release() local
291 ida_free(&fpga_region_ida, region->dev.id); in fpga_region_dev_release()
292 kfree(region); in fpga_region_dev_release()
320 MODULE_DESCRIPTION("FPGA Region");