main.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. *
  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);
  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, "cb->response_buffer size - %d\n",
  254. cb->response_buffer.size);
  255. dev_dbg(&dev->pdev->dev, "cb->buf_idx - %lu\n", cb->buf_idx);
  256. if (length == 0 || ubuf == NULL || *offset > cb->buf_idx) {
  257. rets = -EMSGSIZE;
  258. goto free;
  259. }
  260. /* length is being truncated to PAGE_SIZE,
  261. * however buf_idx may point beyond that */
  262. length = min_t(size_t, length, cb->buf_idx - *offset);
  263. if (copy_to_user(ubuf, cb->response_buffer.data + *offset, length)) {
  264. rets = -EFAULT;
  265. goto free;
  266. }
  267. rets = length;
  268. *offset += length;
  269. if ((unsigned long)*offset < cb->buf_idx)
  270. goto out;
  271. free:
  272. cb_pos = mei_cl_find_read_cb(cl);
  273. /* Remove entry from read list */
  274. if (cb_pos)
  275. list_del(&cb_pos->list);
  276. mei_io_cb_free(cb);
  277. cl->reading_state = MEI_IDLE;
  278. cl->read_cb = NULL;
  279. out:
  280. dev_dbg(&dev->pdev->dev, "end mei read rets= %d\n", rets);
  281. mutex_unlock(&dev->device_lock);
  282. return rets;
  283. }
  284. /**
  285. * mei_write - the write function.
  286. *
  287. * @file: pointer to file structure
  288. * @ubuf: pointer to user buffer
  289. * @length: buffer length
  290. * @offset: data offset in buffer
  291. *
  292. * returns >=0 data length on success , <0 on error
  293. */
  294. static ssize_t mei_write(struct file *file, const char __user *ubuf,
  295. size_t length, loff_t *offset)
  296. {
  297. struct mei_cl *cl = file->private_data;
  298. struct mei_cl_cb *write_cb = NULL;
  299. struct mei_device *dev;
  300. unsigned long timeout = 0;
  301. int rets;
  302. int id;
  303. if (WARN_ON(!cl || !cl->dev))
  304. return -ENODEV;
  305. dev = cl->dev;
  306. mutex_lock(&dev->device_lock);
  307. if (dev->dev_state != MEI_DEV_ENABLED) {
  308. rets = -ENODEV;
  309. goto out;
  310. }
  311. id = mei_me_cl_by_id(dev, cl->me_client_id);
  312. if (id < 0) {
  313. rets = -ENODEV;
  314. goto out;
  315. }
  316. if (length > dev->me_clients[id].props.max_msg_length || length <= 0) {
  317. rets = -EMSGSIZE;
  318. goto out;
  319. }
  320. if (cl->state != MEI_FILE_CONNECTED) {
  321. dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d",
  322. cl->host_client_id, cl->me_client_id);
  323. rets = -ENODEV;
  324. goto out;
  325. }
  326. if (cl == &dev->iamthif_cl) {
  327. write_cb = mei_amthif_find_read_list_entry(dev, file);
  328. if (write_cb) {
  329. timeout = write_cb->read_time +
  330. mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER);
  331. if (time_after(jiffies, timeout) ||
  332. cl->reading_state == MEI_READ_COMPLETE) {
  333. *offset = 0;
  334. list_del(&write_cb->list);
  335. mei_io_cb_free(write_cb);
  336. write_cb = NULL;
  337. }
  338. }
  339. }
  340. /* free entry used in read */
  341. if (cl->reading_state == MEI_READ_COMPLETE) {
  342. *offset = 0;
  343. write_cb = mei_cl_find_read_cb(cl);
  344. if (write_cb) {
  345. list_del(&write_cb->list);
  346. mei_io_cb_free(write_cb);
  347. write_cb = NULL;
  348. cl->reading_state = MEI_IDLE;
  349. cl->read_cb = NULL;
  350. }
  351. } else if (cl->reading_state == MEI_IDLE)
  352. *offset = 0;
  353. write_cb = mei_io_cb_init(cl, file);
  354. if (!write_cb) {
  355. dev_err(&dev->pdev->dev, "write cb allocation failed\n");
  356. rets = -ENOMEM;
  357. goto out;
  358. }
  359. rets = mei_io_cb_alloc_req_buf(write_cb, length);
  360. if (rets)
  361. goto out;
  362. rets = copy_from_user(write_cb->request_buffer.data, ubuf, length);
  363. if (rets)
  364. goto out;
  365. cl->sm_state = 0;
  366. if (length == 4 &&
  367. ((memcmp(mei_wd_state_independence_msg[0],
  368. write_cb->request_buffer.data, 4) == 0) ||
  369. (memcmp(mei_wd_state_independence_msg[1],
  370. write_cb->request_buffer.data, 4) == 0) ||
  371. (memcmp(mei_wd_state_independence_msg[2],
  372. write_cb->request_buffer.data, 4) == 0)))
  373. cl->sm_state |= MEI_WD_STATE_INDEPENDENCE_MSG_SENT;
  374. if (cl == &dev->iamthif_cl) {
  375. rets = mei_amthif_write(dev, write_cb);
  376. if (rets) {
  377. dev_err(&dev->pdev->dev,
  378. "amthif write failed with status = %d\n", rets);
  379. goto out;
  380. }
  381. mutex_unlock(&dev->device_lock);
  382. return length;
  383. }
  384. rets = mei_cl_write(cl, write_cb, false);
  385. out:
  386. mutex_unlock(&dev->device_lock);
  387. if (rets < 0)
  388. mei_io_cb_free(write_cb);
  389. return rets;
  390. }
  391. /**
  392. * mei_ioctl_connect_client - the connect to fw client IOCTL function
  393. *
  394. * @dev: the device structure
  395. * @data: IOCTL connect data, input and output parameters
  396. * @file: private data of the file object
  397. *
  398. * Locking: called under "dev->device_lock" lock
  399. *
  400. * returns 0 on success, <0 on failure.
  401. */
  402. static int mei_ioctl_connect_client(struct file *file,
  403. struct mei_connect_client_data *data)
  404. {
  405. struct mei_device *dev;
  406. struct mei_client *client;
  407. struct mei_cl *cl;
  408. int i;
  409. int rets;
  410. cl = file->private_data;
  411. if (WARN_ON(!cl || !cl->dev))
  412. return -ENODEV;
  413. dev = cl->dev;
  414. if (dev->dev_state != MEI_DEV_ENABLED) {
  415. rets = -ENODEV;
  416. goto end;
  417. }
  418. if (cl->state != MEI_FILE_INITIALIZING &&
  419. cl->state != MEI_FILE_DISCONNECTED) {
  420. rets = -EBUSY;
  421. goto end;
  422. }
  423. /* find ME client we're trying to connect to */
  424. i = mei_me_cl_by_uuid(dev, &data->in_client_uuid);
  425. if (i >= 0 && !dev->me_clients[i].props.fixed_address) {
  426. cl->me_client_id = dev->me_clients[i].client_id;
  427. cl->state = MEI_FILE_CONNECTING;
  428. }
  429. dev_dbg(&dev->pdev->dev, "Connect to FW Client ID = %d\n",
  430. cl->me_client_id);
  431. dev_dbg(&dev->pdev->dev, "FW Client - Protocol Version = %d\n",
  432. dev->me_clients[i].props.protocol_version);
  433. dev_dbg(&dev->pdev->dev, "FW Client - Max Msg Len = %d\n",
  434. dev->me_clients[i].props.max_msg_length);
  435. /* if we're connecting to amthif client then we will use the
  436. * existing connection
  437. */
  438. if (uuid_le_cmp(data->in_client_uuid, mei_amthif_guid) == 0) {
  439. dev_dbg(&dev->pdev->dev, "FW Client is amthi\n");
  440. if (dev->iamthif_cl.state != MEI_FILE_CONNECTED) {
  441. rets = -ENODEV;
  442. goto end;
  443. }
  444. clear_bit(cl->host_client_id, dev->host_clients_map);
  445. mei_cl_unlink(cl);
  446. kfree(cl);
  447. cl = NULL;
  448. file->private_data = &dev->iamthif_cl;
  449. client = &data->out_client_properties;
  450. client->max_msg_length =
  451. dev->me_clients[i].props.max_msg_length;
  452. client->protocol_version =
  453. dev->me_clients[i].props.protocol_version;
  454. rets = dev->iamthif_cl.status;
  455. goto end;
  456. }
  457. if (cl->state != MEI_FILE_CONNECTING) {
  458. rets = -ENODEV;
  459. goto end;
  460. }
  461. /* prepare the output buffer */
  462. client = &data->out_client_properties;
  463. client->max_msg_length = dev->me_clients[i].props.max_msg_length;
  464. client->protocol_version = dev->me_clients[i].props.protocol_version;
  465. dev_dbg(&dev->pdev->dev, "Can connect?\n");
  466. rets = mei_cl_connect(cl, file);
  467. end:
  468. dev_dbg(&dev->pdev->dev, "free connect cb memory.");
  469. return rets;
  470. }
  471. /**
  472. * mei_ioctl - the IOCTL function
  473. *
  474. * @file: pointer to file structure
  475. * @cmd: ioctl command
  476. * @data: pointer to mei message structure
  477. *
  478. * returns 0 on success , <0 on error
  479. */
  480. static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data)
  481. {
  482. struct mei_device *dev;
  483. struct mei_cl *cl = file->private_data;
  484. struct mei_connect_client_data *connect_data = NULL;
  485. int rets;
  486. if (cmd != IOCTL_MEI_CONNECT_CLIENT)
  487. return -EINVAL;
  488. if (WARN_ON(!cl || !cl->dev))
  489. return -ENODEV;
  490. dev = cl->dev;
  491. dev_dbg(&dev->pdev->dev, "IOCTL cmd = 0x%x", cmd);
  492. mutex_lock(&dev->device_lock);
  493. if (dev->dev_state != MEI_DEV_ENABLED) {
  494. rets = -ENODEV;
  495. goto out;
  496. }
  497. dev_dbg(&dev->pdev->dev, ": IOCTL_MEI_CONNECT_CLIENT.\n");
  498. connect_data = kzalloc(sizeof(struct mei_connect_client_data),
  499. GFP_KERNEL);
  500. if (!connect_data) {
  501. rets = -ENOMEM;
  502. goto out;
  503. }
  504. dev_dbg(&dev->pdev->dev, "copy connect data from user\n");
  505. if (copy_from_user(connect_data, (char __user *)data,
  506. sizeof(struct mei_connect_client_data))) {
  507. dev_dbg(&dev->pdev->dev, "failed to copy data from userland\n");
  508. rets = -EFAULT;
  509. goto out;
  510. }
  511. rets = mei_ioctl_connect_client(file, connect_data);
  512. /* if all is ok, copying the data back to user. */
  513. if (rets)
  514. goto out;
  515. dev_dbg(&dev->pdev->dev, "copy connect data to user\n");
  516. if (copy_to_user((char __user *)data, connect_data,
  517. sizeof(struct mei_connect_client_data))) {
  518. dev_dbg(&dev->pdev->dev, "failed to copy data to userland\n");
  519. rets = -EFAULT;
  520. goto out;
  521. }
  522. out:
  523. kfree(connect_data);
  524. mutex_unlock(&dev->device_lock);
  525. return rets;
  526. }
  527. /**
  528. * mei_compat_ioctl - the compat IOCTL function
  529. *
  530. * @file: pointer to file structure
  531. * @cmd: ioctl command
  532. * @data: pointer to mei message structure
  533. *
  534. * returns 0 on success , <0 on error
  535. */
  536. #ifdef CONFIG_COMPAT
  537. static long mei_compat_ioctl(struct file *file,
  538. unsigned int cmd, unsigned long data)
  539. {
  540. return mei_ioctl(file, cmd, (unsigned long)compat_ptr(data));
  541. }
  542. #endif
  543. /**
  544. * mei_poll - the poll function
  545. *
  546. * @file: pointer to file structure
  547. * @wait: pointer to poll_table structure
  548. *
  549. * returns poll mask
  550. */
  551. static unsigned int mei_poll(struct file *file, poll_table *wait)
  552. {
  553. struct mei_cl *cl = file->private_data;
  554. struct mei_device *dev;
  555. unsigned int mask = 0;
  556. if (WARN_ON(!cl || !cl->dev))
  557. return mask;
  558. dev = cl->dev;
  559. mutex_lock(&dev->device_lock);
  560. if (dev->dev_state != MEI_DEV_ENABLED)
  561. goto out;
  562. if (cl == &dev->iamthif_cl) {
  563. mask = mei_amthif_poll(dev, file, wait);
  564. goto out;
  565. }
  566. mutex_unlock(&dev->device_lock);
  567. poll_wait(file, &cl->tx_wait, wait);
  568. mutex_lock(&dev->device_lock);
  569. if (MEI_WRITE_COMPLETE == cl->writing_state)
  570. mask |= (POLLIN | POLLRDNORM);
  571. out:
  572. mutex_unlock(&dev->device_lock);
  573. return mask;
  574. }
  575. /*
  576. * file operations structure will be used for mei char device.
  577. */
  578. static const struct file_operations mei_fops = {
  579. .owner = THIS_MODULE,
  580. .read = mei_read,
  581. .unlocked_ioctl = mei_ioctl,
  582. #ifdef CONFIG_COMPAT
  583. .compat_ioctl = mei_compat_ioctl,
  584. #endif
  585. .open = mei_open,
  586. .release = mei_release,
  587. .write = mei_write,
  588. .poll = mei_poll,
  589. .llseek = no_llseek
  590. };
  591. /*
  592. * Misc Device Struct
  593. */
  594. static struct miscdevice mei_misc_device = {
  595. .name = "mei",
  596. .fops = &mei_fops,
  597. .minor = MISC_DYNAMIC_MINOR,
  598. };
  599. int mei_register(struct mei_device *dev)
  600. {
  601. int ret;
  602. mei_misc_device.parent = &dev->pdev->dev;
  603. ret = misc_register(&mei_misc_device);
  604. if (ret)
  605. return ret;
  606. if (mei_dbgfs_register(dev, mei_misc_device.name))
  607. dev_err(&dev->pdev->dev, "cannot register debugfs\n");
  608. return 0;
  609. }
  610. EXPORT_SYMBOL_GPL(mei_register);
  611. void mei_deregister(struct mei_device *dev)
  612. {
  613. mei_dbgfs_deregister(dev);
  614. misc_deregister(&mei_misc_device);
  615. mei_misc_device.parent = NULL;
  616. }
  617. EXPORT_SYMBOL_GPL(mei_deregister);
  618. static int __init mei_init(void)
  619. {
  620. return mei_cl_bus_init();
  621. }
  622. static void __exit mei_exit(void)
  623. {
  624. mei_cl_bus_exit();
  625. }
  626. module_init(mei_init);
  627. module_exit(mei_exit);
  628. MODULE_AUTHOR("Intel Corporation");
  629. MODULE_DESCRIPTION("Intel(R) Management Engine Interface");
  630. MODULE_LICENSE("GPL v2");