You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ata.c 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /*
  2. * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <stddef.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <assert.h>
  28. #include <errno.h>
  29. #include <byteswap.h>
  30. #include <ipxe/list.h>
  31. #include <ipxe/interface.h>
  32. #include <ipxe/blockdev.h>
  33. #include <ipxe/edd.h>
  34. #include <ipxe/ata.h>
  35. /** @file
  36. *
  37. * ATA block device
  38. *
  39. */
  40. /******************************************************************************
  41. *
  42. * Interface methods
  43. *
  44. ******************************************************************************
  45. */
  46. /**
  47. * Issue ATA command
  48. *
  49. * @v control ATA control interface
  50. * @v data ATA data interface
  51. * @v command ATA command
  52. * @ret tag Command tag, or negative error
  53. */
  54. int ata_command ( struct interface *control, struct interface *data,
  55. struct ata_cmd *command ) {
  56. struct interface *dest;
  57. ata_command_TYPE ( void * ) *op =
  58. intf_get_dest_op ( control, ata_command, &dest );
  59. void *object = intf_object ( dest );
  60. int tag;
  61. if ( op ) {
  62. tag = op ( object, data, command );
  63. } else {
  64. /* Default is to fail to issue the command */
  65. tag = -EOPNOTSUPP;
  66. }
  67. intf_put ( dest );
  68. return tag;
  69. }
  70. /******************************************************************************
  71. *
  72. * ATA devices and commands
  73. *
  74. ******************************************************************************
  75. */
  76. /** List of all ATA commands */
  77. static LIST_HEAD ( ata_commands );
  78. /** An ATA device */
  79. struct ata_device {
  80. /** Reference count */
  81. struct refcnt refcnt;
  82. /** Block control interface */
  83. struct interface block;
  84. /** ATA control interface */
  85. struct interface ata;
  86. /** Device number
  87. *
  88. * Must be ATA_DEV_MASTER or ATA_DEV_SLAVE.
  89. */
  90. unsigned int device;
  91. /** Maximum number of blocks per single transfer */
  92. unsigned int max_count;
  93. /** Device uses LBA48 extended addressing */
  94. int lba48;
  95. };
  96. /** An ATA command */
  97. struct ata_command {
  98. /** Reference count */
  99. struct refcnt refcnt;
  100. /** ATA device */
  101. struct ata_device *atadev;
  102. /** List of ATA commands */
  103. struct list_head list;
  104. /** Block data interface */
  105. struct interface block;
  106. /** ATA data interface */
  107. struct interface ata;
  108. /** Command type */
  109. struct ata_command_type *type;
  110. /** Command tag */
  111. uint32_t tag;
  112. /** Private data */
  113. uint8_t priv[0];
  114. };
  115. /** An ATA command type */
  116. struct ata_command_type {
  117. /** Name */
  118. const char *name;
  119. /** Additional working space */
  120. size_t priv_len;
  121. /** Command for non-LBA48-capable devices */
  122. uint8_t cmd_lba;
  123. /** Command for LBA48-capable devices */
  124. uint8_t cmd_lba48;
  125. /**
  126. * Calculate data-in buffer
  127. *
  128. * @v atacmd ATA command
  129. * @v buffer Available buffer
  130. * @v len Available buffer length
  131. * @ret data_in Data-in buffer
  132. * @ret data_in_len Data-in buffer length
  133. */
  134. void ( * data_in ) ( struct ata_command *atacmd, userptr_t buffer,
  135. size_t len, userptr_t *data_in,
  136. size_t *data_in_len );
  137. /**
  138. * Calculate data-out buffer
  139. *
  140. *
  141. * @v atacmd ATA command
  142. * @v buffer Available buffer
  143. * @v len Available buffer length
  144. * @ret data_out Data-out buffer
  145. * @ret data_out_len Data-out buffer length
  146. */
  147. void ( * data_out ) ( struct ata_command *atacmd, userptr_t buffer,
  148. size_t len, userptr_t *data_out,
  149. size_t *data_out_len );
  150. /**
  151. * Handle ATA command completion
  152. *
  153. * @v atacmd ATA command
  154. * @v rc Reason for completion
  155. */
  156. void ( * done ) ( struct ata_command *atacmd, int rc );
  157. };
  158. /**
  159. * Get reference to ATA device
  160. *
  161. * @v atadev ATA device
  162. * @ret atadev ATA device
  163. */
  164. static inline __attribute__ (( always_inline )) struct ata_device *
  165. atadev_get ( struct ata_device *atadev ) {
  166. ref_get ( &atadev->refcnt );
  167. return atadev;
  168. }
  169. /**
  170. * Drop reference to ATA device
  171. *
  172. * @v atadev ATA device
  173. */
  174. static inline __attribute__ (( always_inline )) void
  175. atadev_put ( struct ata_device *atadev ) {
  176. ref_put ( &atadev->refcnt );
  177. }
  178. /**
  179. * Get reference to ATA command
  180. *
  181. * @v atacmd ATA command
  182. * @ret atacmd ATA command
  183. */
  184. static inline __attribute__ (( always_inline )) struct ata_command *
  185. atacmd_get ( struct ata_command *atacmd ) {
  186. ref_get ( &atacmd->refcnt );
  187. return atacmd;
  188. }
  189. /**
  190. * Drop reference to ATA command
  191. *
  192. * @v atacmd ATA command
  193. */
  194. static inline __attribute__ (( always_inline )) void
  195. atacmd_put ( struct ata_command *atacmd ) {
  196. ref_put ( &atacmd->refcnt );
  197. }
  198. /**
  199. * Get ATA command private data
  200. *
  201. * @v atacmd ATA command
  202. * @ret priv Private data
  203. */
  204. static inline __attribute__ (( always_inline )) void *
  205. atacmd_priv ( struct ata_command *atacmd ) {
  206. return atacmd->priv;
  207. }
  208. /**
  209. * Free ATA command
  210. *
  211. * @v refcnt Reference count
  212. */
  213. static void atacmd_free ( struct refcnt *refcnt ) {
  214. struct ata_command *atacmd =
  215. container_of ( refcnt, struct ata_command, refcnt );
  216. /* Remove from list of commands */
  217. list_del ( &atacmd->list );
  218. atadev_put ( atacmd->atadev );
  219. /* Free command */
  220. free ( atacmd );
  221. }
  222. /**
  223. * Close ATA command
  224. *
  225. * @v atacmd ATA command
  226. * @v rc Reason for close
  227. */
  228. static void atacmd_close ( struct ata_command *atacmd, int rc ) {
  229. struct ata_device *atadev = atacmd->atadev;
  230. if ( rc != 0 ) {
  231. DBGC ( atadev, "ATA %p tag %08x closed: %s\n",
  232. atadev, atacmd->tag, strerror ( rc ) );
  233. }
  234. /* Shut down interfaces */
  235. intf_shutdown ( &atacmd->ata, rc );
  236. intf_shutdown ( &atacmd->block, rc );
  237. }
  238. /**
  239. * Handle ATA command completion
  240. *
  241. * @v atacmd ATA command
  242. * @v rc Reason for close
  243. */
  244. static void atacmd_done ( struct ata_command *atacmd, int rc ) {
  245. /* Hand over to the command completion handler */
  246. atacmd->type->done ( atacmd, rc );
  247. }
  248. /**
  249. * Use provided data buffer for ATA command
  250. *
  251. * @v atacmd ATA command
  252. * @v buffer Available buffer
  253. * @v len Available buffer length
  254. * @ret data Data buffer
  255. * @ret data_len Data buffer length
  256. */
  257. static void atacmd_data_buffer ( struct ata_command *atacmd __unused,
  258. userptr_t buffer, size_t len,
  259. userptr_t *data, size_t *data_len ) {
  260. *data = buffer;
  261. *data_len = len;
  262. }
  263. /**
  264. * Use no data buffer for ATA command
  265. *
  266. * @v atacmd ATA command
  267. * @v buffer Available buffer
  268. * @v len Available buffer length
  269. * @ret data Data buffer
  270. * @ret data_len Data buffer length
  271. */
  272. static void atacmd_data_none ( struct ata_command *atacmd __unused,
  273. userptr_t buffer __unused, size_t len __unused,
  274. userptr_t *data __unused,
  275. size_t *data_len __unused ) {
  276. /* Nothing to do */
  277. }
  278. /**
  279. * Use private data buffer for ATA command
  280. *
  281. * @v atacmd ATA command
  282. * @v buffer Available buffer
  283. * @v len Available buffer length
  284. * @ret data Data buffer
  285. * @ret data_len Data buffer length
  286. */
  287. static void atacmd_data_priv ( struct ata_command *atacmd,
  288. userptr_t buffer __unused, size_t len __unused,
  289. userptr_t *data, size_t *data_len ) {
  290. *data = virt_to_user ( atacmd_priv ( atacmd ) );
  291. *data_len = atacmd->type->priv_len;
  292. }
  293. /** ATA READ command type */
  294. static struct ata_command_type atacmd_read = {
  295. .name = "READ",
  296. .cmd_lba = ATA_CMD_READ,
  297. .cmd_lba48 = ATA_CMD_READ_EXT,
  298. .data_in = atacmd_data_buffer,
  299. .data_out = atacmd_data_none,
  300. .done = atacmd_close,
  301. };
  302. /** ATA WRITE command type */
  303. static struct ata_command_type atacmd_write = {
  304. .name = "WRITE",
  305. .cmd_lba = ATA_CMD_WRITE,
  306. .cmd_lba48 = ATA_CMD_WRITE_EXT,
  307. .data_in = atacmd_data_none,
  308. .data_out = atacmd_data_buffer,
  309. .done = atacmd_close,
  310. };
  311. /** ATA IDENTIFY private data */
  312. struct ata_identify_private {
  313. /** Identity data */
  314. struct ata_identity identity;
  315. };
  316. /**
  317. * Return ATA model string (for debugging)
  318. *
  319. * @v identify ATA identity data
  320. * @ret model Model string
  321. */
  322. static const char * ata_model ( struct ata_identity *identity ) {
  323. static union {
  324. uint16_t words[ sizeof ( identity->model ) / 2 ];
  325. char text[ sizeof ( identity->model ) + 1 /* NUL */ ];
  326. } buf;
  327. unsigned int i;
  328. for ( i = 0 ; i < ( sizeof ( identity->model ) / 2 ) ; i++ )
  329. buf.words[i] = bswap_16 ( identity->model[i] );
  330. return buf.text;
  331. }
  332. /**
  333. * Handle ATA IDENTIFY command completion
  334. *
  335. * @v atacmd ATA command
  336. * @v rc Reason for completion
  337. */
  338. static void atacmd_identify_done ( struct ata_command *atacmd, int rc ) {
  339. struct ata_device *atadev = atacmd->atadev;
  340. struct ata_identify_private *priv = atacmd_priv ( atacmd );
  341. struct ata_identity *identity = &priv->identity;
  342. struct block_device_capacity capacity;
  343. /* Close if command failed */
  344. if ( rc != 0 ) {
  345. atacmd_close ( atacmd, rc );
  346. return;
  347. }
  348. /* Extract capacity */
  349. if ( identity->supports_lba48 & cpu_to_le16 ( ATA_SUPPORTS_LBA48 ) ) {
  350. atadev->lba48 = 1;
  351. capacity.blocks = le64_to_cpu ( identity->lba48_sectors );
  352. } else {
  353. capacity.blocks = le32_to_cpu ( identity->lba_sectors );
  354. }
  355. capacity.blksize = ATA_SECTOR_SIZE;
  356. capacity.max_count = atadev->max_count;
  357. DBGC ( atadev, "ATA %p is a %s\n", atadev, ata_model ( identity ) );
  358. DBGC ( atadev, "ATA %p has %#llx blocks (%ld MB) and uses %s\n",
  359. atadev, capacity.blocks,
  360. ( ( signed long ) ( capacity.blocks >> 11 ) ),
  361. ( atadev->lba48 ? "LBA48" : "LBA" ) );
  362. /* Return capacity to caller */
  363. block_capacity ( &atacmd->block, &capacity );
  364. /* Close command */
  365. atacmd_close ( atacmd, 0 );
  366. }
  367. /** ATA IDENTITY command type */
  368. static struct ata_command_type atacmd_identify = {
  369. .name = "IDENTIFY",
  370. .priv_len = sizeof ( struct ata_identify_private ),
  371. .cmd_lba = ATA_CMD_IDENTIFY,
  372. .cmd_lba48 = ATA_CMD_IDENTIFY,
  373. .data_in = atacmd_data_priv,
  374. .data_out = atacmd_data_none,
  375. .done = atacmd_identify_done,
  376. };
  377. /** ATA command block interface operations */
  378. static struct interface_operation atacmd_block_op[] = {
  379. INTF_OP ( intf_close, struct ata_command *, atacmd_close ),
  380. };
  381. /** ATA command block interface descriptor */
  382. static struct interface_descriptor atacmd_block_desc =
  383. INTF_DESC_PASSTHRU ( struct ata_command, block,
  384. atacmd_block_op, ata );
  385. /** ATA command ATA interface operations */
  386. static struct interface_operation atacmd_ata_op[] = {
  387. INTF_OP ( intf_close, struct ata_command *, atacmd_done ),
  388. };
  389. /** ATA command ATA interface descriptor */
  390. static struct interface_descriptor atacmd_ata_desc =
  391. INTF_DESC_PASSTHRU ( struct ata_command, ata,
  392. atacmd_ata_op, block );
  393. /**
  394. * Create ATA command
  395. *
  396. * @v atadev ATA device
  397. * @v block Block data interface
  398. * @v type ATA command type
  399. * @v lba Starting logical block address
  400. * @v count Number of blocks to transfer
  401. * @v buffer Data buffer
  402. * @v len Length of data buffer
  403. * @ret rc Return status code
  404. */
  405. static int atadev_command ( struct ata_device *atadev,
  406. struct interface *block,
  407. struct ata_command_type *type,
  408. uint64_t lba, unsigned int count,
  409. userptr_t buffer, size_t len ) {
  410. struct ata_command *atacmd;
  411. struct ata_cmd command;
  412. int tag;
  413. int rc;
  414. /* Allocate and initialise structure */
  415. atacmd = zalloc ( sizeof ( *atacmd ) + type->priv_len );
  416. if ( ! atacmd ) {
  417. rc = -ENOMEM;
  418. goto err_zalloc;
  419. }
  420. ref_init ( &atacmd->refcnt, atacmd_free );
  421. intf_init ( &atacmd->block, &atacmd_block_desc, &atacmd->refcnt );
  422. intf_init ( &atacmd->ata, &atacmd_ata_desc,
  423. &atacmd->refcnt );
  424. atacmd->atadev = atadev_get ( atadev );
  425. list_add ( &atacmd->list, &ata_commands );
  426. atacmd->type = type;
  427. /* Sanity check */
  428. if ( len != ( count * ATA_SECTOR_SIZE ) ) {
  429. DBGC ( atadev, "ATA %p tag %08x buffer length mismatch (count "
  430. "%d len %zd)\n", atadev, atacmd->tag, count, len );
  431. rc = -EINVAL;
  432. goto err_len;
  433. }
  434. /* Construct command */
  435. memset ( &command, 0, sizeof ( command ) );
  436. command.cb.lba.native = lba;
  437. command.cb.count.native = count;
  438. command.cb.device = ( atadev->device | ATA_DEV_OBSOLETE | ATA_DEV_LBA );
  439. command.cb.lba48 = atadev->lba48;
  440. if ( ! atadev->lba48 )
  441. command.cb.device |= command.cb.lba.bytes.low_prev;
  442. command.cb.cmd_stat =
  443. ( atadev->lba48 ? type->cmd_lba48 : type->cmd_lba );
  444. type->data_in ( atacmd, buffer, len,
  445. &command.data_in, &command.data_in_len );
  446. type->data_out ( atacmd, buffer, len,
  447. &command.data_out, &command.data_out_len );
  448. /* Issue command */
  449. if ( ( tag = ata_command ( &atadev->ata, &atacmd->ata,
  450. &command ) ) < 0 ) {
  451. rc = tag;
  452. DBGC ( atadev, "ATA %p tag %08x could not issue command: %s\n",
  453. atadev, atacmd->tag, strerror ( rc ) );
  454. goto err_command;
  455. }
  456. atacmd->tag = tag;
  457. DBGC2 ( atadev, "ATA %p tag %08x %s cmd %02x dev %02x LBA%s %08llx "
  458. "count %04x\n", atadev, atacmd->tag, atacmd->type->name,
  459. command.cb.cmd_stat, command.cb.device,
  460. ( command.cb.lba48 ? "48" : "" ),
  461. ( unsigned long long ) command.cb.lba.native,
  462. command.cb.count.native );
  463. /* Attach to parent interface, mortalise self, and return */
  464. intf_plug_plug ( &atacmd->block, block );
  465. ref_put ( &atacmd->refcnt );
  466. return 0;
  467. err_command:
  468. err_len:
  469. atacmd_close ( atacmd, rc );
  470. ref_put ( &atacmd->refcnt );
  471. err_zalloc:
  472. return rc;
  473. }
  474. /**
  475. * Issue ATA block read
  476. *
  477. * @v atadev ATA device
  478. * @v block Block data interface
  479. * @v lba Starting logical block address
  480. * @v count Number of blocks to transfer
  481. * @v buffer Data buffer
  482. * @v len Length of data buffer
  483. * @ret rc Return status code
  484. */
  485. static int atadev_read ( struct ata_device *atadev,
  486. struct interface *block,
  487. uint64_t lba, unsigned int count,
  488. userptr_t buffer, size_t len ) {
  489. return atadev_command ( atadev, block, &atacmd_read,
  490. lba, count, buffer, len );
  491. }
  492. /**
  493. * Issue ATA block write
  494. *
  495. * @v atadev ATA device
  496. * @v block Block data interface
  497. * @v lba Starting logical block address
  498. * @v count Number of blocks to transfer
  499. * @v buffer Data buffer
  500. * @v len Length of data buffer
  501. * @ret rc Return status code
  502. */
  503. static int atadev_write ( struct ata_device *atadev,
  504. struct interface *block,
  505. uint64_t lba, unsigned int count,
  506. userptr_t buffer, size_t len ) {
  507. return atadev_command ( atadev, block, &atacmd_write,
  508. lba, count, buffer, len );
  509. }
  510. /**
  511. * Read ATA device capacity
  512. *
  513. * @v atadev ATA device
  514. * @v block Block data interface
  515. * @ret rc Return status code
  516. */
  517. static int atadev_read_capacity ( struct ata_device *atadev,
  518. struct interface *block ) {
  519. struct ata_identity *identity;
  520. assert ( atacmd_identify.priv_len == sizeof ( *identity ) );
  521. assert ( atacmd_identify.priv_len == ATA_SECTOR_SIZE );
  522. return atadev_command ( atadev, block, &atacmd_identify,
  523. 0, 1, UNULL, ATA_SECTOR_SIZE );
  524. }
  525. /**
  526. * Close ATA device
  527. *
  528. * @v atadev ATA device
  529. * @v rc Reason for close
  530. */
  531. static void atadev_close ( struct ata_device *atadev, int rc ) {
  532. struct ata_command *atacmd;
  533. struct ata_command *tmp;
  534. /* Shut down interfaces */
  535. intf_shutdown ( &atadev->block, rc );
  536. intf_shutdown ( &atadev->ata, rc );
  537. /* Shut down any remaining commands */
  538. list_for_each_entry_safe ( atacmd, tmp, &ata_commands, list ) {
  539. if ( atacmd->atadev != atadev )
  540. continue;
  541. atacmd_get ( atacmd );
  542. atacmd_close ( atacmd, rc );
  543. atacmd_put ( atacmd );
  544. }
  545. }
  546. /**
  547. * Describe ATA device using EDD
  548. *
  549. * @v atadev ATA device
  550. * @v type EDD interface type
  551. * @v path EDD device path
  552. * @ret rc Return status code
  553. */
  554. static int atadev_edd_describe ( struct ata_device *atadev,
  555. struct edd_interface_type *type,
  556. union edd_device_path *path ) {
  557. type->type = cpu_to_le64 ( EDD_INTF_TYPE_ATA );
  558. path->ata.slave = ( ( atadev->device == ATA_DEV_SLAVE ) ? 0x01 : 0x00 );
  559. return 0;
  560. }
  561. /** ATA device block interface operations */
  562. static struct interface_operation atadev_block_op[] = {
  563. INTF_OP ( block_read, struct ata_device *, atadev_read ),
  564. INTF_OP ( block_write, struct ata_device *, atadev_write ),
  565. INTF_OP ( block_read_capacity, struct ata_device *,
  566. atadev_read_capacity ),
  567. INTF_OP ( intf_close, struct ata_device *, atadev_close ),
  568. INTF_OP ( edd_describe, struct ata_device *, atadev_edd_describe ),
  569. };
  570. /** ATA device block interface descriptor */
  571. static struct interface_descriptor atadev_block_desc =
  572. INTF_DESC_PASSTHRU ( struct ata_device, block,
  573. atadev_block_op, ata );
  574. /** ATA device ATA interface operations */
  575. static struct interface_operation atadev_ata_op[] = {
  576. INTF_OP ( intf_close, struct ata_device *, atadev_close ),
  577. };
  578. /** ATA device ATA interface descriptor */
  579. static struct interface_descriptor atadev_ata_desc =
  580. INTF_DESC_PASSTHRU ( struct ata_device, ata,
  581. atadev_ata_op, block );
  582. /**
  583. * Open ATA device
  584. *
  585. * @v block Block control interface
  586. * @v ata ATA control interface
  587. * @v device ATA device number
  588. * @v max_count Maximum number of blocks per single transfer
  589. * @ret rc Return status code
  590. */
  591. int ata_open ( struct interface *block, struct interface *ata,
  592. unsigned int device, unsigned int max_count ) {
  593. struct ata_device *atadev;
  594. /* Allocate and initialise structure */
  595. atadev = zalloc ( sizeof ( *atadev ) );
  596. if ( ! atadev )
  597. return -ENOMEM;
  598. ref_init ( &atadev->refcnt, NULL );
  599. intf_init ( &atadev->block, &atadev_block_desc, &atadev->refcnt );
  600. intf_init ( &atadev->ata, &atadev_ata_desc, &atadev->refcnt );
  601. atadev->device = device;
  602. atadev->max_count = max_count;
  603. /* Attach to ATA and parent and interfaces, mortalise self,
  604. * and return
  605. */
  606. intf_plug_plug ( &atadev->ata, ata );
  607. intf_plug_plug ( &atadev->block, block );
  608. ref_put ( &atadev->refcnt );
  609. return 0;
  610. }