bus.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. /*
  2. * ISHTP bus driver
  3. *
  4. * Copyright (c) 2012-2016, 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. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/device.h>
  19. #include <linux/sched.h>
  20. #include <linux/slab.h>
  21. #include "bus.h"
  22. #include "ishtp-dev.h"
  23. #include "client.h"
  24. #include "hbm.h"
  25. static int ishtp_use_dma;
  26. module_param_named(ishtp_use_dma, ishtp_use_dma, int, 0600);
  27. MODULE_PARM_DESC(ishtp_use_dma, "Use DMA to send messages");
  28. #define to_ishtp_cl_driver(d) container_of(d, struct ishtp_cl_driver, driver)
  29. #define to_ishtp_cl_device(d) container_of(d, struct ishtp_cl_device, dev)
  30. static bool ishtp_device_ready;
  31. /**
  32. * ishtp_recv() - process ishtp message
  33. * @dev: ishtp device
  34. *
  35. * If a message with valid header and size is received, then
  36. * this function calls appropriate handler. The host or firmware
  37. * address is zero, then they are host bus management message,
  38. * otherwise they are message fo clients.
  39. */
  40. void ishtp_recv(struct ishtp_device *dev)
  41. {
  42. uint32_t msg_hdr;
  43. struct ishtp_msg_hdr *ishtp_hdr;
  44. /* Read ISHTP header dword */
  45. msg_hdr = dev->ops->ishtp_read_hdr(dev);
  46. if (!msg_hdr)
  47. return;
  48. dev->ops->sync_fw_clock(dev);
  49. ishtp_hdr = (struct ishtp_msg_hdr *)&msg_hdr;
  50. dev->ishtp_msg_hdr = msg_hdr;
  51. /* Sanity check: ISHTP frag. length in header */
  52. if (ishtp_hdr->length > dev->mtu) {
  53. dev_err(dev->devc,
  54. "ISHTP hdr - bad length: %u; dropped [%08X]\n",
  55. (unsigned int)ishtp_hdr->length, msg_hdr);
  56. return;
  57. }
  58. /* ISHTP bus message */
  59. if (!ishtp_hdr->host_addr && !ishtp_hdr->fw_addr)
  60. recv_hbm(dev, ishtp_hdr);
  61. /* ISHTP fixed-client message */
  62. else if (!ishtp_hdr->host_addr)
  63. recv_fixed_cl_msg(dev, ishtp_hdr);
  64. else
  65. /* ISHTP client message */
  66. recv_ishtp_cl_msg(dev, ishtp_hdr);
  67. }
  68. EXPORT_SYMBOL(ishtp_recv);
  69. /**
  70. * ishtp_send_msg() - Send ishtp message
  71. * @dev: ishtp device
  72. * @hdr: Message header
  73. * @msg: Message contents
  74. * @ipc_send_compl: completion callback
  75. * @ipc_send_compl_prm: completion callback parameter
  76. *
  77. * Send a multi fragment message via IPC. After sending the first fragment
  78. * the completion callback is called to schedule transmit of next fragment.
  79. *
  80. * Return: This returns IPC send message status.
  81. */
  82. int ishtp_send_msg(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr,
  83. void *msg, void(*ipc_send_compl)(void *),
  84. void *ipc_send_compl_prm)
  85. {
  86. unsigned char ipc_msg[IPC_FULL_MSG_SIZE];
  87. uint32_t drbl_val;
  88. drbl_val = dev->ops->ipc_get_header(dev, hdr->length +
  89. sizeof(struct ishtp_msg_hdr),
  90. 1);
  91. memcpy(ipc_msg, &drbl_val, sizeof(uint32_t));
  92. memcpy(ipc_msg + sizeof(uint32_t), hdr, sizeof(uint32_t));
  93. memcpy(ipc_msg + 2 * sizeof(uint32_t), msg, hdr->length);
  94. return dev->ops->write(dev, ipc_send_compl, ipc_send_compl_prm,
  95. ipc_msg, 2 * sizeof(uint32_t) + hdr->length);
  96. }
  97. /**
  98. * ishtp_write_message() - Send ishtp single fragment message
  99. * @dev: ishtp device
  100. * @hdr: Message header
  101. * @buf: message data
  102. *
  103. * Send a single fragment message via IPC. This returns IPC send message
  104. * status.
  105. *
  106. * Return: This returns IPC send message status.
  107. */
  108. int ishtp_write_message(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr,
  109. unsigned char *buf)
  110. {
  111. return ishtp_send_msg(dev, hdr, buf, NULL, NULL);
  112. }
  113. /**
  114. * ishtp_fw_cl_by_uuid() - locate index of fw client
  115. * @dev: ishtp device
  116. * @uuid: uuid of the client to search
  117. *
  118. * Search firmware client using UUID.
  119. *
  120. * Return: fw client index or -ENOENT if not found
  121. */
  122. int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const uuid_le *uuid)
  123. {
  124. int i, res = -ENOENT;
  125. for (i = 0; i < dev->fw_clients_num; ++i) {
  126. if (uuid_le_cmp(*uuid, dev->fw_clients[i].props.protocol_name)
  127. == 0) {
  128. res = i;
  129. break;
  130. }
  131. }
  132. return res;
  133. }
  134. EXPORT_SYMBOL(ishtp_fw_cl_by_uuid);
  135. /**
  136. * ishtp_fw_cl_by_id() - return index to fw_clients for client_id
  137. * @dev: the ishtp device structure
  138. * @client_id: fw client id to search
  139. *
  140. * Search firmware client using client id.
  141. *
  142. * Return: index on success, -ENOENT on failure.
  143. */
  144. int ishtp_fw_cl_by_id(struct ishtp_device *dev, uint8_t client_id)
  145. {
  146. int i, res = -ENOENT;
  147. unsigned long flags;
  148. spin_lock_irqsave(&dev->fw_clients_lock, flags);
  149. for (i = 0; i < dev->fw_clients_num; i++) {
  150. if (dev->fw_clients[i].client_id == client_id) {
  151. res = i;
  152. break;
  153. }
  154. }
  155. spin_unlock_irqrestore(&dev->fw_clients_lock, flags);
  156. return res;
  157. }
  158. /**
  159. * ishtp_cl_device_probe() - Bus probe() callback
  160. * @dev: the device structure
  161. *
  162. * This is a bus probe callback and calls the drive probe function.
  163. *
  164. * Return: Return value from driver probe() call.
  165. */
  166. static int ishtp_cl_device_probe(struct device *dev)
  167. {
  168. struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
  169. struct ishtp_cl_driver *driver;
  170. if (!device)
  171. return 0;
  172. driver = to_ishtp_cl_driver(dev->driver);
  173. if (!driver || !driver->probe)
  174. return -ENODEV;
  175. return driver->probe(device);
  176. }
  177. /**
  178. * ishtp_cl_device_remove() - Bus remove() callback
  179. * @dev: the device structure
  180. *
  181. * This is a bus remove callback and calls the drive remove function.
  182. * Since the ISH driver model supports only built in, this is
  183. * primarily can be called during pci driver init failure.
  184. *
  185. * Return: Return value from driver remove() call.
  186. */
  187. static int ishtp_cl_device_remove(struct device *dev)
  188. {
  189. struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
  190. struct ishtp_cl_driver *driver;
  191. if (!device || !dev->driver)
  192. return 0;
  193. if (device->event_cb) {
  194. device->event_cb = NULL;
  195. cancel_work_sync(&device->event_work);
  196. }
  197. driver = to_ishtp_cl_driver(dev->driver);
  198. if (!driver->remove) {
  199. dev->driver = NULL;
  200. return 0;
  201. }
  202. return driver->remove(device);
  203. }
  204. /**
  205. * ishtp_cl_device_suspend() - Bus suspend callback
  206. * @dev: device
  207. *
  208. * Called during device suspend process.
  209. *
  210. * Return: Return value from driver suspend() call.
  211. */
  212. static int ishtp_cl_device_suspend(struct device *dev)
  213. {
  214. struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
  215. struct ishtp_cl_driver *driver;
  216. int ret = 0;
  217. if (!device)
  218. return 0;
  219. driver = to_ishtp_cl_driver(dev->driver);
  220. if (driver && driver->driver.pm) {
  221. if (driver->driver.pm->suspend)
  222. ret = driver->driver.pm->suspend(dev);
  223. }
  224. return ret;
  225. }
  226. /**
  227. * ishtp_cl_device_resume() - Bus resume callback
  228. * @dev: device
  229. *
  230. * Called during device resume process.
  231. *
  232. * Return: Return value from driver resume() call.
  233. */
  234. static int ishtp_cl_device_resume(struct device *dev)
  235. {
  236. struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
  237. struct ishtp_cl_driver *driver;
  238. int ret = 0;
  239. if (!device)
  240. return 0;
  241. /*
  242. * When ISH needs hard reset, it is done asynchrnously, hence bus
  243. * resume will be called before full ISH resume
  244. */
  245. if (device->ishtp_dev->resume_flag)
  246. return 0;
  247. driver = to_ishtp_cl_driver(dev->driver);
  248. if (driver && driver->driver.pm) {
  249. if (driver->driver.pm->resume)
  250. ret = driver->driver.pm->resume(dev);
  251. }
  252. return ret;
  253. }
  254. /**
  255. * ishtp_cl_device_reset() - Reset callback
  256. * @device: ishtp client device instance
  257. *
  258. * This is a callback when HW reset is done and the device need
  259. * reinit.
  260. *
  261. * Return: Return value from driver reset() call.
  262. */
  263. static int ishtp_cl_device_reset(struct ishtp_cl_device *device)
  264. {
  265. struct ishtp_cl_driver *driver;
  266. int ret = 0;
  267. device->event_cb = NULL;
  268. cancel_work_sync(&device->event_work);
  269. driver = to_ishtp_cl_driver(device->dev.driver);
  270. if (driver && driver->reset)
  271. ret = driver->reset(device);
  272. return ret;
  273. }
  274. static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
  275. char *buf)
  276. {
  277. int len;
  278. len = snprintf(buf, PAGE_SIZE, "ishtp:%s\n", dev_name(dev));
  279. return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
  280. }
  281. static struct device_attribute ishtp_cl_dev_attrs[] = {
  282. __ATTR_RO(modalias),
  283. __ATTR_NULL,
  284. };
  285. static int ishtp_cl_uevent(struct device *dev, struct kobj_uevent_env *env)
  286. {
  287. if (add_uevent_var(env, "MODALIAS=ishtp:%s", dev_name(dev)))
  288. return -ENOMEM;
  289. return 0;
  290. }
  291. static const struct dev_pm_ops ishtp_cl_bus_dev_pm_ops = {
  292. /* Suspend callbacks */
  293. .suspend = ishtp_cl_device_suspend,
  294. .resume = ishtp_cl_device_resume,
  295. /* Hibernate callbacks */
  296. .freeze = ishtp_cl_device_suspend,
  297. .thaw = ishtp_cl_device_resume,
  298. .restore = ishtp_cl_device_resume,
  299. };
  300. static struct bus_type ishtp_cl_bus_type = {
  301. .name = "ishtp",
  302. .dev_attrs = ishtp_cl_dev_attrs,
  303. .probe = ishtp_cl_device_probe,
  304. .remove = ishtp_cl_device_remove,
  305. .pm = &ishtp_cl_bus_dev_pm_ops,
  306. .uevent = ishtp_cl_uevent,
  307. };
  308. static void ishtp_cl_dev_release(struct device *dev)
  309. {
  310. kfree(to_ishtp_cl_device(dev));
  311. }
  312. static struct device_type ishtp_cl_device_type = {
  313. .release = ishtp_cl_dev_release,
  314. };
  315. /**
  316. * ishtp_bus_add_device() - Function to create device on bus
  317. * @dev: ishtp device
  318. * @uuid: uuid of the client
  319. * @name: Name of the client
  320. *
  321. * Allocate ISHTP bus client device, attach it to uuid
  322. * and register with ISHTP bus.
  323. *
  324. * Return: ishtp_cl_device pointer or NULL on failure
  325. */
  326. static struct ishtp_cl_device *ishtp_bus_add_device(struct ishtp_device *dev,
  327. uuid_le uuid, char *name)
  328. {
  329. struct ishtp_cl_device *device;
  330. int status;
  331. unsigned long flags;
  332. spin_lock_irqsave(&dev->device_list_lock, flags);
  333. list_for_each_entry(device, &dev->device_list, device_link) {
  334. if (!strcmp(name, dev_name(&device->dev))) {
  335. device->fw_client = &dev->fw_clients[
  336. dev->fw_client_presentation_num - 1];
  337. spin_unlock_irqrestore(&dev->device_list_lock, flags);
  338. ishtp_cl_device_reset(device);
  339. return device;
  340. }
  341. }
  342. spin_unlock_irqrestore(&dev->device_list_lock, flags);
  343. device = kzalloc(sizeof(struct ishtp_cl_device), GFP_KERNEL);
  344. if (!device)
  345. return NULL;
  346. device->dev.parent = dev->devc;
  347. device->dev.bus = &ishtp_cl_bus_type;
  348. device->dev.type = &ishtp_cl_device_type;
  349. device->ishtp_dev = dev;
  350. device->fw_client =
  351. &dev->fw_clients[dev->fw_client_presentation_num - 1];
  352. dev_set_name(&device->dev, "%s", name);
  353. spin_lock_irqsave(&dev->device_list_lock, flags);
  354. list_add_tail(&device->device_link, &dev->device_list);
  355. spin_unlock_irqrestore(&dev->device_list_lock, flags);
  356. status = device_register(&device->dev);
  357. if (status) {
  358. spin_lock_irqsave(&dev->device_list_lock, flags);
  359. list_del(&device->device_link);
  360. spin_unlock_irqrestore(&dev->device_list_lock, flags);
  361. dev_err(dev->devc, "Failed to register ISHTP client device\n");
  362. kfree(device);
  363. return NULL;
  364. }
  365. ishtp_device_ready = true;
  366. return device;
  367. }
  368. /**
  369. * ishtp_bus_remove_device() - Function to relase device on bus
  370. * @device: client device instance
  371. *
  372. * This is a counterpart of ishtp_bus_add_device.
  373. * Device is unregistered.
  374. * the device structure is freed in 'ishtp_cl_dev_release' function
  375. * Called only during error in pci driver init path.
  376. */
  377. static void ishtp_bus_remove_device(struct ishtp_cl_device *device)
  378. {
  379. device_unregister(&device->dev);
  380. }
  381. /**
  382. * __ishtp_cl_driver_register() - Client driver register
  383. * @driver: the client driver instance
  384. * @owner: Owner of this driver module
  385. *
  386. * Once a client driver is probed, it created a client
  387. * instance and registers with the bus.
  388. *
  389. * Return: Return value of driver_register or -ENODEV if not ready
  390. */
  391. int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver,
  392. struct module *owner)
  393. {
  394. int err;
  395. if (!ishtp_device_ready)
  396. return -ENODEV;
  397. driver->driver.name = driver->name;
  398. driver->driver.owner = owner;
  399. driver->driver.bus = &ishtp_cl_bus_type;
  400. err = driver_register(&driver->driver);
  401. if (err)
  402. return err;
  403. return 0;
  404. }
  405. EXPORT_SYMBOL(__ishtp_cl_driver_register);
  406. /**
  407. * ishtp_cl_driver_unregister() - Client driver unregister
  408. * @driver: the client driver instance
  409. *
  410. * Unregister client during device removal process.
  411. */
  412. void ishtp_cl_driver_unregister(struct ishtp_cl_driver *driver)
  413. {
  414. driver_unregister(&driver->driver);
  415. }
  416. EXPORT_SYMBOL(ishtp_cl_driver_unregister);
  417. /**
  418. * ishtp_bus_event_work() - event work function
  419. * @work: work struct pointer
  420. *
  421. * Once an event is received for a client this work
  422. * function is called. If the device has registered a
  423. * callback then the callback is called.
  424. */
  425. static void ishtp_bus_event_work(struct work_struct *work)
  426. {
  427. struct ishtp_cl_device *device;
  428. device = container_of(work, struct ishtp_cl_device, event_work);
  429. if (device->event_cb)
  430. device->event_cb(device);
  431. }
  432. /**
  433. * ishtp_cl_bus_rx_event() - schedule event work
  434. * @device: client device instance
  435. *
  436. * Once an event is received for a client this schedules
  437. * a work function to process.
  438. */
  439. void ishtp_cl_bus_rx_event(struct ishtp_cl_device *device)
  440. {
  441. if (!device || !device->event_cb)
  442. return;
  443. if (device->event_cb)
  444. schedule_work(&device->event_work);
  445. }
  446. /**
  447. * ishtp_register_event_cb() - Register callback
  448. * @device: client device instance
  449. * @event_cb: Event processor for an client
  450. *
  451. * Register a callback for events, called from client driver
  452. *
  453. * Return: Return 0 or -EALREADY if already registered
  454. */
  455. int ishtp_register_event_cb(struct ishtp_cl_device *device,
  456. void (*event_cb)(struct ishtp_cl_device *))
  457. {
  458. if (device->event_cb)
  459. return -EALREADY;
  460. device->event_cb = event_cb;
  461. INIT_WORK(&device->event_work, ishtp_bus_event_work);
  462. return 0;
  463. }
  464. EXPORT_SYMBOL(ishtp_register_event_cb);
  465. /**
  466. * ishtp_get_device() - update usage count for the device
  467. * @cl_device: client device instance
  468. *
  469. * Increment the usage count. The device can't be deleted
  470. */
  471. void ishtp_get_device(struct ishtp_cl_device *cl_device)
  472. {
  473. cl_device->reference_count++;
  474. }
  475. EXPORT_SYMBOL(ishtp_get_device);
  476. /**
  477. * ishtp_put_device() - decrement usage count for the device
  478. * @cl_device: client device instance
  479. *
  480. * Decrement the usage count. The device can be deleted is count = 0
  481. */
  482. void ishtp_put_device(struct ishtp_cl_device *cl_device)
  483. {
  484. cl_device->reference_count--;
  485. }
  486. EXPORT_SYMBOL(ishtp_put_device);
  487. /**
  488. * ishtp_bus_new_client() - Create a new client
  489. * @dev: ISHTP device instance
  490. *
  491. * Once bus protocol enumerates a client, this is called
  492. * to add a device for the client.
  493. *
  494. * Return: 0 on success or error code on failure
  495. */
  496. int ishtp_bus_new_client(struct ishtp_device *dev)
  497. {
  498. int i;
  499. char *dev_name;
  500. struct ishtp_cl_device *cl_device;
  501. uuid_le device_uuid;
  502. /*
  503. * For all reported clients, create an unconnected client and add its
  504. * device to ISHTP bus.
  505. * If appropriate driver has loaded, this will trigger its probe().
  506. * Otherwise, probe() will be called when driver is loaded
  507. */
  508. i = dev->fw_client_presentation_num - 1;
  509. device_uuid = dev->fw_clients[i].props.protocol_name;
  510. dev_name = kasprintf(GFP_KERNEL, "{%pUL}", device_uuid.b);
  511. if (!dev_name)
  512. return -ENOMEM;
  513. cl_device = ishtp_bus_add_device(dev, device_uuid, dev_name);
  514. if (!cl_device) {
  515. kfree(dev_name);
  516. return -ENOENT;
  517. }
  518. kfree(dev_name);
  519. return 0;
  520. }
  521. /**
  522. * ishtp_cl_device_bind() - bind a device
  523. * @cl: ishtp client device
  524. *
  525. * Binds connected ishtp_cl to ISHTP bus device
  526. *
  527. * Return: 0 on success or fault code
  528. */
  529. int ishtp_cl_device_bind(struct ishtp_cl *cl)
  530. {
  531. struct ishtp_cl_device *cl_device;
  532. unsigned long flags;
  533. int rv;
  534. if (!cl->fw_client_id || cl->state != ISHTP_CL_CONNECTED)
  535. return -EFAULT;
  536. rv = -ENOENT;
  537. spin_lock_irqsave(&cl->dev->device_list_lock, flags);
  538. list_for_each_entry(cl_device, &cl->dev->device_list,
  539. device_link) {
  540. if (cl_device->fw_client->client_id == cl->fw_client_id) {
  541. cl->device = cl_device;
  542. rv = 0;
  543. break;
  544. }
  545. }
  546. spin_unlock_irqrestore(&cl->dev->device_list_lock, flags);
  547. return rv;
  548. }
  549. /**
  550. * ishtp_bus_remove_all_clients() - Remove all clients
  551. * @ishtp_dev: ishtp device
  552. * @warm_reset: Reset due to FW reset dure to errors or S3 suspend
  553. *
  554. * This is part of reset/remove flow. This function the main processing
  555. * only targets error processing, if the FW has forced reset or
  556. * error to remove connected clients. When warm reset the client devices are
  557. * not removed.
  558. */
  559. void ishtp_bus_remove_all_clients(struct ishtp_device *ishtp_dev,
  560. bool warm_reset)
  561. {
  562. struct ishtp_cl_device *cl_device, *n;
  563. struct ishtp_cl *cl;
  564. unsigned long flags;
  565. spin_lock_irqsave(&ishtp_dev->cl_list_lock, flags);
  566. list_for_each_entry(cl, &ishtp_dev->cl_list, link) {
  567. cl->state = ISHTP_CL_DISCONNECTED;
  568. /*
  569. * Wake any pending process. The waiter would check dev->state
  570. * and determine that it's not enabled already,
  571. * and will return error to its caller
  572. */
  573. wake_up_interruptible(&cl->wait_ctrl_res);
  574. /* Disband any pending read/write requests and free rb */
  575. ishtp_cl_flush_queues(cl);
  576. /* Remove all free and in_process rings, both Rx and Tx */
  577. ishtp_cl_free_rx_ring(cl);
  578. ishtp_cl_free_tx_ring(cl);
  579. /*
  580. * Free client and ISHTP bus client device structures
  581. * don't free host client because it is part of the OS fd
  582. * structure
  583. */
  584. }
  585. spin_unlock_irqrestore(&ishtp_dev->cl_list_lock, flags);
  586. /* Release DMA buffers for client messages */
  587. ishtp_cl_free_dma_buf(ishtp_dev);
  588. /* remove bus clients */
  589. spin_lock_irqsave(&ishtp_dev->device_list_lock, flags);
  590. list_for_each_entry_safe(cl_device, n, &ishtp_dev->device_list,
  591. device_link) {
  592. if (warm_reset && cl_device->reference_count)
  593. continue;
  594. list_del(&cl_device->device_link);
  595. spin_unlock_irqrestore(&ishtp_dev->device_list_lock, flags);
  596. ishtp_bus_remove_device(cl_device);
  597. spin_lock_irqsave(&ishtp_dev->device_list_lock, flags);
  598. }
  599. spin_unlock_irqrestore(&ishtp_dev->device_list_lock, flags);
  600. /* Free all client structures */
  601. spin_lock_irqsave(&ishtp_dev->fw_clients_lock, flags);
  602. kfree(ishtp_dev->fw_clients);
  603. ishtp_dev->fw_clients = NULL;
  604. ishtp_dev->fw_clients_num = 0;
  605. ishtp_dev->fw_client_presentation_num = 0;
  606. ishtp_dev->fw_client_index = 0;
  607. bitmap_zero(ishtp_dev->fw_clients_map, ISHTP_CLIENTS_MAX);
  608. spin_unlock_irqrestore(&ishtp_dev->fw_clients_lock, flags);
  609. }
  610. EXPORT_SYMBOL(ishtp_bus_remove_all_clients);
  611. /**
  612. * ishtp_reset_handler() - IPC reset handler
  613. * @dev: ishtp device
  614. *
  615. * ISHTP Handler for IPC_RESET notification
  616. */
  617. void ishtp_reset_handler(struct ishtp_device *dev)
  618. {
  619. unsigned long flags;
  620. /* Handle FW-initiated reset */
  621. dev->dev_state = ISHTP_DEV_RESETTING;
  622. /* Clear BH processing queue - no further HBMs */
  623. spin_lock_irqsave(&dev->rd_msg_spinlock, flags);
  624. dev->rd_msg_fifo_head = dev->rd_msg_fifo_tail = 0;
  625. spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags);
  626. /* Handle ISH FW reset against upper layers */
  627. ishtp_bus_remove_all_clients(dev, true);
  628. }
  629. EXPORT_SYMBOL(ishtp_reset_handler);
  630. /**
  631. * ishtp_reset_compl_handler() - Reset completion handler
  632. * @dev: ishtp device
  633. *
  634. * ISHTP handler for IPC_RESET sequence completion to start
  635. * host message bus start protocol sequence.
  636. */
  637. void ishtp_reset_compl_handler(struct ishtp_device *dev)
  638. {
  639. dev->dev_state = ISHTP_DEV_INIT_CLIENTS;
  640. dev->hbm_state = ISHTP_HBM_START;
  641. ishtp_hbm_start_req(dev);
  642. }
  643. EXPORT_SYMBOL(ishtp_reset_compl_handler);
  644. /**
  645. * ishtp_use_dma_transfer() - Function to use DMA
  646. *
  647. * This interface is used to enable usage of DMA
  648. *
  649. * Return non zero if DMA can be enabled
  650. */
  651. int ishtp_use_dma_transfer(void)
  652. {
  653. return ishtp_use_dma;
  654. }
  655. /**
  656. * ishtp_bus_register() - Function to register bus
  657. *
  658. * This register ishtp bus
  659. *
  660. * Return: Return output of bus_register
  661. */
  662. static int __init ishtp_bus_register(void)
  663. {
  664. return bus_register(&ishtp_cl_bus_type);
  665. }
  666. /**
  667. * ishtp_bus_unregister() - Function to unregister bus
  668. *
  669. * This unregister ishtp bus
  670. */
  671. static void __exit ishtp_bus_unregister(void)
  672. {
  673. bus_unregister(&ishtp_cl_bus_type);
  674. }
  675. module_init(ishtp_bus_register);
  676. module_exit(ishtp_bus_unregister);
  677. MODULE_LICENSE("GPL");