device-init.c 19 KB

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