fpga-mgr.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * FPGA Manager Core
  4. *
  5. * Copyright (C) 2013-2015 Altera Corporation
  6. * Copyright (C) 2017 Intel Corporation
  7. *
  8. * With code from the mailing list:
  9. * Copyright (C) 2013 Xilinx, Inc.
  10. */
  11. #include <linux/firmware.h>
  12. #include <linux/fpga/fpga-mgr.h>
  13. #include <linux/idr.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/mutex.h>
  17. #include <linux/slab.h>
  18. #include <linux/scatterlist.h>
  19. #include <linux/highmem.h>
  20. static DEFINE_IDA(fpga_mgr_ida);
  21. static struct class *fpga_mgr_class;
  22. /**
  23. * fpga_image_info_alloc - Allocate a FPGA image info struct
  24. * @dev: owning device
  25. *
  26. * Return: struct fpga_image_info or NULL
  27. */
  28. struct fpga_image_info *fpga_image_info_alloc(struct device *dev)
  29. {
  30. struct fpga_image_info *info;
  31. get_device(dev);
  32. info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
  33. if (!info) {
  34. put_device(dev);
  35. return NULL;
  36. }
  37. info->dev = dev;
  38. return info;
  39. }
  40. EXPORT_SYMBOL_GPL(fpga_image_info_alloc);
  41. /**
  42. * fpga_image_info_free - Free a FPGA image info struct
  43. * @info: FPGA image info struct to free
  44. */
  45. void fpga_image_info_free(struct fpga_image_info *info)
  46. {
  47. struct device *dev;
  48. if (!info)
  49. return;
  50. dev = info->dev;
  51. if (info->firmware_name)
  52. devm_kfree(dev, info->firmware_name);
  53. devm_kfree(dev, info);
  54. put_device(dev);
  55. }
  56. EXPORT_SYMBOL_GPL(fpga_image_info_free);
  57. /*
  58. * Call the low level driver's write_init function. This will do the
  59. * device-specific things to get the FPGA into the state where it is ready to
  60. * receive an FPGA image. The low level driver only gets to see the first
  61. * initial_header_size bytes in the buffer.
  62. */
  63. static int fpga_mgr_write_init_buf(struct fpga_manager *mgr,
  64. struct fpga_image_info *info,
  65. const char *buf, size_t count)
  66. {
  67. int ret;
  68. mgr->state = FPGA_MGR_STATE_WRITE_INIT;
  69. if (!mgr->mops->initial_header_size)
  70. ret = mgr->mops->write_init(mgr, info, NULL, 0);
  71. else
  72. ret = mgr->mops->write_init(
  73. mgr, info, buf, min(mgr->mops->initial_header_size, count));
  74. if (ret) {
  75. dev_err(&mgr->dev, "Error preparing FPGA for writing\n");
  76. mgr->state = FPGA_MGR_STATE_WRITE_INIT_ERR;
  77. return ret;
  78. }
  79. return 0;
  80. }
  81. static int fpga_mgr_write_init_sg(struct fpga_manager *mgr,
  82. struct fpga_image_info *info,
  83. struct sg_table *sgt)
  84. {
  85. struct sg_mapping_iter miter;
  86. size_t len;
  87. char *buf;
  88. int ret;
  89. if (!mgr->mops->initial_header_size)
  90. return fpga_mgr_write_init_buf(mgr, info, NULL, 0);
  91. /*
  92. * First try to use miter to map the first fragment to access the
  93. * header, this is the typical path.
  94. */
  95. sg_miter_start(&miter, sgt->sgl, sgt->nents, SG_MITER_FROM_SG);
  96. if (sg_miter_next(&miter) &&
  97. miter.length >= mgr->mops->initial_header_size) {
  98. ret = fpga_mgr_write_init_buf(mgr, info, miter.addr,
  99. miter.length);
  100. sg_miter_stop(&miter);
  101. return ret;
  102. }
  103. sg_miter_stop(&miter);
  104. /* Otherwise copy the fragments into temporary memory. */
  105. buf = kmalloc(mgr->mops->initial_header_size, GFP_KERNEL);
  106. if (!buf)
  107. return -ENOMEM;
  108. len = sg_copy_to_buffer(sgt->sgl, sgt->nents, buf,
  109. mgr->mops->initial_header_size);
  110. ret = fpga_mgr_write_init_buf(mgr, info, buf, len);
  111. kfree(buf);
  112. return ret;
  113. }
  114. /*
  115. * After all the FPGA image has been written, do the device specific steps to
  116. * finish and set the FPGA into operating mode.
  117. */
  118. static int fpga_mgr_write_complete(struct fpga_manager *mgr,
  119. struct fpga_image_info *info)
  120. {
  121. int ret;
  122. mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE;
  123. ret = mgr->mops->write_complete(mgr, info);
  124. if (ret) {
  125. dev_err(&mgr->dev, "Error after writing image data to FPGA\n");
  126. mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE_ERR;
  127. return ret;
  128. }
  129. mgr->state = FPGA_MGR_STATE_OPERATING;
  130. return 0;
  131. }
  132. /**
  133. * fpga_mgr_buf_load_sg - load fpga from image in buffer from a scatter list
  134. * @mgr: fpga manager
  135. * @info: fpga image specific information
  136. * @sgt: scatterlist table
  137. *
  138. * Step the low level fpga manager through the device-specific steps of getting
  139. * an FPGA ready to be configured, writing the image to it, then doing whatever
  140. * post-configuration steps necessary. This code assumes the caller got the
  141. * mgr pointer from of_fpga_mgr_get() or fpga_mgr_get() and checked that it is
  142. * not an error code.
  143. *
  144. * This is the preferred entry point for FPGA programming, it does not require
  145. * any contiguous kernel memory.
  146. *
  147. * Return: 0 on success, negative error code otherwise.
  148. */
  149. static int fpga_mgr_buf_load_sg(struct fpga_manager *mgr,
  150. struct fpga_image_info *info,
  151. struct sg_table *sgt)
  152. {
  153. int ret;
  154. ret = fpga_mgr_write_init_sg(mgr, info, sgt);
  155. if (ret)
  156. return ret;
  157. /* Write the FPGA image to the FPGA. */
  158. mgr->state = FPGA_MGR_STATE_WRITE;
  159. if (mgr->mops->write_sg) {
  160. ret = mgr->mops->write_sg(mgr, sgt);
  161. } else {
  162. struct sg_mapping_iter miter;
  163. sg_miter_start(&miter, sgt->sgl, sgt->nents, SG_MITER_FROM_SG);
  164. while (sg_miter_next(&miter)) {
  165. ret = mgr->mops->write(mgr, miter.addr, miter.length);
  166. if (ret)
  167. break;
  168. }
  169. sg_miter_stop(&miter);
  170. }
  171. if (ret) {
  172. dev_err(&mgr->dev, "Error while writing image data to FPGA\n");
  173. mgr->state = FPGA_MGR_STATE_WRITE_ERR;
  174. return ret;
  175. }
  176. return fpga_mgr_write_complete(mgr, info);
  177. }
  178. static int fpga_mgr_buf_load_mapped(struct fpga_manager *mgr,
  179. struct fpga_image_info *info,
  180. const char *buf, size_t count)
  181. {
  182. int ret;
  183. ret = fpga_mgr_write_init_buf(mgr, info, buf, count);
  184. if (ret)
  185. return ret;
  186. /*
  187. * Write the FPGA image to the FPGA.
  188. */
  189. mgr->state = FPGA_MGR_STATE_WRITE;
  190. ret = mgr->mops->write(mgr, buf, count);
  191. if (ret) {
  192. dev_err(&mgr->dev, "Error while writing image data to FPGA\n");
  193. mgr->state = FPGA_MGR_STATE_WRITE_ERR;
  194. return ret;
  195. }
  196. return fpga_mgr_write_complete(mgr, info);
  197. }
  198. /**
  199. * fpga_mgr_buf_load - load fpga from image in buffer
  200. * @mgr: fpga manager
  201. * @info: fpga image info
  202. * @buf: buffer contain fpga image
  203. * @count: byte count of buf
  204. *
  205. * Step the low level fpga manager through the device-specific steps of getting
  206. * an FPGA ready to be configured, writing the image to it, then doing whatever
  207. * post-configuration steps necessary. This code assumes the caller got the
  208. * mgr pointer from of_fpga_mgr_get() and checked that it is not an error code.
  209. *
  210. * Return: 0 on success, negative error code otherwise.
  211. */
  212. static int fpga_mgr_buf_load(struct fpga_manager *mgr,
  213. struct fpga_image_info *info,
  214. const char *buf, size_t count)
  215. {
  216. struct page **pages;
  217. struct sg_table sgt;
  218. const void *p;
  219. int nr_pages;
  220. int index;
  221. int rc;
  222. /*
  223. * This is just a fast path if the caller has already created a
  224. * contiguous kernel buffer and the driver doesn't require SG, non-SG
  225. * drivers will still work on the slow path.
  226. */
  227. if (mgr->mops->write)
  228. return fpga_mgr_buf_load_mapped(mgr, info, buf, count);
  229. /*
  230. * Convert the linear kernel pointer into a sg_table of pages for use
  231. * by the driver.
  232. */
  233. nr_pages = DIV_ROUND_UP((unsigned long)buf + count, PAGE_SIZE) -
  234. (unsigned long)buf / PAGE_SIZE;
  235. pages = kmalloc_array(nr_pages, sizeof(struct page *), GFP_KERNEL);
  236. if (!pages)
  237. return -ENOMEM;
  238. p = buf - offset_in_page(buf);
  239. for (index = 0; index < nr_pages; index++) {
  240. if (is_vmalloc_addr(p))
  241. pages[index] = vmalloc_to_page(p);
  242. else
  243. pages[index] = kmap_to_page((void *)p);
  244. if (!pages[index]) {
  245. kfree(pages);
  246. return -EFAULT;
  247. }
  248. p += PAGE_SIZE;
  249. }
  250. /*
  251. * The temporary pages list is used to code share the merging algorithm
  252. * in sg_alloc_table_from_pages
  253. */
  254. rc = sg_alloc_table_from_pages(&sgt, pages, index, offset_in_page(buf),
  255. count, GFP_KERNEL);
  256. kfree(pages);
  257. if (rc)
  258. return rc;
  259. rc = fpga_mgr_buf_load_sg(mgr, info, &sgt);
  260. sg_free_table(&sgt);
  261. return rc;
  262. }
  263. /**
  264. * fpga_mgr_firmware_load - request firmware and load to fpga
  265. * @mgr: fpga manager
  266. * @info: fpga image specific information
  267. * @image_name: name of image file on the firmware search path
  268. *
  269. * Request an FPGA image using the firmware class, then write out to the FPGA.
  270. * Update the state before each step to provide info on what step failed if
  271. * there is a failure. This code assumes the caller got the mgr pointer
  272. * from of_fpga_mgr_get() or fpga_mgr_get() and checked that it is not an error
  273. * code.
  274. *
  275. * Return: 0 on success, negative error code otherwise.
  276. */
  277. static int fpga_mgr_firmware_load(struct fpga_manager *mgr,
  278. struct fpga_image_info *info,
  279. const char *image_name)
  280. {
  281. struct device *dev = &mgr->dev;
  282. const struct firmware *fw;
  283. int ret;
  284. dev_info(dev, "writing %s to %s\n", image_name, mgr->name);
  285. mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ;
  286. ret = request_firmware(&fw, image_name, dev);
  287. if (ret) {
  288. mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ_ERR;
  289. dev_err(dev, "Error requesting firmware %s\n", image_name);
  290. return ret;
  291. }
  292. ret = fpga_mgr_buf_load(mgr, info, fw->data, fw->size);
  293. release_firmware(fw);
  294. return ret;
  295. }
  296. /**
  297. * fpga_mgr_load - load FPGA from scatter/gather table, buffer, or firmware
  298. * @mgr: fpga manager
  299. * @info: fpga image information.
  300. *
  301. * Load the FPGA from an image which is indicated in @info. If successful, the
  302. * FPGA ends up in operating mode.
  303. *
  304. * Return: 0 on success, negative error code otherwise.
  305. */
  306. int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info)
  307. {
  308. if (info->sgt)
  309. return fpga_mgr_buf_load_sg(mgr, info, info->sgt);
  310. if (info->buf && info->count)
  311. return fpga_mgr_buf_load(mgr, info, info->buf, info->count);
  312. if (info->firmware_name)
  313. return fpga_mgr_firmware_load(mgr, info, info->firmware_name);
  314. return -EINVAL;
  315. }
  316. EXPORT_SYMBOL_GPL(fpga_mgr_load);
  317. static const char * const state_str[] = {
  318. [FPGA_MGR_STATE_UNKNOWN] = "unknown",
  319. [FPGA_MGR_STATE_POWER_OFF] = "power off",
  320. [FPGA_MGR_STATE_POWER_UP] = "power up",
  321. [FPGA_MGR_STATE_RESET] = "reset",
  322. /* requesting FPGA image from firmware */
  323. [FPGA_MGR_STATE_FIRMWARE_REQ] = "firmware request",
  324. [FPGA_MGR_STATE_FIRMWARE_REQ_ERR] = "firmware request error",
  325. /* Preparing FPGA to receive image */
  326. [FPGA_MGR_STATE_WRITE_INIT] = "write init",
  327. [FPGA_MGR_STATE_WRITE_INIT_ERR] = "write init error",
  328. /* Writing image to FPGA */
  329. [FPGA_MGR_STATE_WRITE] = "write",
  330. [FPGA_MGR_STATE_WRITE_ERR] = "write error",
  331. /* Finishing configuration after image has been written */
  332. [FPGA_MGR_STATE_WRITE_COMPLETE] = "write complete",
  333. [FPGA_MGR_STATE_WRITE_COMPLETE_ERR] = "write complete error",
  334. /* FPGA reports to be in normal operating mode */
  335. [FPGA_MGR_STATE_OPERATING] = "operating",
  336. };
  337. static ssize_t name_show(struct device *dev,
  338. struct device_attribute *attr, char *buf)
  339. {
  340. struct fpga_manager *mgr = to_fpga_manager(dev);
  341. return sprintf(buf, "%s\n", mgr->name);
  342. }
  343. static ssize_t state_show(struct device *dev,
  344. struct device_attribute *attr, char *buf)
  345. {
  346. struct fpga_manager *mgr = to_fpga_manager(dev);
  347. return sprintf(buf, "%s\n", state_str[mgr->state]);
  348. }
  349. static DEVICE_ATTR_RO(name);
  350. static DEVICE_ATTR_RO(state);
  351. static struct attribute *fpga_mgr_attrs[] = {
  352. &dev_attr_name.attr,
  353. &dev_attr_state.attr,
  354. NULL,
  355. };
  356. ATTRIBUTE_GROUPS(fpga_mgr);
  357. static struct fpga_manager *__fpga_mgr_get(struct device *dev)
  358. {
  359. struct fpga_manager *mgr;
  360. mgr = to_fpga_manager(dev);
  361. if (!try_module_get(dev->parent->driver->owner))
  362. goto err_dev;
  363. return mgr;
  364. err_dev:
  365. put_device(dev);
  366. return ERR_PTR(-ENODEV);
  367. }
  368. static int fpga_mgr_dev_match(struct device *dev, const void *data)
  369. {
  370. return dev->parent == data;
  371. }
  372. /**
  373. * fpga_mgr_get - Given a device, get a reference to a fpga mgr.
  374. * @dev: parent device that fpga mgr was registered with
  375. *
  376. * Return: fpga manager struct or IS_ERR() condition containing error code.
  377. */
  378. struct fpga_manager *fpga_mgr_get(struct device *dev)
  379. {
  380. struct device *mgr_dev = class_find_device(fpga_mgr_class, NULL, dev,
  381. fpga_mgr_dev_match);
  382. if (!mgr_dev)
  383. return ERR_PTR(-ENODEV);
  384. return __fpga_mgr_get(mgr_dev);
  385. }
  386. EXPORT_SYMBOL_GPL(fpga_mgr_get);
  387. static int fpga_mgr_of_node_match(struct device *dev, const void *data)
  388. {
  389. return dev->of_node == data;
  390. }
  391. /**
  392. * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
  393. *
  394. * @node: device node
  395. *
  396. * Return: fpga manager struct or IS_ERR() condition containing error code.
  397. */
  398. struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
  399. {
  400. struct device *dev;
  401. dev = class_find_device(fpga_mgr_class, NULL, node,
  402. fpga_mgr_of_node_match);
  403. if (!dev)
  404. return ERR_PTR(-ENODEV);
  405. return __fpga_mgr_get(dev);
  406. }
  407. EXPORT_SYMBOL_GPL(of_fpga_mgr_get);
  408. /**
  409. * fpga_mgr_put - release a reference to a fpga manager
  410. * @mgr: fpga manager structure
  411. */
  412. void fpga_mgr_put(struct fpga_manager *mgr)
  413. {
  414. module_put(mgr->dev.parent->driver->owner);
  415. put_device(&mgr->dev);
  416. }
  417. EXPORT_SYMBOL_GPL(fpga_mgr_put);
  418. /**
  419. * fpga_mgr_lock - Lock FPGA manager for exclusive use
  420. * @mgr: fpga manager
  421. *
  422. * Given a pointer to FPGA Manager (from fpga_mgr_get() or
  423. * of_fpga_mgr_put()) attempt to get the mutex. The user should call
  424. * fpga_mgr_lock() and verify that it returns 0 before attempting to
  425. * program the FPGA. Likewise, the user should call fpga_mgr_unlock
  426. * when done programming the FPGA.
  427. *
  428. * Return: 0 for success or -EBUSY
  429. */
  430. int fpga_mgr_lock(struct fpga_manager *mgr)
  431. {
  432. if (!mutex_trylock(&mgr->ref_mutex)) {
  433. dev_err(&mgr->dev, "FPGA manager is in use.\n");
  434. return -EBUSY;
  435. }
  436. return 0;
  437. }
  438. EXPORT_SYMBOL_GPL(fpga_mgr_lock);
  439. /**
  440. * fpga_mgr_unlock - Unlock FPGA manager after done programming
  441. * @mgr: fpga manager
  442. */
  443. void fpga_mgr_unlock(struct fpga_manager *mgr)
  444. {
  445. mutex_unlock(&mgr->ref_mutex);
  446. }
  447. EXPORT_SYMBOL_GPL(fpga_mgr_unlock);
  448. /**
  449. * fpga_mgr_create - create and initialize a FPGA manager struct
  450. * @dev: fpga manager device from pdev
  451. * @name: fpga manager name
  452. * @mops: pointer to structure of fpga manager ops
  453. * @priv: fpga manager private data
  454. *
  455. * Return: pointer to struct fpga_manager or NULL
  456. */
  457. struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,
  458. const struct fpga_manager_ops *mops,
  459. void *priv)
  460. {
  461. struct fpga_manager *mgr;
  462. int id, ret;
  463. if (!mops || !mops->write_complete || !mops->state ||
  464. !mops->write_init || (!mops->write && !mops->write_sg) ||
  465. (mops->write && mops->write_sg)) {
  466. dev_err(dev, "Attempt to register without fpga_manager_ops\n");
  467. return NULL;
  468. }
  469. if (!name || !strlen(name)) {
  470. dev_err(dev, "Attempt to register with no name!\n");
  471. return NULL;
  472. }
  473. mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
  474. if (!mgr)
  475. return NULL;
  476. id = ida_simple_get(&fpga_mgr_ida, 0, 0, GFP_KERNEL);
  477. if (id < 0) {
  478. ret = id;
  479. goto error_kfree;
  480. }
  481. mutex_init(&mgr->ref_mutex);
  482. mgr->name = name;
  483. mgr->mops = mops;
  484. mgr->priv = priv;
  485. device_initialize(&mgr->dev);
  486. mgr->dev.class = fpga_mgr_class;
  487. mgr->dev.groups = mops->groups;
  488. mgr->dev.parent = dev;
  489. mgr->dev.of_node = dev->of_node;
  490. mgr->dev.id = id;
  491. ret = dev_set_name(&mgr->dev, "fpga%d", id);
  492. if (ret)
  493. goto error_device;
  494. return mgr;
  495. error_device:
  496. ida_simple_remove(&fpga_mgr_ida, id);
  497. error_kfree:
  498. kfree(mgr);
  499. return NULL;
  500. }
  501. EXPORT_SYMBOL_GPL(fpga_mgr_create);
  502. /**
  503. * fpga_mgr_free - deallocate a FPGA manager
  504. * @mgr: fpga manager struct created by fpga_mgr_create
  505. */
  506. void fpga_mgr_free(struct fpga_manager *mgr)
  507. {
  508. ida_simple_remove(&fpga_mgr_ida, mgr->dev.id);
  509. kfree(mgr);
  510. }
  511. EXPORT_SYMBOL_GPL(fpga_mgr_free);
  512. /**
  513. * fpga_mgr_register - register a FPGA manager
  514. * @mgr: fpga manager struct created by fpga_mgr_create
  515. *
  516. * Return: 0 on success, negative error code otherwise.
  517. */
  518. int fpga_mgr_register(struct fpga_manager *mgr)
  519. {
  520. int ret;
  521. /*
  522. * Initialize framework state by requesting low level driver read state
  523. * from device. FPGA may be in reset mode or may have been programmed
  524. * by bootloader or EEPROM.
  525. */
  526. mgr->state = mgr->mops->state(mgr);
  527. ret = device_add(&mgr->dev);
  528. if (ret)
  529. goto error_device;
  530. dev_info(&mgr->dev, "%s registered\n", mgr->name);
  531. return 0;
  532. error_device:
  533. ida_simple_remove(&fpga_mgr_ida, mgr->dev.id);
  534. return ret;
  535. }
  536. EXPORT_SYMBOL_GPL(fpga_mgr_register);
  537. /**
  538. * fpga_mgr_unregister - unregister and free a FPGA manager
  539. * @mgr: fpga manager struct
  540. */
  541. void fpga_mgr_unregister(struct fpga_manager *mgr)
  542. {
  543. dev_info(&mgr->dev, "%s %s\n", __func__, mgr->name);
  544. /*
  545. * If the low level driver provides a method for putting fpga into
  546. * a desired state upon unregister, do it.
  547. */
  548. if (mgr->mops->fpga_remove)
  549. mgr->mops->fpga_remove(mgr);
  550. device_unregister(&mgr->dev);
  551. }
  552. EXPORT_SYMBOL_GPL(fpga_mgr_unregister);
  553. static void fpga_mgr_dev_release(struct device *dev)
  554. {
  555. struct fpga_manager *mgr = to_fpga_manager(dev);
  556. fpga_mgr_free(mgr);
  557. }
  558. static int __init fpga_mgr_class_init(void)
  559. {
  560. pr_info("FPGA manager framework\n");
  561. fpga_mgr_class = class_create(THIS_MODULE, "fpga_manager");
  562. if (IS_ERR(fpga_mgr_class))
  563. return PTR_ERR(fpga_mgr_class);
  564. fpga_mgr_class->dev_groups = fpga_mgr_groups;
  565. fpga_mgr_class->dev_release = fpga_mgr_dev_release;
  566. return 0;
  567. }
  568. static void __exit fpga_mgr_class_exit(void)
  569. {
  570. class_destroy(fpga_mgr_class);
  571. ida_destroy(&fpga_mgr_ida);
  572. }
  573. MODULE_AUTHOR("Alan Tull <atull@kernel.org>");
  574. MODULE_DESCRIPTION("FPGA manager framework");
  575. MODULE_LICENSE("GPL v2");
  576. subsys_initcall(fpga_mgr_class_init);
  577. module_exit(fpga_mgr_class_exit);