main.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /*
  2. *
  3. * Intel Management Engine Interface (Intel MEI) Linux driver
  4. * Copyright (c) 2003-2012, Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. */
  16. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/device.h>
  21. #include <linux/fs.h>
  22. #include <linux/errno.h>
  23. #include <linux/types.h>
  24. #include <linux/fcntl.h>
  25. #include <linux/aio.h>
  26. #include <linux/pci.h>
  27. #include <linux/poll.h>
  28. #include <linux/init.h>
  29. #include <linux/ioctl.h>
  30. #include <linux/cdev.h>
  31. #include <linux/sched.h>
  32. #include <linux/uuid.h>
  33. #include <linux/compat.h>
  34. #include <linux/jiffies.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/miscdevice.h>
  37. #include <linux/mei.h>
  38. #include "mei_dev.h"
  39. #include "hw-me.h"
  40. #include "client.h"
  41. /**
  42. * mei_open - the open function
  43. *
  44. * @inode: pointer to inode structure
  45. * @file: pointer to file structure
  46. e
  47. * returns 0 on success, <0 on error
  48. */
  49. static int mei_open(struct inode *inode, struct file *file)
  50. {
  51. struct miscdevice *misc = file->private_data;
  52. struct pci_dev *pdev;
  53. struct mei_cl *cl;
  54. struct mei_device *dev;
  55. int err;
  56. err = -ENODEV;
  57. if (!misc->parent)
  58. goto out;
  59. pdev = container_of(misc->parent, struct pci_dev, dev);
  60. dev = pci_get_drvdata(pdev);
  61. if (!dev)
  62. goto out;
  63. mutex_lock(&dev->device_lock);
  64. err = -ENOMEM;
  65. cl = mei_cl_allocate(dev);
  66. if (!cl)
  67. goto out_unlock;
  68. err = -ENODEV;
  69. if (dev->dev_state != MEI_DEV_ENABLED) {
  70. dev_dbg(&dev->pdev->dev, "dev_state != MEI_ENABLED dev_state = %s\n",
  71. mei_dev_state_str(dev->dev_state));
  72. goto out_unlock;
  73. }
  74. err = -EMFILE;
  75. if (dev->open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT) {
  76. dev_err(&dev->pdev->dev, "open_handle_count exceded %d",
  77. MEI_MAX_OPEN_HANDLE_COUNT);
  78. goto out_unlock;
  79. }
  80. err = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY);
  81. if (err)
  82. goto out_unlock;
  83. file->private_data = cl;
  84. mutex_unlock(&dev->device_lock);
  85. return nonseekable_open(inode, file);
  86. out_unlock:
  87. mutex_unlock(&dev->device_lock);
  88. kfree(cl);
  89. out:
  90. return err;
  91. }
  92. /**
  93. * mei_release - the release function
  94. *
  95. * @inode: pointer to inode structure
  96. * @file: pointer to file structure
  97. *
  98. * returns 0 on success, <0 on error
  99. */
  100. static int mei_release(struct inode *inode, struct file *file)
  101. {
  102. struct mei_cl *cl = file->private_data;
  103. struct mei_cl_cb *cb;
  104. struct mei_device *dev;
  105. int rets = 0;
  106. if (WARN_ON(!cl || !cl->dev))
  107. return -ENODEV;
  108. dev = cl->dev;
  109. mutex_lock(&dev->device_lock);
  110. if (cl == &dev->iamthif_cl) {
  111. rets = mei_amthif_release(dev, file);
  112. goto out;
  113. }
  114. if (cl->state == MEI_FILE_CONNECTED) {
  115. cl->state = MEI_FILE_DISCONNECTING;
  116. dev_dbg(&dev->pdev->dev,
  117. "disconnecting client host client = %d, "
  118. "ME client = %d\n",
  119. cl->host_client_id,
  120. cl->me_client_id);
  121. rets = mei_cl_disconnect(cl);
  122. }
  123. mei_cl_flush_queues(cl);
  124. dev_dbg(&dev->pdev->dev, "remove client host client = %d, ME client = %d\n",
  125. cl->host_client_id,
  126. cl->me_client_id);
  127. if (dev->open_handle_count > 0) {
  128. clear_bit(cl->host_client_id, dev->host_clients_map);
  129. dev->open_handle_count--;
  130. }
  131. mei_cl_unlink(cl);
  132. /* free read cb */
  133. cb = NULL;
  134. if (cl->read_cb) {
  135. cb = mei_cl_find_read_cb(cl);
  136. /* Remove entry from read list */
  137. if (cb)
  138. list_del(&cb->list);
  139. cb = cl->read_cb;
  140. cl->read_cb = NULL;
  141. }
  142. file->private_data = NULL;
  143. if (cb) {
  144. mei_io_cb_free(cb);
  145. cb = NULL;
  146. }
  147. kfree(cl);
  148. out:
  149. mutex_unlock(&dev->device_lock);
  150. return rets;
  151. }
  152. /**
  153. * mei_read - the read function.
  154. *
  155. * @file: pointer to file structure
  156. * @ubuf: pointer to user buffer
  157. * @length: buffer length
  158. * @offset: data offset in buffer
  159. *
  160. * returns >=0 data length on success , <0 on error
  161. */
  162. static ssize_t mei_read(struct file *file, char __user *ubuf,
  163. size_t length, loff_t *offset)
  164. {
  165. struct mei_cl *cl = file->private_data;
  166. struct mei_cl_cb *cb_pos = NULL;
  167. struct mei_cl_cb *cb = NULL;
  168. struct mei_device *dev;
  169. int i;
  170. int rets;
  171. int err;
  172. if (WARN_ON(!cl || !cl->dev))
  173. return -ENODEV;
  174. dev = cl->dev;
  175. mutex_lock(&dev->device_lock);
  176. if (dev->dev_state != MEI_DEV_ENABLED) {
  177. rets = -ENODEV;
  178. goto out;
  179. }
  180. if ((cl->sm_state & MEI_WD_STATE_INDEPENDENCE_MSG_SENT) == 0) {
  181. /* Do not allow to read watchdog client */
  182. i = mei_me_cl_by_uuid(dev, &mei_wd_guid);
  183. if (i >= 0) {
  184. struct mei_me_client *me_client = &dev->me_clients[i];
  185. if (cl->me_client_id == me_client->client_id) {
  186. rets = -EBADF;
  187. goto out;
  188. }
  189. }
  190. } else {
  191. cl->sm_state &= ~MEI_WD_STATE_INDEPENDENCE_MSG_SENT;
  192. }
  193. if (cl == &dev->iamthif_cl) {
  194. rets = mei_amthif_read(dev, file, ubuf, length, offset);
  195. goto out;
  196. }
  197. if (cl->read_cb && cl->read_cb->buf_idx > *offset) {
  198. cb = cl->read_cb;
  199. goto copy_buffer;
  200. } else if (cl->read_cb && cl->read_cb->buf_idx > 0 &&
  201. cl->read_cb->buf_idx <= *offset) {
  202. cb = cl->read_cb;
  203. rets = 0;
  204. goto free;
  205. } else if ((!cl->read_cb || !cl->read_cb->buf_idx) && *offset > 0) {
  206. /*Offset needs to be cleaned for contiguous reads*/
  207. *offset = 0;
  208. rets = 0;
  209. goto out;
  210. }
  211. err = mei_cl_read_start(cl, length);
  212. if (err && err != -EBUSY) {
  213. dev_dbg(&dev->pdev->dev,
  214. "mei start read failure with status = %d\n", err);
  215. rets = err;
  216. goto out;
  217. }
  218. if (MEI_READ_COMPLETE != cl->reading_state &&
  219. !waitqueue_active(&cl->rx_wait)) {
  220. if (file->f_flags & O_NONBLOCK) {
  221. rets = -EAGAIN;
  222. goto out;
  223. }
  224. mutex_unlock(&dev->device_lock);
  225. if (wait_event_interruptible(cl->rx_wait,
  226. (MEI_READ_COMPLETE == cl->reading_state ||
  227. MEI_FILE_INITIALIZING == cl->state ||
  228. MEI_FILE_DISCONNECTED == cl->state ||
  229. MEI_FILE_DISCONNECTING == cl->state))) {
  230. if (signal_pending(current))
  231. return -EINTR;
  232. return -ERESTARTSYS;
  233. }
  234. mutex_lock(&dev->device_lock);
  235. if (MEI_FILE_INITIALIZING == cl->state ||
  236. MEI_FILE_DISCONNECTED == cl->state ||
  237. MEI_FILE_DISCONNECTING == cl->state) {
  238. rets = -EBUSY;
  239. goto out;
  240. }
  241. }
  242. cb = cl->read_cb;
  243. if (!cb) {
  244. rets = -ENODEV;
  245. goto out;
  246. }
  247. if (cl->reading_state != MEI_READ_COMPLETE) {
  248. rets = 0;
  249. goto out;
  250. }
  251. /* now copy the data to user space */
  252. copy_buffer:
  253. dev_dbg(&dev->pdev->dev, "buf.size = %d buf.idx= %ld\n",
  254. cb->response_buffer.size, cb->buf_idx);
  255. if (length == 0 || ubuf == NULL || *offset > cb->buf_idx) {
  256. rets = -EMSGSIZE;
  257. goto free;
  258. }
  259. /* length is being truncated to PAGE_SIZE,
  260. * however buf_idx may point beyond that */
  261. length = min_t(size_t, length, cb->buf_idx - *offset);
  262. if (copy_to_user(ubuf, cb->response_buffer.data + *offset, length)) {
  263. rets = -EFAULT;
  264. goto free;
  265. }
  266. rets = length;
  267. *offset += length;
  268. if ((unsigned long)*offset < cb->buf_idx)
  269. goto out;
  270. free:
  271. cb_pos = mei_cl_find_read_cb(cl);
  272. /* Remove entry from read list */
  273. if (cb_pos)
  274. list_del(&cb_pos->list);
  275. mei_io_cb_free(cb);
  276. cl->reading_state = MEI_IDLE;
  277. cl->read_cb = NULL;
  278. out:
  279. dev_dbg(&dev->pdev->dev, "end mei read rets= %d\n", rets);
  280. mutex_unlock(&dev->device_lock);
  281. return rets;
  282. }
  283. /**
  284. * mei_write - the write function.
  285. *
  286. * @file: pointer to file structure
  287. * @ubuf: pointer to user buffer
  288. * @length: buffer length
  289. * @offset: data offset in buffer
  290. *
  291. * returns >=0 data length on success , <0 on error
  292. */
  293. static ssize_t mei_write(struct file *file, const char __user *ubuf,
  294. size_t length, loff_t *offset)
  295. {
  296. struct mei_cl *cl = file->private_data;
  297. struct mei_cl_cb *write_cb = NULL;
  298. struct mei_device *dev;
  299. unsigned long timeout = 0;
  300. int rets;
  301. int id;
  302. if (WARN_ON(!cl || !cl->dev))
  303. return -ENODEV;
  304. dev = cl->dev;
  305. mutex_lock(&dev->device_lock);
  306. if (dev->dev_state != MEI_DEV_ENABLED) {
  307. rets = -ENODEV;
  308. goto out;
  309. }
  310. id = mei_me_cl_by_id(dev, cl->me_client_id);
  311. if (id < 0) {
  312. rets = -ENODEV;
  313. goto out;
  314. }
  315. if (length > dev->me_clients[id].props.max_msg_length || length <= 0) {
  316. rets = -EMSGSIZE;
  317. goto out;
  318. }
  319. if (cl->state != MEI_FILE_CONNECTED) {
  320. dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d",
  321. cl->host_client_id, cl->me_client_id);
  322. rets = -ENODEV;
  323. goto out;
  324. }
  325. if (cl == &dev->iamthif_cl) {
  326. write_cb = mei_amthif_find_read_list_entry(dev, file);
  327. if (write_cb) {
  328. timeout = write_cb->read_time +
  329. mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER);
  330. if (time_after(jiffies, timeout) ||
  331. cl->reading_state == MEI_READ_COMPLETE) {
  332. *offset = 0;
  333. list_del(&write_cb->list);
  334. mei_io_cb_free(write_cb);
  335. write_cb = NULL;
  336. }
  337. }
  338. }
  339. /* free entry used in read */
  340. if (cl->reading_state == MEI_READ_COMPLETE) {
  341. *offset = 0;
  342. write_cb = mei_cl_find_read_cb(cl);
  343. if (write_cb) {
  344. list_del(&write_cb->list);
  345. mei_io_cb_free(write_cb);
  346. write_cb = NULL;
  347. cl->reading_state = MEI_IDLE;
  348. cl->read_cb = NULL;
  349. }
  350. } else if (cl->reading_state == MEI_IDLE)
  351. *offset = 0;
  352. write_cb = mei_io_cb_init(cl, file);
  353. if (!write_cb) {
  354. dev_err(&dev->pdev->dev, "write cb allocation failed\n");
  355. rets = -ENOMEM;
  356. goto out;
  357. }
  358. rets = mei_io_cb_alloc_req_buf(write_cb, length);
  359. if (rets)
  360. goto out;
  361. rets = copy_from_user(write_cb->request_buffer.data, ubuf, length);
  362. if (rets)
  363. goto out;
  364. cl->sm_state = 0;
  365. if (length == 4 &&
  366. ((memcmp(mei_wd_state_independence_msg[0],
  367. write_cb->request_buffer.data, 4) == 0) ||
  368. (memcmp(mei_wd_state_independence_msg[1],
  369. write_cb->request_buffer.data, 4) == 0) ||
  370. (memcmp(mei_wd_state_independence_msg[2],
  371. write_cb->request_buffer.data, 4) == 0)))
  372. cl->sm_state |= MEI_WD_STATE_INDEPENDENCE_MSG_SENT;
  373. if (cl == &dev->iamthif_cl) {
  374. rets = mei_amthif_write(dev, write_cb);
  375. if (rets) {
  376. dev_err(&dev->pdev->dev,
  377. "amthif write failed with status = %d\n", rets);
  378. goto out;
  379. }
  380. mutex_unlock(&dev->device_lock);
  381. return length;
  382. }
  383. rets = mei_cl_write(cl, write_cb, false);
  384. out:
  385. mutex_unlock(&dev->device_lock);
  386. if (rets < 0)
  387. mei_io_cb_free(write_cb);
  388. return rets;
  389. }
  390. /**
  391. * mei_ioctl_connect_client - the connect to fw client IOCTL function
  392. *
  393. * @dev: the device structure
  394. * @data: IOCTL connect data, input and output parameters
  395. * @file: private data of the file object
  396. *
  397. * Locking: called under "dev->device_lock" lock
  398. *
  399. * returns 0 on success, <0 on failure.
  400. */
  401. static int mei_ioctl_connect_client(struct file *file,
  402. struct mei_connect_client_data *data)
  403. {
  404. struct mei_device *dev;
  405. struct mei_client *client;
  406. struct mei_cl *cl;
  407. int i;
  408. int rets;
  409. cl = file->private_data;
  410. if (WARN_ON(!cl || !cl->dev))
  411. return -ENODEV;
  412. dev = cl->dev;
  413. if (dev->dev_state != MEI_DEV_ENABLED) {
  414. rets = -ENODEV;
  415. goto end;
  416. }
  417. if (cl->state != MEI_FILE_INITIALIZING &&
  418. cl->state != MEI_FILE_DISCONNECTED) {
  419. rets = -EBUSY;
  420. goto end;
  421. }
  422. /* find ME client we're trying to connect to */
  423. i = mei_me_cl_by_uuid(dev, &data->in_client_uuid);
  424. if (i >= 0 && !dev->me_clients[i].props.fixed_address) {
  425. cl->me_client_id = dev->me_clients[i].client_id;
  426. cl->state = MEI_FILE_CONNECTING;
  427. }
  428. dev_dbg(&dev->pdev->dev, "Connect to FW Client ID = %d\n",
  429. cl->me_client_id);
  430. dev_dbg(&dev->pdev->dev, "FW Client - Protocol Version = %d\n",
  431. dev->me_clients[i].props.protocol_version);
  432. dev_dbg(&dev->pdev->dev, "FW Client - Max Msg Len = %d\n",
  433. dev->me_clients[i].props.max_msg_length);
  434. /* if we're connecting to amthif client then we will use the
  435. * existing connection
  436. */
  437. if (uuid_le_cmp(data->in_client_uuid, mei_amthif_guid) == 0) {
  438. dev_dbg(&dev->pdev->dev, "FW Client is amthi\n");
  439. if (dev->iamthif_cl.state != MEI_FILE_CONNECTED) {
  440. rets = -ENODEV;
  441. goto end;
  442. }
  443. clear_bit(cl->host_client_id, dev->host_clients_map);
  444. mei_cl_unlink(cl);
  445. kfree(cl);
  446. cl = NULL;
  447. file->private_data = &dev->iamthif_cl;
  448. client = &data->out_client_properties;
  449. client->max_msg_length =
  450. dev->me_clients[i].props.max_msg_length;
  451. client->protocol_version =
  452. dev->me_clients[i].props.protocol_version;
  453. rets = dev->iamthif_cl.status;
  454. goto end;
  455. }
  456. if (cl->state != MEI_FILE_CONNECTING) {
  457. rets = -ENODEV;
  458. goto end;
  459. }
  460. /* prepare the output buffer */
  461. client = &data->out_client_properties;
  462. client->max_msg_length = dev->me_clients[i].props.max_msg_length;
  463. client->protocol_version = dev->me_clients[i].props.protocol_version;
  464. dev_dbg(&dev->pdev->dev, "Can connect?\n");
  465. rets = mei_cl_connect(cl, file);
  466. end:
  467. dev_dbg(&dev->pdev->dev, "free connect cb memory.");
  468. return rets;
  469. }
  470. /**
  471. * mei_ioctl - the IOCTL function
  472. *
  473. * @file: pointer to file structure
  474. * @cmd: ioctl command
  475. * @data: pointer to mei message structure
  476. *
  477. * returns 0 on success , <0 on error
  478. */
  479. static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data)
  480. {
  481. struct mei_device *dev;
  482. struct mei_cl *cl = file->private_data;
  483. struct mei_connect_client_data *connect_data = NULL;
  484. int rets;
  485. if (cmd != IOCTL_MEI_CONNECT_CLIENT)
  486. return -EINVAL;
  487. if (WARN_ON(!cl || !cl->dev))
  488. return -ENODEV;
  489. dev = cl->dev;
  490. dev_dbg(&dev->pdev->dev, "IOCTL cmd = 0x%x", cmd);
  491. mutex_lock(&dev->device_lock);
  492. if (dev->dev_state != MEI_DEV_ENABLED) {
  493. rets = -ENODEV;
  494. goto out;
  495. }
  496. dev_dbg(&dev->pdev->dev, ": IOCTL_MEI_CONNECT_CLIENT.\n");
  497. connect_data = kzalloc(sizeof(struct mei_connect_client_data),
  498. GFP_KERNEL);
  499. if (!connect_data) {
  500. rets = -ENOMEM;
  501. goto out;
  502. }
  503. dev_dbg(&dev->pdev->dev, "copy connect data from user\n");
  504. if (copy_from_user(connect_data, (char __user *)data,
  505. sizeof(struct mei_connect_client_data))) {
  506. dev_dbg(&dev->pdev->dev, "failed to copy data from userland\n");
  507. rets = -EFAULT;
  508. goto out;
  509. }
  510. rets = mei_ioctl_connect_client(file, connect_data);
  511. /* if all is ok, copying the data back to user. */
  512. if (rets)
  513. goto out;
  514. dev_dbg(&dev->pdev->dev, "copy connect data to user\n");
  515. if (copy_to_user((char __user *)data, connect_data,
  516. sizeof(struct mei_connect_client_data))) {
  517. dev_dbg(&dev->pdev->dev, "failed to copy data to userland\n");
  518. rets = -EFAULT;
  519. goto out;
  520. }
  521. out:
  522. kfree(connect_data);
  523. mutex_unlock(&dev->device_lock);
  524. return rets;
  525. }
  526. /**
  527. * mei_compat_ioctl - the compat IOCTL function
  528. *
  529. * @file: pointer to file structure
  530. * @cmd: ioctl command
  531. * @data: pointer to mei message structure
  532. *
  533. * returns 0 on success , <0 on error
  534. */
  535. #ifdef CONFIG_COMPAT
  536. static long mei_compat_ioctl(struct file *file,
  537. unsigned int cmd, unsigned long data)
  538. {
  539. return mei_ioctl(file, cmd, (unsigned long)compat_ptr(data));
  540. }
  541. #endif
  542. /**
  543. * mei_poll - the poll function
  544. *
  545. * @file: pointer to file structure
  546. * @wait: pointer to poll_table structure
  547. *
  548. * returns poll mask
  549. */
  550. static unsigned int mei_poll(struct file *file, poll_table *wait)
  551. {
  552. struct mei_cl *cl = file->private_data;
  553. struct mei_device *dev;
  554. unsigned int mask = 0;
  555. if (WARN_ON(!cl || !cl->dev))
  556. return mask;
  557. dev = cl->dev;
  558. mutex_lock(&dev->device_lock);
  559. if (dev->dev_state != MEI_DEV_ENABLED)
  560. goto out;
  561. if (cl == &dev->iamthif_cl) {
  562. mask = mei_amthif_poll(dev, file, wait);
  563. goto out;
  564. }
  565. mutex_unlock(&dev->device_lock);
  566. poll_wait(file, &cl->tx_wait, wait);
  567. mutex_lock(&dev->device_lock);
  568. if (MEI_WRITE_COMPLETE == cl->writing_state)
  569. mask |= (POLLIN | POLLRDNORM);
  570. out:
  571. mutex_unlock(&dev->device_lock);
  572. return mask;
  573. }
  574. /*
  575. * file operations structure will be used for mei char device.
  576. */
  577. static const struct file_operations mei_fops = {
  578. .owner = THIS_MODULE,
  579. .read = mei_read,
  580. .unlocked_ioctl = mei_ioctl,
  581. #ifdef CONFIG_COMPAT
  582. .compat_ioctl = mei_compat_ioctl,
  583. #endif
  584. .open = mei_open,
  585. .release = mei_release,
  586. .write = mei_write,
  587. .poll = mei_poll,
  588. .llseek = no_llseek
  589. };
  590. /*
  591. * Misc Device Struct
  592. */
  593. static struct miscdevice mei_misc_device = {
  594. .name = "mei",
  595. .fops = &mei_fops,
  596. .minor = MISC_DYNAMIC_MINOR,
  597. };
  598. int mei_register(struct mei_device *dev)
  599. {
  600. int ret;
  601. mei_misc_device.parent = &dev->pdev->dev;
  602. ret = misc_register(&mei_misc_device);
  603. if (ret)
  604. return ret;
  605. if (mei_dbgfs_register(dev, mei_misc_device.name))
  606. dev_err(&dev->pdev->dev, "cannot register debugfs\n");
  607. return 0;
  608. }
  609. EXPORT_SYMBOL_GPL(mei_register);
  610. void mei_deregister(struct mei_device *dev)
  611. {
  612. mei_dbgfs_deregister(dev);
  613. misc_deregister(&mei_misc_device);
  614. mei_misc_device.parent = NULL;
  615. }
  616. EXPORT_SYMBOL_GPL(mei_deregister);
  617. static int __init mei_init(void)
  618. {
  619. return mei_cl_bus_init();
  620. }
  621. static void __exit mei_exit(void)
  622. {
  623. mei_cl_bus_exit();
  624. }
  625. module_init(mei_init);
  626. module_exit(mei_exit);
  627. MODULE_AUTHOR("Intel Corporation");
  628. MODULE_DESCRIPTION("Intel(R) Management Engine Interface");
  629. MODULE_LICENSE("GPL v2");