device-init.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. /*
  2. * PS3 device registration routines.
  3. *
  4. * Copyright (C) 2007 Sony Computer Entertainment Inc.
  5. * Copyright 2007 Sony Corp.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/delay.h>
  21. #include <linux/freezer.h>
  22. #include <linux/kernel.h>
  23. #include <linux/kthread.h>
  24. #include <linux/init.h>
  25. #include <asm/firmware.h>
  26. #include <asm/lv1call.h>
  27. #include <asm/ps3stor.h>
  28. #include "platform.h"
  29. /**
  30. * ps3_setup_gelic_device - Setup and register a gelic device instance.
  31. *
  32. * Allocates memory for a struct ps3_system_bus_device instance, initialises the
  33. * structure members, and registers the device instance with the system bus.
  34. */
  35. static int __init ps3_setup_gelic_device(
  36. const struct ps3_repository_device *repo)
  37. {
  38. int result;
  39. struct layout {
  40. struct ps3_system_bus_device dev;
  41. struct ps3_dma_region d_region;
  42. } *p;
  43. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  44. BUG_ON(repo->bus_type != PS3_BUS_TYPE_SB);
  45. BUG_ON(repo->dev_type != PS3_DEV_TYPE_SB_GELIC);
  46. p = kzalloc(sizeof(struct layout), GFP_KERNEL);
  47. if (!p) {
  48. result = -ENOMEM;
  49. goto fail_malloc;
  50. }
  51. p->dev.match_id = PS3_MATCH_ID_GELIC;
  52. p->dev.dev_type = PS3_DEVICE_TYPE_SB;
  53. p->dev.bus_id = repo->bus_id;
  54. p->dev.dev_id = repo->dev_id;
  55. p->dev.d_region = &p->d_region;
  56. result = ps3_repository_find_interrupt(repo,
  57. PS3_INTERRUPT_TYPE_EVENT_PORT, &p->dev.interrupt_id);
  58. if (result) {
  59. pr_debug("%s:%d ps3_repository_find_interrupt failed\n",
  60. __func__, __LINE__);
  61. goto fail_find_interrupt;
  62. }
  63. BUG_ON(p->dev.interrupt_id != 0);
  64. result = ps3_dma_region_init(&p->dev, p->dev.d_region, PS3_DMA_64K,
  65. PS3_DMA_OTHER, NULL, 0);
  66. if (result) {
  67. pr_debug("%s:%d ps3_dma_region_init failed\n",
  68. __func__, __LINE__);
  69. goto fail_dma_init;
  70. }
  71. result = ps3_system_bus_device_register(&p->dev);
  72. if (result) {
  73. pr_debug("%s:%d ps3_system_bus_device_register failed\n",
  74. __func__, __LINE__);
  75. goto fail_device_register;
  76. }
  77. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  78. return result;
  79. fail_device_register:
  80. fail_dma_init:
  81. fail_find_interrupt:
  82. kfree(p);
  83. fail_malloc:
  84. pr_debug(" <- %s:%d: fail.\n", __func__, __LINE__);
  85. return result;
  86. }
  87. static int __init_refok ps3_setup_uhc_device(
  88. const struct ps3_repository_device *repo, enum ps3_match_id match_id,
  89. enum ps3_interrupt_type interrupt_type, enum ps3_reg_type reg_type)
  90. {
  91. int result;
  92. struct layout {
  93. struct ps3_system_bus_device dev;
  94. struct ps3_dma_region d_region;
  95. struct ps3_mmio_region m_region;
  96. } *p;
  97. u64 bus_addr;
  98. u64 len;
  99. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  100. BUG_ON(repo->bus_type != PS3_BUS_TYPE_SB);
  101. BUG_ON(repo->dev_type != PS3_DEV_TYPE_SB_USB);
  102. p = kzalloc(sizeof(struct layout), GFP_KERNEL);
  103. if (!p) {
  104. result = -ENOMEM;
  105. goto fail_malloc;
  106. }
  107. p->dev.match_id = match_id;
  108. p->dev.dev_type = PS3_DEVICE_TYPE_SB;
  109. p->dev.bus_id = repo->bus_id;
  110. p->dev.dev_id = repo->dev_id;
  111. p->dev.d_region = &p->d_region;
  112. p->dev.m_region = &p->m_region;
  113. result = ps3_repository_find_interrupt(repo,
  114. interrupt_type, &p->dev.interrupt_id);
  115. if (result) {
  116. pr_debug("%s:%d ps3_repository_find_interrupt failed\n",
  117. __func__, __LINE__);
  118. goto fail_find_interrupt;
  119. }
  120. result = ps3_repository_find_reg(repo, reg_type,
  121. &bus_addr, &len);
  122. if (result) {
  123. pr_debug("%s:%d ps3_repository_find_reg failed\n",
  124. __func__, __LINE__);
  125. goto fail_find_reg;
  126. }
  127. result = ps3_dma_region_init(&p->dev, p->dev.d_region, PS3_DMA_64K,
  128. PS3_DMA_INTERNAL, NULL, 0);
  129. if (result) {
  130. pr_debug("%s:%d ps3_dma_region_init failed\n",
  131. __func__, __LINE__);
  132. goto fail_dma_init;
  133. }
  134. result = ps3_mmio_region_init(&p->dev, p->dev.m_region, bus_addr, len,
  135. PS3_MMIO_4K);
  136. if (result) {
  137. pr_debug("%s:%d ps3_mmio_region_init failed\n",
  138. __func__, __LINE__);
  139. goto fail_mmio_init;
  140. }
  141. result = ps3_system_bus_device_register(&p->dev);
  142. if (result) {
  143. pr_debug("%s:%d ps3_system_bus_device_register failed\n",
  144. __func__, __LINE__);
  145. goto fail_device_register;
  146. }
  147. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  148. return result;
  149. fail_device_register:
  150. fail_mmio_init:
  151. fail_dma_init:
  152. fail_find_reg:
  153. fail_find_interrupt:
  154. kfree(p);
  155. fail_malloc:
  156. pr_debug(" <- %s:%d: fail.\n", __func__, __LINE__);
  157. return result;
  158. }
  159. static int __init ps3_setup_ehci_device(
  160. const struct ps3_repository_device *repo)
  161. {
  162. return ps3_setup_uhc_device(repo, PS3_MATCH_ID_EHCI,
  163. PS3_INTERRUPT_TYPE_SB_EHCI, PS3_REG_TYPE_SB_EHCI);
  164. }
  165. static int __init ps3_setup_ohci_device(
  166. const struct ps3_repository_device *repo)
  167. {
  168. return ps3_setup_uhc_device(repo, PS3_MATCH_ID_OHCI,
  169. PS3_INTERRUPT_TYPE_SB_OHCI, PS3_REG_TYPE_SB_OHCI);
  170. }
  171. static int __init ps3_setup_vuart_device(enum ps3_match_id match_id,
  172. unsigned int port_number)
  173. {
  174. int result;
  175. struct layout {
  176. struct ps3_system_bus_device dev;
  177. } *p;
  178. pr_debug(" -> %s:%d: match_id %u, port %u\n", __func__, __LINE__,
  179. match_id, port_number);
  180. p = kzalloc(sizeof(struct layout), GFP_KERNEL);
  181. if (!p)
  182. return -ENOMEM;
  183. p->dev.match_id = match_id;
  184. p->dev.dev_type = PS3_DEVICE_TYPE_VUART;
  185. p->dev.port_number = port_number;
  186. result = ps3_system_bus_device_register(&p->dev);
  187. if (result)
  188. pr_debug("%s:%d ps3_system_bus_device_register failed\n",
  189. __func__, __LINE__);
  190. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  191. return result;
  192. }
  193. static int ps3stor_wait_for_completion(u64 dev_id, u64 tag,
  194. unsigned int timeout)
  195. {
  196. int result = -1;
  197. unsigned int retries = 0;
  198. u64 status;
  199. for (retries = 0; retries < timeout; retries++) {
  200. result = lv1_storage_check_async_status(dev_id, tag, &status);
  201. if (!result)
  202. break;
  203. msleep(1);
  204. }
  205. if (result)
  206. pr_debug("%s:%u: check_async_status: %s, status %lx\n",
  207. __func__, __LINE__, ps3_result(result), status);
  208. return result;
  209. }
  210. /**
  211. * ps3_storage_wait_for_device - Wait for a storage device to become ready.
  212. * @repo: The repository device to wait for.
  213. *
  214. * Uses the hypervisor's storage device notification mechanism to wait until
  215. * a storage device is ready. The device notification mechanism uses a
  216. * psuedo device (id = -1) to asynchronously notify the guest when storage
  217. * devices become ready. The notification device has a block size of 512
  218. * bytes.
  219. */
  220. static int ps3_storage_wait_for_device(const struct ps3_repository_device *repo)
  221. {
  222. int result;
  223. const u64 notification_dev_id = (u64)-1LL;
  224. const unsigned int timeout = HZ;
  225. u64 lpar;
  226. u64 tag;
  227. struct {
  228. u64 operation_code; /* must be zero */
  229. u64 event_mask; /* 1 = device ready */
  230. } *notify_cmd;
  231. struct {
  232. u64 event_type; /* notify_device_ready */
  233. u64 bus_id;
  234. u64 dev_id;
  235. u64 dev_type;
  236. u64 dev_port;
  237. } *notify_event;
  238. enum {
  239. notify_device_ready = 1
  240. };
  241. pr_debug(" -> %s:%u: bus_id %u, dev_id %u, dev_type %u\n", __func__,
  242. __LINE__, repo->bus_id, repo->dev_id, repo->dev_type);
  243. notify_cmd = kzalloc(512, GFP_KERNEL);
  244. notify_event = (void *)notify_cmd;
  245. if (!notify_cmd)
  246. return -ENOMEM;
  247. lpar = ps3_mm_phys_to_lpar(__pa(notify_cmd));
  248. result = lv1_open_device(repo->bus_id, notification_dev_id, 0);
  249. if (result) {
  250. printk(KERN_ERR "%s:%u: lv1_open_device %s\n", __func__,
  251. __LINE__, ps3_result(result));
  252. result = -ENODEV;
  253. goto fail_free;
  254. }
  255. /* Setup and write the request for device notification. */
  256. notify_cmd->operation_code = 0; /* must be zero */
  257. notify_cmd->event_mask = 0x01; /* device ready */
  258. result = lv1_storage_write(notification_dev_id, 0, 0, 1, 0, lpar,
  259. &tag);
  260. if (result) {
  261. printk(KERN_ERR "%s:%u: write failed %s\n", __func__, __LINE__,
  262. ps3_result(result));
  263. result = -ENODEV;
  264. goto fail_close;
  265. }
  266. /* Wait for the write completion */
  267. result = ps3stor_wait_for_completion(notification_dev_id, tag,
  268. timeout);
  269. if (result) {
  270. printk(KERN_ERR "%s:%u: write not completed %s\n", __func__,
  271. __LINE__, ps3_result(result));
  272. result = -ENODEV;
  273. goto fail_close;
  274. }
  275. /* Loop here processing the requested notification events. */
  276. result = -ENODEV;
  277. while (1) {
  278. memset(notify_event, 0, sizeof(*notify_event));
  279. result = lv1_storage_read(notification_dev_id, 0, 0, 1, 0,
  280. lpar, &tag);
  281. if (result) {
  282. printk(KERN_ERR "%s:%u: write failed %s\n", __func__,
  283. __LINE__, ps3_result(result));
  284. break;
  285. }
  286. result = ps3stor_wait_for_completion(notification_dev_id, tag,
  287. timeout);
  288. if (result) {
  289. printk(KERN_ERR "%s:%u: read not completed %s\n",
  290. __func__, __LINE__, ps3_result(result));
  291. break;
  292. }
  293. if (notify_event->event_type != notify_device_ready ||
  294. notify_event->bus_id != repo->bus_id) {
  295. pr_debug("%s:%u: bad notify_event: event %lu, "
  296. "dev_id %lu, dev_type %lu\n",
  297. __func__, __LINE__, notify_event->event_type,
  298. notify_event->dev_id, notify_event->dev_type);
  299. break;
  300. }
  301. if (notify_event->dev_id == repo->dev_id &&
  302. notify_event->dev_type == repo->dev_type) {
  303. pr_debug("%s:%u: device ready: dev_id %u\n", __func__,
  304. __LINE__, repo->dev_id);
  305. result = 0;
  306. break;
  307. }
  308. if (notify_event->dev_id == repo->dev_id &&
  309. notify_event->dev_type == PS3_DEV_TYPE_NOACCESS) {
  310. pr_debug("%s:%u: no access: dev_id %u\n", __func__,
  311. __LINE__, repo->dev_id);
  312. break;
  313. }
  314. }
  315. fail_close:
  316. lv1_close_device(repo->bus_id, notification_dev_id);
  317. fail_free:
  318. kfree(notify_cmd);
  319. pr_debug(" <- %s:%u\n", __func__, __LINE__);
  320. return result;
  321. }
  322. static int ps3_setup_storage_dev(const struct ps3_repository_device *repo,
  323. enum ps3_match_id match_id)
  324. {
  325. int result;
  326. struct ps3_storage_device *p;
  327. u64 port, blk_size, num_blocks;
  328. unsigned int num_regions, i;
  329. pr_debug(" -> %s:%u: match_id %u\n", __func__, __LINE__, match_id);
  330. result = ps3_repository_read_stor_dev_info(repo->bus_index,
  331. repo->dev_index, &port,
  332. &blk_size, &num_blocks,
  333. &num_regions);
  334. if (result) {
  335. printk(KERN_ERR "%s:%u: _read_stor_dev_info failed %d\n",
  336. __func__, __LINE__, result);
  337. return -ENODEV;
  338. }
  339. pr_debug("%s:%u: index %u:%u: port %lu blk_size %lu num_blocks %lu "
  340. "num_regions %u\n", __func__, __LINE__, repo->bus_index,
  341. repo->dev_index, port, blk_size, num_blocks, num_regions);
  342. p = kzalloc(sizeof(struct ps3_storage_device) +
  343. num_regions * sizeof(struct ps3_storage_region),
  344. GFP_KERNEL);
  345. if (!p) {
  346. result = -ENOMEM;
  347. goto fail_malloc;
  348. }
  349. p->sbd.match_id = match_id;
  350. p->sbd.dev_type = PS3_DEVICE_TYPE_SB;
  351. p->sbd.bus_id = repo->bus_id;
  352. p->sbd.dev_id = repo->dev_id;
  353. p->sbd.d_region = &p->dma_region;
  354. p->blk_size = blk_size;
  355. p->num_regions = num_regions;
  356. result = ps3_repository_find_interrupt(repo,
  357. PS3_INTERRUPT_TYPE_EVENT_PORT,
  358. &p->sbd.interrupt_id);
  359. if (result) {
  360. printk(KERN_ERR "%s:%u: find_interrupt failed %d\n", __func__,
  361. __LINE__, result);
  362. result = -ENODEV;
  363. goto fail_find_interrupt;
  364. }
  365. /* FIXME: Arrange to only do this on a 'cold' boot */
  366. result = ps3_storage_wait_for_device(repo);
  367. if (result) {
  368. printk(KERN_ERR "%s:%u: storage_notification failed %d\n",
  369. __func__, __LINE__, result);
  370. result = -ENODEV;
  371. goto fail_probe_notification;
  372. }
  373. for (i = 0; i < num_regions; i++) {
  374. unsigned int id;
  375. u64 start, size;
  376. result = ps3_repository_read_stor_dev_region(repo->bus_index,
  377. repo->dev_index,
  378. i, &id, &start,
  379. &size);
  380. if (result) {
  381. printk(KERN_ERR
  382. "%s:%u: read_stor_dev_region failed %d\n",
  383. __func__, __LINE__, result);
  384. result = -ENODEV;
  385. goto fail_read_region;
  386. }
  387. pr_debug("%s:%u: region %u: id %u start %lu size %lu\n",
  388. __func__, __LINE__, i, id, start, size);
  389. p->regions[i].id = id;
  390. p->regions[i].start = start;
  391. p->regions[i].size = size;
  392. }
  393. result = ps3_system_bus_device_register(&p->sbd);
  394. if (result) {
  395. pr_debug("%s:%u ps3_system_bus_device_register failed\n",
  396. __func__, __LINE__);
  397. goto fail_device_register;
  398. }
  399. pr_debug(" <- %s:%u\n", __func__, __LINE__);
  400. return 0;
  401. fail_device_register:
  402. fail_read_region:
  403. fail_probe_notification:
  404. fail_find_interrupt:
  405. kfree(p);
  406. fail_malloc:
  407. pr_debug(" <- %s:%u: fail.\n", __func__, __LINE__);
  408. return result;
  409. }
  410. static int __init ps3_register_vuart_devices(void)
  411. {
  412. int result;
  413. unsigned int port_number;
  414. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  415. result = ps3_repository_read_vuart_av_port(&port_number);
  416. if (result)
  417. port_number = 0; /* av default */
  418. result = ps3_setup_vuart_device(PS3_MATCH_ID_AV_SETTINGS, port_number);
  419. WARN_ON(result);
  420. result = ps3_repository_read_vuart_sysmgr_port(&port_number);
  421. if (result)
  422. port_number = 2; /* sysmgr default */
  423. result = ps3_setup_vuart_device(PS3_MATCH_ID_SYSTEM_MANAGER,
  424. port_number);
  425. WARN_ON(result);
  426. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  427. return result;
  428. }
  429. static int __init ps3_register_sound_devices(void)
  430. {
  431. int result;
  432. struct layout {
  433. struct ps3_system_bus_device dev;
  434. struct ps3_dma_region d_region;
  435. struct ps3_mmio_region m_region;
  436. } *p;
  437. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  438. p = kzalloc(sizeof(*p), GFP_KERNEL);
  439. if (!p)
  440. return -ENOMEM;
  441. p->dev.match_id = PS3_MATCH_ID_SOUND;
  442. p->dev.dev_type = PS3_DEVICE_TYPE_IOC0;
  443. p->dev.d_region = &p->d_region;
  444. p->dev.m_region = &p->m_region;
  445. result = ps3_system_bus_device_register(&p->dev);
  446. if (result)
  447. pr_debug("%s:%d ps3_system_bus_device_register failed\n",
  448. __func__, __LINE__);
  449. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  450. return result;
  451. }
  452. static int __init ps3_register_graphics_devices(void)
  453. {
  454. int result;
  455. struct layout {
  456. struct ps3_system_bus_device dev;
  457. } *p;
  458. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  459. p = kzalloc(sizeof(struct layout), GFP_KERNEL);
  460. if (!p)
  461. return -ENOMEM;
  462. p->dev.match_id = PS3_MATCH_ID_GRAPHICS;
  463. p->dev.dev_type = PS3_DEVICE_TYPE_IOC0;
  464. result = ps3_system_bus_device_register(&p->dev);
  465. if (result)
  466. pr_debug("%s:%d ps3_system_bus_device_register failed\n",
  467. __func__, __LINE__);
  468. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  469. return result;
  470. }
  471. /**
  472. * ps3_register_repository_device - Register a device from the repositiory info.
  473. *
  474. */
  475. static int ps3_register_repository_device(
  476. const struct ps3_repository_device *repo)
  477. {
  478. int result;
  479. switch (repo->dev_type) {
  480. case PS3_DEV_TYPE_SB_GELIC:
  481. result = ps3_setup_gelic_device(repo);
  482. if (result) {
  483. pr_debug("%s:%d ps3_setup_gelic_device failed\n",
  484. __func__, __LINE__);
  485. }
  486. break;
  487. case PS3_DEV_TYPE_SB_USB:
  488. /* Each USB device has both an EHCI and an OHCI HC */
  489. result = ps3_setup_ehci_device(repo);
  490. if (result) {
  491. pr_debug("%s:%d ps3_setup_ehci_device failed\n",
  492. __func__, __LINE__);
  493. }
  494. result = ps3_setup_ohci_device(repo);
  495. if (result) {
  496. pr_debug("%s:%d ps3_setup_ohci_device failed\n",
  497. __func__, __LINE__);
  498. }
  499. break;
  500. case PS3_DEV_TYPE_STOR_DISK:
  501. result = ps3_setup_storage_dev(repo, PS3_MATCH_ID_STOR_DISK);
  502. /* Some devices are not accessable from the Other OS lpar. */
  503. if (result == -ENODEV) {
  504. result = 0;
  505. pr_debug("%s:%u: not accessable\n", __func__,
  506. __LINE__);
  507. }
  508. if (result)
  509. pr_debug("%s:%u ps3_setup_storage_dev failed\n",
  510. __func__, __LINE__);
  511. break;
  512. case PS3_DEV_TYPE_STOR_ROM:
  513. result = ps3_setup_storage_dev(repo, PS3_MATCH_ID_STOR_ROM);
  514. if (result)
  515. pr_debug("%s:%u ps3_setup_storage_dev failed\n",
  516. __func__, __LINE__);
  517. break;
  518. case PS3_DEV_TYPE_STOR_FLASH:
  519. result = ps3_setup_storage_dev(repo, PS3_MATCH_ID_STOR_FLASH);
  520. if (result)
  521. pr_debug("%s:%u ps3_setup_storage_dev failed\n",
  522. __func__, __LINE__);
  523. break;
  524. default:
  525. result = 0;
  526. pr_debug("%s:%u: unsupported dev_type %u\n", __func__, __LINE__,
  527. repo->dev_type);
  528. }
  529. return result;
  530. }
  531. /**
  532. * ps3_probe_thread - Background repository probing at system startup.
  533. *
  534. * This implementation only supports background probing on a single bus.
  535. */
  536. static int ps3_probe_thread(void *data)
  537. {
  538. struct ps3_repository_device *repo = data;
  539. int result;
  540. unsigned int ms = 250;
  541. pr_debug(" -> %s:%u: kthread started\n", __func__, __LINE__);
  542. do {
  543. try_to_freeze();
  544. pr_debug("%s:%u: probing...\n", __func__, __LINE__);
  545. do {
  546. result = ps3_repository_find_device(repo);
  547. if (result == -ENODEV)
  548. pr_debug("%s:%u: nothing new\n", __func__,
  549. __LINE__);
  550. else if (result)
  551. pr_debug("%s:%u: find device error.\n",
  552. __func__, __LINE__);
  553. else {
  554. pr_debug("%s:%u: found device\n", __func__,
  555. __LINE__);
  556. ps3_register_repository_device(repo);
  557. ps3_repository_bump_device(repo);
  558. ms = 250;
  559. }
  560. } while (!result);
  561. pr_debug("%s:%u: ms %u\n", __func__, __LINE__, ms);
  562. if ( ms > 60000)
  563. break;
  564. msleep_interruptible(ms);
  565. /* An exponential backoff. */
  566. ms <<= 1;
  567. } while (!kthread_should_stop());
  568. pr_debug(" <- %s:%u: kthread finished\n", __func__, __LINE__);
  569. return 0;
  570. }
  571. /**
  572. * ps3_start_probe_thread - Starts the background probe thread.
  573. *
  574. */
  575. static int __init ps3_start_probe_thread(enum ps3_bus_type bus_type)
  576. {
  577. int result;
  578. struct task_struct *task;
  579. static struct ps3_repository_device repo; /* must be static */
  580. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  581. memset(&repo, 0, sizeof(repo));
  582. repo.bus_type = bus_type;
  583. result = ps3_repository_find_bus(repo.bus_type, 0, &repo.bus_index);
  584. if (result) {
  585. printk(KERN_ERR "%s: Cannot find bus (%d)\n", __func__, result);
  586. return -ENODEV;
  587. }
  588. result = ps3_repository_read_bus_id(repo.bus_index, &repo.bus_id);
  589. if (result) {
  590. printk(KERN_ERR "%s: read_bus_id failed %d\n", __func__,
  591. result);
  592. return -ENODEV;
  593. }
  594. task = kthread_run(ps3_probe_thread, &repo, "ps3-probe-%u", bus_type);
  595. if (IS_ERR(task)) {
  596. result = PTR_ERR(task);
  597. printk(KERN_ERR "%s: kthread_run failed %d\n", __func__,
  598. result);
  599. return result;
  600. }
  601. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  602. return 0;
  603. }
  604. /**
  605. * ps3_register_devices - Probe the system and register devices found.
  606. *
  607. * A device_initcall() routine.
  608. */
  609. static int __init ps3_register_devices(void)
  610. {
  611. int result;
  612. if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
  613. return -ENODEV;
  614. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  615. /* ps3_repository_dump_bus_info(); */
  616. result = ps3_start_probe_thread(PS3_BUS_TYPE_STORAGE);
  617. ps3_register_vuart_devices();
  618. ps3_register_graphics_devices();
  619. ps3_repository_find_devices(PS3_BUS_TYPE_SB,
  620. ps3_register_repository_device);
  621. ps3_register_sound_devices();
  622. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  623. return 0;
  624. }
  625. device_initcall(ps3_register_devices);