device-init.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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 error = -ENODEV;
  223. int result;
  224. const u64 notification_dev_id = (u64)-1LL;
  225. const unsigned int timeout = HZ;
  226. u64 lpar;
  227. u64 tag;
  228. void *buf;
  229. enum ps3_notify_type {
  230. notify_device_ready = 0,
  231. notify_region_probe = 1,
  232. notify_region_update = 2,
  233. };
  234. struct {
  235. u64 operation_code; /* must be zero */
  236. u64 event_mask; /* OR of 1UL << enum ps3_notify_type */
  237. } *notify_cmd;
  238. struct {
  239. u64 event_type; /* enum ps3_notify_type */
  240. u64 bus_id;
  241. u64 dev_id;
  242. u64 dev_type;
  243. u64 dev_port;
  244. } *notify_event;
  245. pr_debug(" -> %s:%u: bus_id %u, dev_id %u, dev_type %u\n", __func__,
  246. __LINE__, repo->bus_id, repo->dev_id, repo->dev_type);
  247. buf = kzalloc(512, GFP_KERNEL);
  248. if (!buf)
  249. return -ENOMEM;
  250. lpar = ps3_mm_phys_to_lpar(__pa(buf));
  251. notify_cmd = buf;
  252. notify_event = buf;
  253. result = lv1_open_device(repo->bus_id, notification_dev_id, 0);
  254. if (result) {
  255. printk(KERN_ERR "%s:%u: lv1_open_device %s\n", __func__,
  256. __LINE__, ps3_result(result));
  257. goto fail_free;
  258. }
  259. /* Setup and write the request for device notification. */
  260. notify_cmd->operation_code = 0; /* must be zero */
  261. notify_cmd->event_mask = 1UL << notify_region_probe;
  262. result = lv1_storage_write(notification_dev_id, 0, 0, 1, 0, lpar,
  263. &tag);
  264. if (result) {
  265. printk(KERN_ERR "%s:%u: write failed %s\n", __func__, __LINE__,
  266. ps3_result(result));
  267. goto fail_close;
  268. }
  269. /* Wait for the write completion */
  270. result = ps3stor_wait_for_completion(notification_dev_id, tag,
  271. timeout);
  272. if (result) {
  273. printk(KERN_ERR "%s:%u: write not completed %s\n", __func__,
  274. __LINE__, ps3_result(result));
  275. goto fail_close;
  276. }
  277. /* Loop here processing the requested notification events. */
  278. while (1) {
  279. memset(notify_event, 0, sizeof(*notify_event));
  280. result = lv1_storage_read(notification_dev_id, 0, 0, 1, 0,
  281. lpar, &tag);
  282. if (result) {
  283. printk(KERN_ERR "%s:%u: write failed %s\n", __func__,
  284. __LINE__, ps3_result(result));
  285. break;
  286. }
  287. result = ps3stor_wait_for_completion(notification_dev_id, tag,
  288. timeout);
  289. if (result) {
  290. printk(KERN_ERR "%s:%u: read not completed %s\n",
  291. __func__, __LINE__, ps3_result(result));
  292. break;
  293. }
  294. if (notify_event->event_type != notify_region_probe ||
  295. notify_event->bus_id != repo->bus_id) {
  296. pr_debug("%s:%u: bad notify_event: event %lu, "
  297. "dev_id %lu, dev_type %lu\n",
  298. __func__, __LINE__, notify_event->event_type,
  299. notify_event->dev_id, notify_event->dev_type);
  300. break;
  301. }
  302. if (notify_event->dev_id == repo->dev_id &&
  303. notify_event->dev_type == repo->dev_type) {
  304. pr_debug("%s:%u: device ready: dev_id %u\n", __func__,
  305. __LINE__, repo->dev_id);
  306. error = 0;
  307. break;
  308. }
  309. if (notify_event->dev_id == repo->dev_id &&
  310. notify_event->dev_type == PS3_DEV_TYPE_NOACCESS) {
  311. pr_debug("%s:%u: no access: dev_id %u\n", __func__,
  312. __LINE__, repo->dev_id);
  313. break;
  314. }
  315. }
  316. fail_close:
  317. lv1_close_device(repo->bus_id, notification_dev_id);
  318. fail_free:
  319. kfree(buf);
  320. pr_debug(" <- %s:%u\n", __func__, __LINE__);
  321. return error;
  322. }
  323. static int ps3_setup_storage_dev(const struct ps3_repository_device *repo,
  324. enum ps3_match_id match_id)
  325. {
  326. int result;
  327. struct ps3_storage_device *p;
  328. u64 port, blk_size, num_blocks;
  329. unsigned int num_regions, i;
  330. pr_debug(" -> %s:%u: match_id %u\n", __func__, __LINE__, match_id);
  331. result = ps3_repository_read_stor_dev_info(repo->bus_index,
  332. repo->dev_index, &port,
  333. &blk_size, &num_blocks,
  334. &num_regions);
  335. if (result) {
  336. printk(KERN_ERR "%s:%u: _read_stor_dev_info failed %d\n",
  337. __func__, __LINE__, result);
  338. return -ENODEV;
  339. }
  340. pr_debug("%s:%u: index %u:%u: port %lu blk_size %lu num_blocks %lu "
  341. "num_regions %u\n", __func__, __LINE__, repo->bus_index,
  342. repo->dev_index, port, blk_size, num_blocks, num_regions);
  343. p = kzalloc(sizeof(struct ps3_storage_device) +
  344. num_regions * sizeof(struct ps3_storage_region),
  345. GFP_KERNEL);
  346. if (!p) {
  347. result = -ENOMEM;
  348. goto fail_malloc;
  349. }
  350. p->sbd.match_id = match_id;
  351. p->sbd.dev_type = PS3_DEVICE_TYPE_SB;
  352. p->sbd.bus_id = repo->bus_id;
  353. p->sbd.dev_id = repo->dev_id;
  354. p->sbd.d_region = &p->dma_region;
  355. p->blk_size = blk_size;
  356. p->num_regions = num_regions;
  357. result = ps3_repository_find_interrupt(repo,
  358. PS3_INTERRUPT_TYPE_EVENT_PORT,
  359. &p->sbd.interrupt_id);
  360. if (result) {
  361. printk(KERN_ERR "%s:%u: find_interrupt failed %d\n", __func__,
  362. __LINE__, result);
  363. result = -ENODEV;
  364. goto fail_find_interrupt;
  365. }
  366. /* FIXME: Arrange to only do this on a 'cold' boot */
  367. result = ps3_storage_wait_for_device(repo);
  368. if (result) {
  369. printk(KERN_ERR "%s:%u: storage_notification failed %d\n",
  370. __func__, __LINE__, result);
  371. result = -ENODEV;
  372. goto fail_probe_notification;
  373. }
  374. for (i = 0; i < num_regions; i++) {
  375. unsigned int id;
  376. u64 start, size;
  377. result = ps3_repository_read_stor_dev_region(repo->bus_index,
  378. repo->dev_index,
  379. i, &id, &start,
  380. &size);
  381. if (result) {
  382. printk(KERN_ERR
  383. "%s:%u: read_stor_dev_region failed %d\n",
  384. __func__, __LINE__, result);
  385. result = -ENODEV;
  386. goto fail_read_region;
  387. }
  388. pr_debug("%s:%u: region %u: id %u start %lu size %lu\n",
  389. __func__, __LINE__, i, id, start, size);
  390. p->regions[i].id = id;
  391. p->regions[i].start = start;
  392. p->regions[i].size = size;
  393. }
  394. result = ps3_system_bus_device_register(&p->sbd);
  395. if (result) {
  396. pr_debug("%s:%u ps3_system_bus_device_register failed\n",
  397. __func__, __LINE__);
  398. goto fail_device_register;
  399. }
  400. pr_debug(" <- %s:%u\n", __func__, __LINE__);
  401. return 0;
  402. fail_device_register:
  403. fail_read_region:
  404. fail_probe_notification:
  405. fail_find_interrupt:
  406. kfree(p);
  407. fail_malloc:
  408. pr_debug(" <- %s:%u: fail.\n", __func__, __LINE__);
  409. return result;
  410. }
  411. static int __init ps3_register_vuart_devices(void)
  412. {
  413. int result;
  414. unsigned int port_number;
  415. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  416. result = ps3_repository_read_vuart_av_port(&port_number);
  417. if (result)
  418. port_number = 0; /* av default */
  419. result = ps3_setup_vuart_device(PS3_MATCH_ID_AV_SETTINGS, port_number);
  420. WARN_ON(result);
  421. result = ps3_repository_read_vuart_sysmgr_port(&port_number);
  422. if (result)
  423. port_number = 2; /* sysmgr default */
  424. result = ps3_setup_vuart_device(PS3_MATCH_ID_SYSTEM_MANAGER,
  425. port_number);
  426. WARN_ON(result);
  427. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  428. return result;
  429. }
  430. static int __init ps3_register_sound_devices(void)
  431. {
  432. int result;
  433. struct layout {
  434. struct ps3_system_bus_device dev;
  435. struct ps3_dma_region d_region;
  436. struct ps3_mmio_region m_region;
  437. } *p;
  438. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  439. p = kzalloc(sizeof(*p), GFP_KERNEL);
  440. if (!p)
  441. return -ENOMEM;
  442. p->dev.match_id = PS3_MATCH_ID_SOUND;
  443. p->dev.dev_type = PS3_DEVICE_TYPE_IOC0;
  444. p->dev.d_region = &p->d_region;
  445. p->dev.m_region = &p->m_region;
  446. result = ps3_system_bus_device_register(&p->dev);
  447. if (result)
  448. pr_debug("%s:%d ps3_system_bus_device_register failed\n",
  449. __func__, __LINE__);
  450. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  451. return result;
  452. }
  453. static int __init ps3_register_graphics_devices(void)
  454. {
  455. int result;
  456. struct layout {
  457. struct ps3_system_bus_device dev;
  458. } *p;
  459. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  460. p = kzalloc(sizeof(struct layout), GFP_KERNEL);
  461. if (!p)
  462. return -ENOMEM;
  463. p->dev.match_id = PS3_MATCH_ID_GRAPHICS;
  464. p->dev.dev_type = PS3_DEVICE_TYPE_IOC0;
  465. result = ps3_system_bus_device_register(&p->dev);
  466. if (result)
  467. pr_debug("%s:%d ps3_system_bus_device_register failed\n",
  468. __func__, __LINE__);
  469. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  470. return result;
  471. }
  472. /**
  473. * ps3_register_repository_device - Register a device from the repositiory info.
  474. *
  475. */
  476. static int ps3_register_repository_device(
  477. const struct ps3_repository_device *repo)
  478. {
  479. int result;
  480. switch (repo->dev_type) {
  481. case PS3_DEV_TYPE_SB_GELIC:
  482. result = ps3_setup_gelic_device(repo);
  483. if (result) {
  484. pr_debug("%s:%d ps3_setup_gelic_device failed\n",
  485. __func__, __LINE__);
  486. }
  487. break;
  488. case PS3_DEV_TYPE_SB_USB:
  489. /* Each USB device has both an EHCI and an OHCI HC */
  490. result = ps3_setup_ehci_device(repo);
  491. if (result) {
  492. pr_debug("%s:%d ps3_setup_ehci_device failed\n",
  493. __func__, __LINE__);
  494. }
  495. result = ps3_setup_ohci_device(repo);
  496. if (result) {
  497. pr_debug("%s:%d ps3_setup_ohci_device failed\n",
  498. __func__, __LINE__);
  499. }
  500. break;
  501. case PS3_DEV_TYPE_STOR_DISK:
  502. result = ps3_setup_storage_dev(repo, PS3_MATCH_ID_STOR_DISK);
  503. /* Some devices are not accessable from the Other OS lpar. */
  504. if (result == -ENODEV) {
  505. result = 0;
  506. pr_debug("%s:%u: not accessable\n", __func__,
  507. __LINE__);
  508. }
  509. if (result)
  510. pr_debug("%s:%u ps3_setup_storage_dev failed\n",
  511. __func__, __LINE__);
  512. break;
  513. case PS3_DEV_TYPE_STOR_ROM:
  514. result = ps3_setup_storage_dev(repo, PS3_MATCH_ID_STOR_ROM);
  515. if (result)
  516. pr_debug("%s:%u ps3_setup_storage_dev failed\n",
  517. __func__, __LINE__);
  518. break;
  519. case PS3_DEV_TYPE_STOR_FLASH:
  520. result = ps3_setup_storage_dev(repo, PS3_MATCH_ID_STOR_FLASH);
  521. if (result)
  522. pr_debug("%s:%u ps3_setup_storage_dev failed\n",
  523. __func__, __LINE__);
  524. break;
  525. default:
  526. result = 0;
  527. pr_debug("%s:%u: unsupported dev_type %u\n", __func__, __LINE__,
  528. repo->dev_type);
  529. }
  530. return result;
  531. }
  532. /**
  533. * ps3_probe_thread - Background repository probing at system startup.
  534. *
  535. * This implementation only supports background probing on a single bus.
  536. */
  537. static int ps3_probe_thread(void *data)
  538. {
  539. struct ps3_repository_device *repo = data;
  540. int result;
  541. unsigned int ms = 250;
  542. pr_debug(" -> %s:%u: kthread started\n", __func__, __LINE__);
  543. do {
  544. try_to_freeze();
  545. pr_debug("%s:%u: probing...\n", __func__, __LINE__);
  546. do {
  547. result = ps3_repository_find_device(repo);
  548. if (result == -ENODEV)
  549. pr_debug("%s:%u: nothing new\n", __func__,
  550. __LINE__);
  551. else if (result)
  552. pr_debug("%s:%u: find device error.\n",
  553. __func__, __LINE__);
  554. else {
  555. pr_debug("%s:%u: found device\n", __func__,
  556. __LINE__);
  557. ps3_register_repository_device(repo);
  558. ps3_repository_bump_device(repo);
  559. ms = 250;
  560. }
  561. } while (!result);
  562. pr_debug("%s:%u: ms %u\n", __func__, __LINE__, ms);
  563. if ( ms > 60000)
  564. break;
  565. msleep_interruptible(ms);
  566. /* An exponential backoff. */
  567. ms <<= 1;
  568. } while (!kthread_should_stop());
  569. pr_debug(" <- %s:%u: kthread finished\n", __func__, __LINE__);
  570. return 0;
  571. }
  572. /**
  573. * ps3_start_probe_thread - Starts the background probe thread.
  574. *
  575. */
  576. static int __init ps3_start_probe_thread(enum ps3_bus_type bus_type)
  577. {
  578. int result;
  579. struct task_struct *task;
  580. static struct ps3_repository_device repo; /* must be static */
  581. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  582. memset(&repo, 0, sizeof(repo));
  583. repo.bus_type = bus_type;
  584. result = ps3_repository_find_bus(repo.bus_type, 0, &repo.bus_index);
  585. if (result) {
  586. printk(KERN_ERR "%s: Cannot find bus (%d)\n", __func__, result);
  587. return -ENODEV;
  588. }
  589. result = ps3_repository_read_bus_id(repo.bus_index, &repo.bus_id);
  590. if (result) {
  591. printk(KERN_ERR "%s: read_bus_id failed %d\n", __func__,
  592. result);
  593. return -ENODEV;
  594. }
  595. task = kthread_run(ps3_probe_thread, &repo, "ps3-probe-%u", bus_type);
  596. if (IS_ERR(task)) {
  597. result = PTR_ERR(task);
  598. printk(KERN_ERR "%s: kthread_run failed %d\n", __func__,
  599. result);
  600. return result;
  601. }
  602. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  603. return 0;
  604. }
  605. /**
  606. * ps3_register_devices - Probe the system and register devices found.
  607. *
  608. * A device_initcall() routine.
  609. */
  610. static int __init ps3_register_devices(void)
  611. {
  612. int result;
  613. if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
  614. return -ENODEV;
  615. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  616. /* ps3_repository_dump_bus_info(); */
  617. result = ps3_start_probe_thread(PS3_BUS_TYPE_STORAGE);
  618. ps3_register_vuart_devices();
  619. ps3_register_graphics_devices();
  620. ps3_repository_find_devices(PS3_BUS_TYPE_SB,
  621. ps3_register_repository_device);
  622. ps3_register_sound_devices();
  623. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  624. return 0;
  625. }
  626. device_initcall(ps3_register_devices);