dell_rbu.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /*
  2. * dell_rbu.c
  3. * Bios Update driver for Dell systems
  4. * Author: Dell Inc
  5. * Abhay Salunke <abhay_salunke@dell.com>
  6. *
  7. * Copyright (C) 2005 Dell Inc.
  8. *
  9. * Remote BIOS Update (rbu) driver is used for updating DELL BIOS by
  10. * creating entries in the /sys file systems on Linux 2.6 and higher
  11. * kernels. The driver supports two mechanism to update the BIOS namely
  12. * contiguous and packetized. Both these methods still require having some
  13. * application to set the CMOS bit indicating the BIOS to update itself
  14. * after a reboot.
  15. *
  16. * Contiguous method:
  17. * This driver writes the incoming data in a monolithic image by allocating
  18. * contiguous physical pages large enough to accommodate the incoming BIOS
  19. * image size.
  20. *
  21. * Packetized method:
  22. * The driver writes the incoming packet image by allocating a new packet
  23. * on every time the packet data is written. This driver requires an
  24. * application to break the BIOS image in to fixed sized packet chunks.
  25. *
  26. * See Documentation/dell_rbu.txt for more info.
  27. *
  28. * This program is free software; you can redistribute it and/or modify
  29. * it under the terms of the GNU General Public License v2.0 as published by
  30. * the Free Software Foundation
  31. *
  32. * This program is distributed in the hope that it will be useful,
  33. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  35. * GNU General Public License for more details.
  36. */
  37. #include <linux/init.h>
  38. #include <linux/module.h>
  39. #include <linux/string.h>
  40. #include <linux/errno.h>
  41. #include <linux/blkdev.h>
  42. #include <linux/platform_device.h>
  43. #include <linux/spinlock.h>
  44. #include <linux/moduleparam.h>
  45. #include <linux/firmware.h>
  46. #include <linux/dma-mapping.h>
  47. MODULE_AUTHOR("Abhay Salunke <abhay_salunke@dell.com>");
  48. MODULE_DESCRIPTION("Driver for updating BIOS image on DELL systems");
  49. MODULE_LICENSE("GPL");
  50. MODULE_VERSION("3.2");
  51. #define BIOS_SCAN_LIMIT 0xffffffff
  52. #define MAX_IMAGE_LENGTH 16
  53. static struct _rbu_data {
  54. void *image_update_buffer;
  55. unsigned long image_update_buffer_size;
  56. unsigned long bios_image_size;
  57. int image_update_ordernum;
  58. int dma_alloc;
  59. spinlock_t lock;
  60. unsigned long packet_read_count;
  61. unsigned long num_packets;
  62. unsigned long packetsize;
  63. unsigned long imagesize;
  64. int entry_created;
  65. } rbu_data;
  66. static char image_type[MAX_IMAGE_LENGTH + 1] = "mono";
  67. module_param_string(image_type, image_type, sizeof (image_type), 0);
  68. MODULE_PARM_DESC(image_type,
  69. "BIOS image type. choose- mono or packet or init");
  70. static unsigned long allocation_floor = 0x100000;
  71. module_param(allocation_floor, ulong, 0644);
  72. MODULE_PARM_DESC(allocation_floor,
  73. "Minimum address for allocations when using Packet mode");
  74. struct packet_data {
  75. struct list_head list;
  76. size_t length;
  77. void *data;
  78. int ordernum;
  79. };
  80. static struct packet_data packet_data_head;
  81. static struct platform_device *rbu_device;
  82. static int context;
  83. static dma_addr_t dell_rbu_dmaaddr;
  84. static void init_packet_head(void)
  85. {
  86. INIT_LIST_HEAD(&packet_data_head.list);
  87. rbu_data.packet_read_count = 0;
  88. rbu_data.num_packets = 0;
  89. rbu_data.packetsize = 0;
  90. rbu_data.imagesize = 0;
  91. }
  92. static int create_packet(void *data, size_t length)
  93. {
  94. struct packet_data *newpacket;
  95. int ordernum = 0;
  96. int retval = 0;
  97. unsigned int packet_array_size = 0;
  98. void **invalid_addr_packet_array = NULL;
  99. void *packet_data_temp_buf = NULL;
  100. unsigned int idx = 0;
  101. pr_debug("create_packet: entry \n");
  102. if (!rbu_data.packetsize) {
  103. pr_debug("create_packet: packetsize not specified\n");
  104. retval = -EINVAL;
  105. goto out_noalloc;
  106. }
  107. spin_unlock(&rbu_data.lock);
  108. newpacket = kzalloc(sizeof (struct packet_data), GFP_KERNEL);
  109. if (!newpacket) {
  110. printk(KERN_WARNING
  111. "dell_rbu:%s: failed to allocate new "
  112. "packet\n", __func__);
  113. retval = -ENOMEM;
  114. spin_lock(&rbu_data.lock);
  115. goto out_noalloc;
  116. }
  117. ordernum = get_order(length);
  118. /*
  119. * BIOS errata mean we cannot allocate packets below 1MB or they will
  120. * be overwritten by BIOS.
  121. *
  122. * array to temporarily hold packets
  123. * that are below the allocation floor
  124. *
  125. * NOTE: very simplistic because we only need the floor to be at 1MB
  126. * due to BIOS errata. This shouldn't be used for higher floors
  127. * or you will run out of mem trying to allocate the array.
  128. */
  129. packet_array_size = max(
  130. (unsigned int)(allocation_floor / rbu_data.packetsize),
  131. (unsigned int)1);
  132. invalid_addr_packet_array = kzalloc(packet_array_size * sizeof(void*),
  133. GFP_KERNEL);
  134. if (!invalid_addr_packet_array) {
  135. printk(KERN_WARNING
  136. "dell_rbu:%s: failed to allocate "
  137. "invalid_addr_packet_array \n",
  138. __func__);
  139. retval = -ENOMEM;
  140. spin_lock(&rbu_data.lock);
  141. goto out_alloc_packet;
  142. }
  143. while (!packet_data_temp_buf) {
  144. packet_data_temp_buf = (unsigned char *)
  145. __get_free_pages(GFP_KERNEL, ordernum);
  146. if (!packet_data_temp_buf) {
  147. printk(KERN_WARNING
  148. "dell_rbu:%s: failed to allocate new "
  149. "packet\n", __func__);
  150. retval = -ENOMEM;
  151. spin_lock(&rbu_data.lock);
  152. goto out_alloc_packet_array;
  153. }
  154. if ((unsigned long)virt_to_phys(packet_data_temp_buf)
  155. < allocation_floor) {
  156. pr_debug("packet 0x%lx below floor at 0x%lx.\n",
  157. (unsigned long)virt_to_phys(
  158. packet_data_temp_buf),
  159. allocation_floor);
  160. invalid_addr_packet_array[idx++] = packet_data_temp_buf;
  161. packet_data_temp_buf = NULL;
  162. }
  163. }
  164. spin_lock(&rbu_data.lock);
  165. newpacket->data = packet_data_temp_buf;
  166. pr_debug("create_packet: newpacket at physical addr %lx\n",
  167. (unsigned long)virt_to_phys(newpacket->data));
  168. /* packets may not have fixed size */
  169. newpacket->length = length;
  170. newpacket->ordernum = ordernum;
  171. ++rbu_data.num_packets;
  172. /* initialize the newly created packet headers */
  173. INIT_LIST_HEAD(&newpacket->list);
  174. list_add_tail(&newpacket->list, &packet_data_head.list);
  175. memcpy(newpacket->data, data, length);
  176. pr_debug("create_packet: exit \n");
  177. out_alloc_packet_array:
  178. /* always free packet array */
  179. for (;idx>0;idx--) {
  180. pr_debug("freeing unused packet below floor 0x%lx.\n",
  181. (unsigned long)virt_to_phys(
  182. invalid_addr_packet_array[idx-1]));
  183. free_pages((unsigned long)invalid_addr_packet_array[idx-1],
  184. ordernum);
  185. }
  186. kfree(invalid_addr_packet_array);
  187. out_alloc_packet:
  188. /* if error, free data */
  189. if (retval)
  190. kfree(newpacket);
  191. out_noalloc:
  192. return retval;
  193. }
  194. static int packetize_data(const u8 *data, size_t length)
  195. {
  196. int rc = 0;
  197. int done = 0;
  198. int packet_length;
  199. u8 *temp;
  200. u8 *end = (u8 *) data + length;
  201. pr_debug("packetize_data: data length %zd\n", length);
  202. if (!rbu_data.packetsize) {
  203. printk(KERN_WARNING
  204. "dell_rbu: packetsize not specified\n");
  205. return -EIO;
  206. }
  207. temp = (u8 *) data;
  208. /* packetize the hunk */
  209. while (!done) {
  210. if ((temp + rbu_data.packetsize) < end)
  211. packet_length = rbu_data.packetsize;
  212. else {
  213. /* this is the last packet */
  214. packet_length = end - temp;
  215. done = 1;
  216. }
  217. if ((rc = create_packet(temp, packet_length)))
  218. return rc;
  219. pr_debug("%p:%td\n", temp, (end - temp));
  220. temp += packet_length;
  221. }
  222. rbu_data.imagesize = length;
  223. return rc;
  224. }
  225. static int do_packet_read(char *data, struct list_head *ptemp_list,
  226. int length, int bytes_read, int *list_read_count)
  227. {
  228. void *ptemp_buf;
  229. struct packet_data *newpacket = NULL;
  230. int bytes_copied = 0;
  231. int j = 0;
  232. newpacket = list_entry(ptemp_list, struct packet_data, list);
  233. *list_read_count += newpacket->length;
  234. if (*list_read_count > bytes_read) {
  235. /* point to the start of unread data */
  236. j = newpacket->length - (*list_read_count - bytes_read);
  237. /* point to the offset in the packet buffer */
  238. ptemp_buf = (u8 *) newpacket->data + j;
  239. /*
  240. * check if there is enough room in
  241. * * the incoming buffer
  242. */
  243. if (length > (*list_read_count - bytes_read))
  244. /*
  245. * copy what ever is there in this
  246. * packet and move on
  247. */
  248. bytes_copied = (*list_read_count - bytes_read);
  249. else
  250. /* copy the remaining */
  251. bytes_copied = length;
  252. memcpy(data, ptemp_buf, bytes_copied);
  253. }
  254. return bytes_copied;
  255. }
  256. static int packet_read_list(char *data, size_t * pread_length)
  257. {
  258. struct list_head *ptemp_list;
  259. int temp_count = 0;
  260. int bytes_copied = 0;
  261. int bytes_read = 0;
  262. int remaining_bytes = 0;
  263. char *pdest = data;
  264. /* check if we have any packets */
  265. if (0 == rbu_data.num_packets)
  266. return -ENOMEM;
  267. remaining_bytes = *pread_length;
  268. bytes_read = rbu_data.packet_read_count;
  269. ptemp_list = (&packet_data_head.list)->next;
  270. while (!list_empty(ptemp_list)) {
  271. bytes_copied = do_packet_read(pdest, ptemp_list,
  272. remaining_bytes, bytes_read, &temp_count);
  273. remaining_bytes -= bytes_copied;
  274. bytes_read += bytes_copied;
  275. pdest += bytes_copied;
  276. /*
  277. * check if we reached end of buffer before reaching the
  278. * last packet
  279. */
  280. if (remaining_bytes == 0)
  281. break;
  282. ptemp_list = ptemp_list->next;
  283. }
  284. /*finally set the bytes read */
  285. *pread_length = bytes_read - rbu_data.packet_read_count;
  286. rbu_data.packet_read_count = bytes_read;
  287. return 0;
  288. }
  289. static void packet_empty_list(void)
  290. {
  291. struct list_head *ptemp_list;
  292. struct list_head *pnext_list;
  293. struct packet_data *newpacket;
  294. ptemp_list = (&packet_data_head.list)->next;
  295. while (!list_empty(ptemp_list)) {
  296. newpacket =
  297. list_entry(ptemp_list, struct packet_data, list);
  298. pnext_list = ptemp_list->next;
  299. list_del(ptemp_list);
  300. ptemp_list = pnext_list;
  301. /*
  302. * zero out the RBU packet memory before freeing
  303. * to make sure there are no stale RBU packets left in memory
  304. */
  305. memset(newpacket->data, 0, rbu_data.packetsize);
  306. free_pages((unsigned long) newpacket->data,
  307. newpacket->ordernum);
  308. kfree(newpacket);
  309. }
  310. rbu_data.packet_read_count = 0;
  311. rbu_data.num_packets = 0;
  312. rbu_data.imagesize = 0;
  313. }
  314. /*
  315. * img_update_free: Frees the buffer allocated for storing BIOS image
  316. * Always called with lock held and returned with lock held
  317. */
  318. static void img_update_free(void)
  319. {
  320. if (!rbu_data.image_update_buffer)
  321. return;
  322. /*
  323. * zero out this buffer before freeing it to get rid of any stale
  324. * BIOS image copied in memory.
  325. */
  326. memset(rbu_data.image_update_buffer, 0,
  327. rbu_data.image_update_buffer_size);
  328. if (rbu_data.dma_alloc == 1)
  329. dma_free_coherent(NULL, rbu_data.bios_image_size,
  330. rbu_data.image_update_buffer, dell_rbu_dmaaddr);
  331. else
  332. free_pages((unsigned long) rbu_data.image_update_buffer,
  333. rbu_data.image_update_ordernum);
  334. /*
  335. * Re-initialize the rbu_data variables after a free
  336. */
  337. rbu_data.image_update_ordernum = -1;
  338. rbu_data.image_update_buffer = NULL;
  339. rbu_data.image_update_buffer_size = 0;
  340. rbu_data.bios_image_size = 0;
  341. rbu_data.dma_alloc = 0;
  342. }
  343. /*
  344. * img_update_realloc: This function allocates the contiguous pages to
  345. * accommodate the requested size of data. The memory address and size
  346. * values are stored globally and on every call to this function the new
  347. * size is checked to see if more data is required than the existing size.
  348. * If true the previous memory is freed and new allocation is done to
  349. * accommodate the new size. If the incoming size is less then than the
  350. * already allocated size, then that memory is reused. This function is
  351. * called with lock held and returns with lock held.
  352. */
  353. static int img_update_realloc(unsigned long size)
  354. {
  355. unsigned char *image_update_buffer = NULL;
  356. unsigned long rc;
  357. unsigned long img_buf_phys_addr;
  358. int ordernum;
  359. int dma_alloc = 0;
  360. /*
  361. * check if the buffer of sufficient size has been
  362. * already allocated
  363. */
  364. if (rbu_data.image_update_buffer_size >= size) {
  365. /*
  366. * check for corruption
  367. */
  368. if ((size != 0) && (rbu_data.image_update_buffer == NULL)) {
  369. printk(KERN_ERR "dell_rbu:%s: corruption "
  370. "check failed\n", __func__);
  371. return -EINVAL;
  372. }
  373. /*
  374. * we have a valid pre-allocated buffer with
  375. * sufficient size
  376. */
  377. return 0;
  378. }
  379. /*
  380. * free any previously allocated buffer
  381. */
  382. img_update_free();
  383. spin_unlock(&rbu_data.lock);
  384. ordernum = get_order(size);
  385. image_update_buffer =
  386. (unsigned char *) __get_free_pages(GFP_KERNEL, ordernum);
  387. img_buf_phys_addr =
  388. (unsigned long) virt_to_phys(image_update_buffer);
  389. if (img_buf_phys_addr > BIOS_SCAN_LIMIT) {
  390. free_pages((unsigned long) image_update_buffer, ordernum);
  391. ordernum = -1;
  392. image_update_buffer = dma_alloc_coherent(NULL, size,
  393. &dell_rbu_dmaaddr, GFP_KERNEL);
  394. dma_alloc = 1;
  395. }
  396. spin_lock(&rbu_data.lock);
  397. if (image_update_buffer != NULL) {
  398. rbu_data.image_update_buffer = image_update_buffer;
  399. rbu_data.image_update_buffer_size = size;
  400. rbu_data.bios_image_size =
  401. rbu_data.image_update_buffer_size;
  402. rbu_data.image_update_ordernum = ordernum;
  403. rbu_data.dma_alloc = dma_alloc;
  404. rc = 0;
  405. } else {
  406. pr_debug("Not enough memory for image update:"
  407. "size = %ld\n", size);
  408. rc = -ENOMEM;
  409. }
  410. return rc;
  411. }
  412. static ssize_t read_packet_data(char *buffer, loff_t pos, size_t count)
  413. {
  414. int retval;
  415. size_t bytes_left;
  416. size_t data_length;
  417. char *ptempBuf = buffer;
  418. /* check to see if we have something to return */
  419. if (rbu_data.num_packets == 0) {
  420. pr_debug("read_packet_data: no packets written\n");
  421. retval = -ENOMEM;
  422. goto read_rbu_data_exit;
  423. }
  424. if (pos > rbu_data.imagesize) {
  425. retval = 0;
  426. printk(KERN_WARNING "dell_rbu:read_packet_data: "
  427. "data underrun\n");
  428. goto read_rbu_data_exit;
  429. }
  430. bytes_left = rbu_data.imagesize - pos;
  431. data_length = min(bytes_left, count);
  432. if ((retval = packet_read_list(ptempBuf, &data_length)) < 0)
  433. goto read_rbu_data_exit;
  434. if ((pos + count) > rbu_data.imagesize) {
  435. rbu_data.packet_read_count = 0;
  436. /* this was the last copy */
  437. retval = bytes_left;
  438. } else
  439. retval = count;
  440. read_rbu_data_exit:
  441. return retval;
  442. }
  443. static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count)
  444. {
  445. /* check to see if we have something to return */
  446. if ((rbu_data.image_update_buffer == NULL) ||
  447. (rbu_data.bios_image_size == 0)) {
  448. pr_debug("read_rbu_data_mono: image_update_buffer %p ,"
  449. "bios_image_size %lu\n",
  450. rbu_data.image_update_buffer,
  451. rbu_data.bios_image_size);
  452. return -ENOMEM;
  453. }
  454. return memory_read_from_buffer(buffer, count, &pos,
  455. rbu_data.image_update_buffer, rbu_data.bios_image_size);
  456. }
  457. static ssize_t read_rbu_data(struct kobject *kobj,
  458. struct bin_attribute *bin_attr,
  459. char *buffer, loff_t pos, size_t count)
  460. {
  461. ssize_t ret_count = 0;
  462. spin_lock(&rbu_data.lock);
  463. if (!strcmp(image_type, "mono"))
  464. ret_count = read_rbu_mono_data(buffer, pos, count);
  465. else if (!strcmp(image_type, "packet"))
  466. ret_count = read_packet_data(buffer, pos, count);
  467. else
  468. pr_debug("read_rbu_data: invalid image type specified\n");
  469. spin_unlock(&rbu_data.lock);
  470. return ret_count;
  471. }
  472. static void callbackfn_rbu(const struct firmware *fw, void *context)
  473. {
  474. rbu_data.entry_created = 0;
  475. if (!fw)
  476. return;
  477. if (!fw->size)
  478. goto out;
  479. spin_lock(&rbu_data.lock);
  480. if (!strcmp(image_type, "mono")) {
  481. if (!img_update_realloc(fw->size))
  482. memcpy(rbu_data.image_update_buffer,
  483. fw->data, fw->size);
  484. } else if (!strcmp(image_type, "packet")) {
  485. /*
  486. * we need to free previous packets if a
  487. * new hunk of packets needs to be downloaded
  488. */
  489. packet_empty_list();
  490. if (packetize_data(fw->data, fw->size))
  491. /* Incase something goes wrong when we are
  492. * in middle of packetizing the data, we
  493. * need to free up whatever packets might
  494. * have been created before we quit.
  495. */
  496. packet_empty_list();
  497. } else
  498. pr_debug("invalid image type specified.\n");
  499. spin_unlock(&rbu_data.lock);
  500. out:
  501. release_firmware(fw);
  502. }
  503. static ssize_t read_rbu_image_type(struct kobject *kobj,
  504. struct bin_attribute *bin_attr,
  505. char *buffer, loff_t pos, size_t count)
  506. {
  507. int size = 0;
  508. if (!pos)
  509. size = scnprintf(buffer, count, "%s\n", image_type);
  510. return size;
  511. }
  512. static ssize_t write_rbu_image_type(struct kobject *kobj,
  513. struct bin_attribute *bin_attr,
  514. char *buffer, loff_t pos, size_t count)
  515. {
  516. int rc = count;
  517. int req_firm_rc = 0;
  518. int i;
  519. spin_lock(&rbu_data.lock);
  520. /*
  521. * Find the first newline or space
  522. */
  523. for (i = 0; i < count; ++i)
  524. if (buffer[i] == '\n' || buffer[i] == ' ') {
  525. buffer[i] = '\0';
  526. break;
  527. }
  528. if (i == count)
  529. buffer[count] = '\0';
  530. if (strstr(buffer, "mono"))
  531. strcpy(image_type, "mono");
  532. else if (strstr(buffer, "packet"))
  533. strcpy(image_type, "packet");
  534. else if (strstr(buffer, "init")) {
  535. /*
  536. * If due to the user error the driver gets in a bad
  537. * state where even though it is loaded , the
  538. * /sys/class/firmware/dell_rbu entries are missing.
  539. * to cover this situation the user can recreate entries
  540. * by writing init to image_type.
  541. */
  542. if (!rbu_data.entry_created) {
  543. spin_unlock(&rbu_data.lock);
  544. req_firm_rc = request_firmware_nowait(THIS_MODULE,
  545. FW_ACTION_NOHOTPLUG, "dell_rbu",
  546. &rbu_device->dev, GFP_KERNEL, &context,
  547. callbackfn_rbu);
  548. if (req_firm_rc) {
  549. printk(KERN_ERR
  550. "dell_rbu:%s request_firmware_nowait"
  551. " failed %d\n", __func__, rc);
  552. rc = -EIO;
  553. } else
  554. rbu_data.entry_created = 1;
  555. spin_lock(&rbu_data.lock);
  556. }
  557. } else {
  558. printk(KERN_WARNING "dell_rbu: image_type is invalid\n");
  559. spin_unlock(&rbu_data.lock);
  560. return -EINVAL;
  561. }
  562. /* we must free all previous allocations */
  563. packet_empty_list();
  564. img_update_free();
  565. spin_unlock(&rbu_data.lock);
  566. return rc;
  567. }
  568. static ssize_t read_rbu_packet_size(struct kobject *kobj,
  569. struct bin_attribute *bin_attr,
  570. char *buffer, loff_t pos, size_t count)
  571. {
  572. int size = 0;
  573. if (!pos) {
  574. spin_lock(&rbu_data.lock);
  575. size = scnprintf(buffer, count, "%lu\n", rbu_data.packetsize);
  576. spin_unlock(&rbu_data.lock);
  577. }
  578. return size;
  579. }
  580. static ssize_t write_rbu_packet_size(struct kobject *kobj,
  581. struct bin_attribute *bin_attr,
  582. char *buffer, loff_t pos, size_t count)
  583. {
  584. unsigned long temp;
  585. spin_lock(&rbu_data.lock);
  586. packet_empty_list();
  587. sscanf(buffer, "%lu", &temp);
  588. if (temp < 0xffffffff)
  589. rbu_data.packetsize = temp;
  590. spin_unlock(&rbu_data.lock);
  591. return count;
  592. }
  593. static struct bin_attribute rbu_data_attr = {
  594. .attr = {.name = "data", .mode = 0444},
  595. .read = read_rbu_data,
  596. };
  597. static struct bin_attribute rbu_image_type_attr = {
  598. .attr = {.name = "image_type", .mode = 0644},
  599. .read = read_rbu_image_type,
  600. .write = write_rbu_image_type,
  601. };
  602. static struct bin_attribute rbu_packet_size_attr = {
  603. .attr = {.name = "packet_size", .mode = 0644},
  604. .read = read_rbu_packet_size,
  605. .write = write_rbu_packet_size,
  606. };
  607. static int __init dcdrbu_init(void)
  608. {
  609. int rc;
  610. spin_lock_init(&rbu_data.lock);
  611. init_packet_head();
  612. rbu_device = platform_device_register_simple("dell_rbu", -1, NULL, 0);
  613. if (IS_ERR(rbu_device)) {
  614. printk(KERN_ERR
  615. "dell_rbu:%s:platform_device_register_simple "
  616. "failed\n", __func__);
  617. return PTR_ERR(rbu_device);
  618. }
  619. rc = sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_data_attr);
  620. if (rc)
  621. goto out_devreg;
  622. rc = sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_image_type_attr);
  623. if (rc)
  624. goto out_data;
  625. rc = sysfs_create_bin_file(&rbu_device->dev.kobj,
  626. &rbu_packet_size_attr);
  627. if (rc)
  628. goto out_imtype;
  629. rbu_data.entry_created = 0;
  630. return 0;
  631. out_imtype:
  632. sysfs_remove_bin_file(&rbu_device->dev.kobj, &rbu_image_type_attr);
  633. out_data:
  634. sysfs_remove_bin_file(&rbu_device->dev.kobj, &rbu_data_attr);
  635. out_devreg:
  636. platform_device_unregister(rbu_device);
  637. return rc;
  638. }
  639. static __exit void dcdrbu_exit(void)
  640. {
  641. spin_lock(&rbu_data.lock);
  642. packet_empty_list();
  643. img_update_free();
  644. spin_unlock(&rbu_data.lock);
  645. platform_device_unregister(rbu_device);
  646. }
  647. module_exit(dcdrbu_exit);
  648. module_init(dcdrbu_init);
  649. /* vim:noet:ts=8:sw=8
  650. */