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.
42 * Return -EBUSY if someone already has a reference to the region.
43 * Return -ENODEV if @np is not an FPGA Region.
45 static struct fpga_region *fpga_region_get(struct fpga_region *region) in fpga_region_get() argument
47 struct device *dev = ®ion->dev; in fpga_region_get()
49 if (!mutex_trylock(®ion->mutex)) { in fpga_region_get()
50 dev_dbg(dev, "%s: FPGA Region already in use\n", __func__); in fpga_region_get()
57 mutex_unlock(®ion->mutex); in fpga_region_get()
63 return region; in fpga_region_get()
67 * fpga_region_put - release a reference to a region
69 * @region: FPGA region
71 static void fpga_region_put(struct fpga_region *region) in fpga_region_put() argument
73 struct device *dev = ®ion->dev; in fpga_region_put()
79 mutex_unlock(®ion->mutex); in fpga_region_put()
85 * @region: FPGA region
87 * Program an FPGA using fpga image info (region->info).
88 * If the region has a get_bridges function, the exclusive reference for the
90 * reprogramming the region until the caller considers it safe to do so.
92 * reprogram the region.
96 int fpga_region_program_fpga(struct fpga_region *region) in fpga_region_program_fpga() argument
98 struct device *dev = ®ion->dev; in fpga_region_program_fpga()
99 struct fpga_image_info *info = region->info; in fpga_region_program_fpga()
102 region = fpga_region_get(region); in fpga_region_program_fpga()
103 if (IS_ERR(region)) { in fpga_region_program_fpga()
104 dev_err(dev, "failed to get FPGA region\n"); in fpga_region_program_fpga()
105 return PTR_ERR(region); in fpga_region_program_fpga()
108 ret = fpga_mgr_lock(region->mgr); in fpga_region_program_fpga()
116 * fpga region struct. Or we don't have any bridges. in fpga_region_program_fpga()
118 if (region->get_bridges) { in fpga_region_program_fpga()
119 ret = region->get_bridges(region); in fpga_region_program_fpga()
121 dev_err(dev, "failed to get fpga region bridges\n"); in fpga_region_program_fpga()
126 ret = fpga_bridges_disable(®ion->bridge_list); in fpga_region_program_fpga()
132 ret = fpga_mgr_load(region->mgr, info); in fpga_region_program_fpga()
138 ret = fpga_bridges_enable(®ion->bridge_list); in fpga_region_program_fpga()
140 dev_err(dev, "failed to enable region bridges\n"); in fpga_region_program_fpga()
144 fpga_mgr_unlock(region->mgr); in fpga_region_program_fpga()
145 fpga_region_put(region); in fpga_region_program_fpga()
150 if (region->get_bridges) in fpga_region_program_fpga()
151 fpga_bridges_put(®ion->bridge_list); in fpga_region_program_fpga()
153 fpga_mgr_unlock(region->mgr); in fpga_region_program_fpga()
155 fpga_region_put(region); in fpga_region_program_fpga()
164 struct fpga_region *region = to_fpga_region(dev); in compat_id_show() local
166 if (!region->compat_id) in compat_id_show()
170 (unsigned long long)region->compat_id->id_h, in compat_id_show()
171 (unsigned long long)region->compat_id->id_l); in compat_id_show()
183 * fpga_region_register_full - create and register an FPGA Region device
185 * @info: parameters for FPGA Region
192 struct fpga_region *region; in fpga_region_register_full() local
201 region = kzalloc(sizeof(*region), GFP_KERNEL); in fpga_region_register_full()
202 if (!region) in fpga_region_register_full()
211 region->mgr = info->mgr; in fpga_region_register_full()
212 region->compat_id = info->compat_id; in fpga_region_register_full()
213 region->priv = info->priv; in fpga_region_register_full()
214 region->get_bridges = info->get_bridges; in fpga_region_register_full()
216 mutex_init(®ion->mutex); in fpga_region_register_full()
217 INIT_LIST_HEAD(®ion->bridge_list); in fpga_region_register_full()
219 region->dev.class = fpga_region_class; in fpga_region_register_full()
220 region->dev.parent = parent; in fpga_region_register_full()
221 region->dev.of_node = parent->of_node; in fpga_region_register_full()
222 region->dev.id = id; in fpga_region_register_full()
224 ret = dev_set_name(®ion->dev, "region%d", id); in fpga_region_register_full()
228 ret = device_register(®ion->dev); in fpga_region_register_full()
230 put_device(®ion->dev); in fpga_region_register_full()
234 return region; in fpga_region_register_full()
239 kfree(region); in fpga_region_register_full()
246 * fpga_region_register - create and register an FPGA Region device
248 * @mgr: manager that programs this region
271 * fpga_region_unregister - unregister an FPGA region
272 * @region: FPGA region
274 * This function is intended for use in an FPGA region driver's remove function.
276 void fpga_region_unregister(struct fpga_region *region) in fpga_region_unregister() argument
278 device_unregister(®ion->dev); in fpga_region_unregister()
284 struct fpga_region *region = to_fpga_region(dev); in fpga_region_dev_release() local
286 ida_free(&fpga_region_ida, region->dev.id); in fpga_region_dev_release()
287 kfree(region); in fpga_region_dev_release()
315 MODULE_DESCRIPTION("FPGA Region");