libata-acpi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. * libata-acpi.c
  3. * Provides ACPI support for PATA/SATA.
  4. *
  5. * Copyright (C) 2006 Intel Corp.
  6. * Copyright (C) 2006 Randy Dunlap
  7. */
  8. #include <linux/ata.h>
  9. #include <linux/delay.h>
  10. #include <linux/device.h>
  11. #include <linux/errno.h>
  12. #include <linux/kernel.h>
  13. #include <linux/acpi.h>
  14. #include <linux/libata.h>
  15. #include <linux/pci.h>
  16. #include "libata.h"
  17. #include <acpi/acpi_bus.h>
  18. #include <acpi/acnames.h>
  19. #include <acpi/acnamesp.h>
  20. #include <acpi/acparser.h>
  21. #include <acpi/acexcep.h>
  22. #include <acpi/acmacros.h>
  23. #include <acpi/actypes.h>
  24. #define SATA_ROOT_PORT(x) (((x) >> 16) & 0xffff)
  25. #define SATA_PORT_NUMBER(x) ((x) & 0xffff) /* or NO_PORT_MULT */
  26. #define NO_PORT_MULT 0xffff
  27. #define SATA_ADR_RSVD 0xffffffff
  28. #define REGS_PER_GTF 7
  29. struct taskfile_array {
  30. u8 tfa[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */
  31. };
  32. /**
  33. * sata_get_dev_handle - finds acpi_handle and PCI device.function
  34. * @dev: device to locate
  35. * @handle: returned acpi_handle for @dev
  36. * @pcidevfn: return PCI device.func for @dev
  37. *
  38. * This function is somewhat SATA-specific. Or at least the
  39. * PATA & SATA versions of this function are different,
  40. * so it's not entirely generic code.
  41. *
  42. * Returns 0 on success, <0 on error.
  43. */
  44. static int sata_get_dev_handle(struct device *dev, acpi_handle *handle,
  45. acpi_integer *pcidevfn)
  46. {
  47. struct pci_dev *pci_dev;
  48. acpi_integer addr;
  49. pci_dev = to_pci_dev(dev); /* NOTE: PCI-specific */
  50. /* Please refer to the ACPI spec for the syntax of _ADR. */
  51. addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
  52. *pcidevfn = addr;
  53. *handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
  54. if (!*handle)
  55. return -ENODEV;
  56. return 0;
  57. }
  58. /**
  59. * pata_get_dev_handle - finds acpi_handle and PCI device.function
  60. * @dev: device to locate
  61. * @handle: returned acpi_handle for @dev
  62. * @pcidevfn: return PCI device.func for @dev
  63. *
  64. * The PATA and SATA versions of this function are different.
  65. *
  66. * Returns 0 on success, <0 on error.
  67. */
  68. static int pata_get_dev_handle(struct device *dev, acpi_handle *handle,
  69. acpi_integer *pcidevfn)
  70. {
  71. unsigned int bus, devnum, func;
  72. acpi_integer addr;
  73. acpi_handle dev_handle, parent_handle;
  74. struct acpi_buffer buffer = {.length = ACPI_ALLOCATE_BUFFER,
  75. .pointer = NULL};
  76. acpi_status status;
  77. struct acpi_device_info *dinfo = NULL;
  78. int ret = -ENODEV;
  79. struct pci_dev *pdev = to_pci_dev(dev);
  80. bus = pdev->bus->number;
  81. devnum = PCI_SLOT(pdev->devfn);
  82. func = PCI_FUNC(pdev->devfn);
  83. dev_handle = DEVICE_ACPI_HANDLE(dev);
  84. parent_handle = DEVICE_ACPI_HANDLE(dev->parent);
  85. status = acpi_get_object_info(parent_handle, &buffer);
  86. if (ACPI_FAILURE(status))
  87. goto err;
  88. dinfo = buffer.pointer;
  89. if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
  90. dinfo->address == bus) {
  91. /* ACPI spec for _ADR for PCI bus: */
  92. addr = (acpi_integer)(devnum << 16 | func);
  93. *pcidevfn = addr;
  94. *handle = dev_handle;
  95. } else {
  96. goto err;
  97. }
  98. if (!*handle)
  99. goto err;
  100. ret = 0;
  101. err:
  102. kfree(dinfo);
  103. return ret;
  104. }
  105. struct walk_info { /* can be trimmed some */
  106. struct device *dev;
  107. struct acpi_device *adev;
  108. acpi_handle handle;
  109. acpi_integer pcidevfn;
  110. unsigned int drivenum;
  111. acpi_handle obj_handle;
  112. struct ata_port *ataport;
  113. struct ata_device *atadev;
  114. u32 sata_adr;
  115. int status;
  116. char basepath[ACPI_PATHNAME_MAX];
  117. int basepath_len;
  118. };
  119. static acpi_status get_devices(acpi_handle handle,
  120. u32 level, void *context, void **return_value)
  121. {
  122. acpi_status status;
  123. struct walk_info *winfo = context;
  124. struct acpi_buffer namebuf = {ACPI_ALLOCATE_BUFFER, NULL};
  125. char *pathname;
  126. struct acpi_buffer buffer;
  127. struct acpi_device_info *dinfo;
  128. status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &namebuf);
  129. if (status)
  130. goto ret;
  131. pathname = namebuf.pointer;
  132. buffer.length = ACPI_ALLOCATE_BUFFER;
  133. buffer.pointer = NULL;
  134. status = acpi_get_object_info(handle, &buffer);
  135. if (ACPI_FAILURE(status))
  136. goto out2;
  137. dinfo = buffer.pointer;
  138. /* find full device path name for pcidevfn */
  139. if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
  140. dinfo->address == winfo->pcidevfn) {
  141. if (ata_msg_probe(winfo->ataport))
  142. ata_dev_printk(winfo->atadev, KERN_DEBUG,
  143. ":%s: matches pcidevfn (0x%llx)\n",
  144. pathname, winfo->pcidevfn);
  145. strlcpy(winfo->basepath, pathname,
  146. sizeof(winfo->basepath));
  147. winfo->basepath_len = strlen(pathname);
  148. goto out;
  149. }
  150. /* if basepath is not yet known, ignore this object */
  151. if (!winfo->basepath_len)
  152. goto out;
  153. /* if this object is in scope of basepath, maybe use it */
  154. if (strncmp(pathname, winfo->basepath,
  155. winfo->basepath_len) == 0) {
  156. if (!(dinfo->valid & ACPI_VALID_ADR))
  157. goto out;
  158. if (ata_msg_probe(winfo->ataport))
  159. ata_dev_printk(winfo->atadev, KERN_DEBUG,
  160. "GOT ONE: (%s) root_port = 0x%llx,"
  161. " port_num = 0x%llx\n", pathname,
  162. SATA_ROOT_PORT(dinfo->address),
  163. SATA_PORT_NUMBER(dinfo->address));
  164. /* heuristics: */
  165. if (SATA_PORT_NUMBER(dinfo->address) != NO_PORT_MULT)
  166. if (ata_msg_probe(winfo->ataport))
  167. ata_dev_printk(winfo->atadev,
  168. KERN_DEBUG, "warning: don't"
  169. " know how to handle SATA port"
  170. " multiplier\n");
  171. if (SATA_ROOT_PORT(dinfo->address) ==
  172. winfo->ataport->port_no &&
  173. SATA_PORT_NUMBER(dinfo->address) == NO_PORT_MULT) {
  174. if (ata_msg_probe(winfo->ataport))
  175. ata_dev_printk(winfo->atadev,
  176. KERN_DEBUG,
  177. "THIS ^^^^^ is the requested"
  178. " SATA drive (handle = 0x%p)\n",
  179. handle);
  180. winfo->sata_adr = dinfo->address;
  181. winfo->obj_handle = handle;
  182. }
  183. }
  184. out:
  185. kfree(dinfo);
  186. out2:
  187. kfree(pathname);
  188. ret:
  189. return status;
  190. }
  191. /* Get the SATA drive _ADR object. */
  192. static int get_sata_adr(struct device *dev, acpi_handle handle,
  193. acpi_integer pcidevfn, unsigned int drive,
  194. struct ata_port *ap,
  195. struct ata_device *atadev, u32 *dev_adr)
  196. {
  197. acpi_status status;
  198. struct walk_info *winfo;
  199. int err = -ENOMEM;
  200. winfo = kzalloc(sizeof(struct walk_info), GFP_KERNEL);
  201. if (!winfo)
  202. goto out;
  203. winfo->dev = dev;
  204. winfo->atadev = atadev;
  205. winfo->ataport = ap;
  206. if (acpi_bus_get_device(handle, &winfo->adev) < 0)
  207. if (ata_msg_probe(ap))
  208. ata_dev_printk(winfo->atadev, KERN_DEBUG,
  209. "acpi_bus_get_device failed\n");
  210. winfo->handle = handle;
  211. winfo->pcidevfn = pcidevfn;
  212. winfo->drivenum = drive;
  213. status = acpi_get_devices(NULL, get_devices, winfo, NULL);
  214. if (ACPI_FAILURE(status)) {
  215. if (ata_msg_probe(ap))
  216. ata_dev_printk(winfo->atadev, KERN_DEBUG,
  217. "%s: acpi_get_devices failed\n",
  218. __FUNCTION__);
  219. err = -ENODEV;
  220. } else {
  221. *dev_adr = winfo->sata_adr;
  222. atadev->obj_handle = winfo->obj_handle;
  223. err = 0;
  224. }
  225. kfree(winfo);
  226. out:
  227. return err;
  228. }
  229. /**
  230. * do_drive_get_GTF - get the drive bootup default taskfile settings
  231. * @ap: the ata_port for the drive
  232. * @ix: target ata_device (drive) index
  233. * @gtf_length: number of bytes of _GTF data returned at @gtf_address
  234. * @gtf_address: buffer containing _GTF taskfile arrays
  235. *
  236. * This applies to both PATA and SATA drives.
  237. *
  238. * The _GTF method has no input parameters.
  239. * It returns a variable number of register set values (registers
  240. * hex 1F1..1F7, taskfiles).
  241. * The <variable number> is not known in advance, so have ACPI-CA
  242. * allocate the buffer as needed and return it, then free it later.
  243. *
  244. * The returned @gtf_length and @gtf_address are only valid if the
  245. * function return value is 0.
  246. */
  247. static int do_drive_get_GTF(struct ata_port *ap, int ix,
  248. unsigned int *gtf_length, unsigned long *gtf_address,
  249. unsigned long *obj_loc)
  250. {
  251. acpi_status status;
  252. acpi_handle dev_handle = NULL;
  253. acpi_handle chan_handle, drive_handle;
  254. acpi_integer pcidevfn = 0;
  255. u32 dev_adr;
  256. struct acpi_buffer output;
  257. union acpi_object *out_obj;
  258. struct device *dev = ap->host->dev;
  259. struct ata_device *atadev = &ap->device[ix];
  260. int err = -ENODEV;
  261. *gtf_length = 0;
  262. *gtf_address = 0UL;
  263. *obj_loc = 0UL;
  264. if (noacpi)
  265. return 0;
  266. if (ata_msg_probe(ap))
  267. ata_dev_printk(atadev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
  268. __FUNCTION__, ap->port_no);
  269. if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED)) {
  270. if (ata_msg_probe(ap))
  271. ata_dev_printk(atadev, KERN_DEBUG, "%s: ERR: "
  272. "ata_dev_present: %d, PORT_DISABLED: %lu\n",
  273. __FUNCTION__, ata_dev_enabled(atadev),
  274. ap->flags & ATA_FLAG_DISABLED);
  275. goto out;
  276. }
  277. /* Don't continue if device has no _ADR method.
  278. * _GTF is intended for known motherboard devices. */
  279. if (!(ap->cbl == ATA_CBL_SATA)) {
  280. err = pata_get_dev_handle(dev, &dev_handle, &pcidevfn);
  281. if (err < 0) {
  282. if (ata_msg_probe(ap))
  283. ata_dev_printk(atadev, KERN_DEBUG,
  284. "%s: pata_get_dev_handle failed (%d)\n",
  285. __FUNCTION__, err);
  286. goto out;
  287. }
  288. } else {
  289. err = sata_get_dev_handle(dev, &dev_handle, &pcidevfn);
  290. if (err < 0) {
  291. if (ata_msg_probe(ap))
  292. ata_dev_printk(atadev, KERN_DEBUG,
  293. "%s: sata_get_dev_handle failed (%d\n",
  294. __FUNCTION__, err);
  295. goto out;
  296. }
  297. }
  298. /* Get this drive's _ADR info. if not already known. */
  299. if (!atadev->obj_handle) {
  300. if (!(ap->cbl == ATA_CBL_SATA)) {
  301. /* get child objects of dev_handle == channel objects,
  302. * + _their_ children == drive objects */
  303. /* channel is ap->port_no */
  304. chan_handle = acpi_get_child(dev_handle,
  305. ap->port_no);
  306. if (ata_msg_probe(ap))
  307. ata_dev_printk(atadev, KERN_DEBUG,
  308. "%s: chan adr=%d: chan_handle=0x%p\n",
  309. __FUNCTION__, ap->port_no,
  310. chan_handle);
  311. if (!chan_handle) {
  312. err = -ENODEV;
  313. goto out;
  314. }
  315. /* TBD: could also check ACPI object VALID bits */
  316. drive_handle = acpi_get_child(chan_handle, ix);
  317. if (!drive_handle) {
  318. err = -ENODEV;
  319. goto out;
  320. }
  321. dev_adr = ix;
  322. atadev->obj_handle = drive_handle;
  323. } else { /* for SATA mode */
  324. dev_adr = SATA_ADR_RSVD;
  325. err = get_sata_adr(dev, dev_handle, pcidevfn, 0,
  326. ap, atadev, &dev_adr);
  327. }
  328. if (err < 0 || dev_adr == SATA_ADR_RSVD ||
  329. !atadev->obj_handle) {
  330. if (ata_msg_probe(ap))
  331. ata_dev_printk(atadev, KERN_DEBUG,
  332. "%s: get_sata/pata_adr failed: "
  333. "err=%d, dev_adr=%u, obj_handle=0x%p\n",
  334. __FUNCTION__, err, dev_adr,
  335. atadev->obj_handle);
  336. goto out;
  337. }
  338. }
  339. /* Setting up output buffer */
  340. output.length = ACPI_ALLOCATE_BUFFER;
  341. output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
  342. /* _GTF has no input parameters */
  343. err = -EIO;
  344. status = acpi_evaluate_object(atadev->obj_handle, "_GTF",
  345. NULL, &output);
  346. if (ACPI_FAILURE(status)) {
  347. if (ata_msg_probe(ap))
  348. ata_dev_printk(atadev, KERN_DEBUG,
  349. "%s: Run _GTF error: status = 0x%x\n",
  350. __FUNCTION__, status);
  351. goto out;
  352. }
  353. if (!output.length || !output.pointer) {
  354. if (ata_msg_probe(ap))
  355. ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: "
  356. "length or ptr is NULL (0x%llx, 0x%p)\n",
  357. __FUNCTION__,
  358. (unsigned long long)output.length,
  359. output.pointer);
  360. kfree(output.pointer);
  361. goto out;
  362. }
  363. out_obj = output.pointer;
  364. if (out_obj->type != ACPI_TYPE_BUFFER) {
  365. kfree(output.pointer);
  366. if (ata_msg_probe(ap))
  367. ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: "
  368. "error: expected object type of "
  369. " ACPI_TYPE_BUFFER, got 0x%x\n",
  370. __FUNCTION__, out_obj->type);
  371. err = -ENOENT;
  372. goto out;
  373. }
  374. if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
  375. out_obj->buffer.length % REGS_PER_GTF) {
  376. if (ata_msg_drv(ap))
  377. ata_dev_printk(atadev, KERN_ERR,
  378. "%s: unexpected GTF length (%d) or addr (0x%p)\n",
  379. __FUNCTION__, out_obj->buffer.length,
  380. out_obj->buffer.pointer);
  381. err = -ENOENT;
  382. goto out;
  383. }
  384. *gtf_length = out_obj->buffer.length;
  385. *gtf_address = (unsigned long)out_obj->buffer.pointer;
  386. *obj_loc = (unsigned long)out_obj;
  387. if (ata_msg_probe(ap))
  388. ata_dev_printk(atadev, KERN_DEBUG, "%s: returning "
  389. "gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
  390. __FUNCTION__, *gtf_length, *gtf_address, *obj_loc);
  391. err = 0;
  392. out:
  393. return err;
  394. }
  395. /**
  396. * taskfile_load_raw - send taskfile registers to host controller
  397. * @ap: Port to which output is sent
  398. * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
  399. *
  400. * Outputs ATA taskfile to standard ATA host controller using MMIO
  401. * or PIO as indicated by the ATA_FLAG_MMIO flag.
  402. * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
  403. * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
  404. * hob_lbal, hob_lbam, and hob_lbah.
  405. *
  406. * This function waits for idle (!BUSY and !DRQ) after writing
  407. * registers. If the control register has a new value, this
  408. * function also waits for idle after writing control and before
  409. * writing the remaining registers.
  410. *
  411. * LOCKING: TBD:
  412. * Inherited from caller.
  413. */
  414. static void taskfile_load_raw(struct ata_port *ap,
  415. struct ata_device *atadev,
  416. const struct taskfile_array *gtf)
  417. {
  418. struct ata_taskfile tf;
  419. unsigned int err;
  420. if (ata_msg_probe(ap))
  421. ata_dev_printk(atadev, KERN_DEBUG, "%s: (0x1f1-1f7): hex: "
  422. "%02x %02x %02x %02x %02x %02x %02x\n",
  423. __FUNCTION__,
  424. gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
  425. gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
  426. if ((gtf->tfa[0] == 0) && (gtf->tfa[1] == 0) && (gtf->tfa[2] == 0)
  427. && (gtf->tfa[3] == 0) && (gtf->tfa[4] == 0) && (gtf->tfa[5] == 0)
  428. && (gtf->tfa[6] == 0))
  429. return;
  430. ata_tf_init(atadev, &tf);
  431. /* convert gtf to tf */
  432. tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */
  433. tf.protocol = atadev->class == ATA_DEV_ATAPI ?
  434. ATA_PROT_ATAPI_NODATA : ATA_PROT_NODATA;
  435. tf.feature = gtf->tfa[0]; /* 0x1f1 */
  436. tf.nsect = gtf->tfa[1]; /* 0x1f2 */
  437. tf.lbal = gtf->tfa[2]; /* 0x1f3 */
  438. tf.lbam = gtf->tfa[3]; /* 0x1f4 */
  439. tf.lbah = gtf->tfa[4]; /* 0x1f5 */
  440. tf.device = gtf->tfa[5]; /* 0x1f6 */
  441. tf.command = gtf->tfa[6]; /* 0x1f7 */
  442. err = ata_exec_internal(atadev, &tf, NULL, DMA_NONE, NULL, 0);
  443. if (err && ata_msg_probe(ap))
  444. ata_dev_printk(atadev, KERN_ERR,
  445. "%s: ata_exec_internal failed: %u\n",
  446. __FUNCTION__, err);
  447. }
  448. /**
  449. * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
  450. * @ap: the ata_port for the drive
  451. * @atadev: target ata_device
  452. * @gtf_length: total number of bytes of _GTF taskfiles
  453. * @gtf_address: location of _GTF taskfile arrays
  454. *
  455. * This applies to both PATA and SATA drives.
  456. *
  457. * Write {gtf_address, length gtf_length} in groups of
  458. * REGS_PER_GTF bytes.
  459. */
  460. static int do_drive_set_taskfiles(struct ata_port *ap,
  461. struct ata_device *atadev, unsigned int gtf_length,
  462. unsigned long gtf_address)
  463. {
  464. int err = -ENODEV;
  465. int gtf_count = gtf_length / REGS_PER_GTF;
  466. int ix;
  467. struct taskfile_array *gtf;
  468. if (ata_msg_probe(ap))
  469. ata_dev_printk(atadev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
  470. __FUNCTION__, ap->port_no);
  471. if (noacpi || !(ap->cbl == ATA_CBL_SATA))
  472. return 0;
  473. if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED))
  474. goto out;
  475. if (!gtf_count) /* shouldn't be here */
  476. goto out;
  477. if (gtf_length % REGS_PER_GTF) {
  478. if (ata_msg_drv(ap))
  479. ata_dev_printk(atadev, KERN_ERR,
  480. "%s: unexpected GTF length (%d)\n",
  481. __FUNCTION__, gtf_length);
  482. goto out;
  483. }
  484. for (ix = 0; ix < gtf_count; ix++) {
  485. gtf = (struct taskfile_array *)
  486. (gtf_address + ix * REGS_PER_GTF);
  487. /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
  488. taskfile_load_raw(ap, atadev, gtf);
  489. }
  490. err = 0;
  491. out:
  492. return err;
  493. }
  494. /**
  495. * ata_acpi_exec_tfs - get then write drive taskfile settings
  496. * @ap: the ata_port for the drive
  497. *
  498. * This applies to both PATA and SATA drives.
  499. */
  500. int ata_acpi_exec_tfs(struct ata_port *ap)
  501. {
  502. int ix;
  503. int ret =0;
  504. unsigned int gtf_length;
  505. unsigned long gtf_address;
  506. unsigned long obj_loc;
  507. if (noacpi)
  508. return 0;
  509. /*
  510. * TBD - implement PATA support. For now,
  511. * we should not run GTF on PATA devices since some
  512. * PATA require execution of GTM/STM before GTF.
  513. */
  514. if (!(ap->cbl == ATA_CBL_SATA))
  515. return 0;
  516. for (ix = 0; ix < ATA_MAX_DEVICES; ix++) {
  517. if (!ata_dev_enabled(&ap->device[ix]))
  518. continue;
  519. ret = do_drive_get_GTF(ap, ix,
  520. &gtf_length, &gtf_address, &obj_loc);
  521. if (ret < 0) {
  522. if (ata_msg_probe(ap))
  523. ata_port_printk(ap, KERN_DEBUG,
  524. "%s: get_GTF error (%d)\n",
  525. __FUNCTION__, ret);
  526. break;
  527. }
  528. ret = do_drive_set_taskfiles(ap, &ap->device[ix],
  529. gtf_length, gtf_address);
  530. kfree((void *)obj_loc);
  531. if (ret < 0) {
  532. if (ata_msg_probe(ap))
  533. ata_port_printk(ap, KERN_DEBUG,
  534. "%s: set_taskfiles error (%d)\n",
  535. __FUNCTION__, ret);
  536. break;
  537. }
  538. }
  539. return ret;
  540. }
  541. /**
  542. * ata_acpi_push_id - send Identify data to drive
  543. * @ap: the ata_port for the drive
  544. * @ix: drive index
  545. *
  546. * _SDD ACPI object: for SATA mode only
  547. * Must be after Identify (Packet) Device -- uses its data
  548. * ATM this function never returns a failure. It is an optional
  549. * method and if it fails for whatever reason, we should still
  550. * just keep going.
  551. */
  552. int ata_acpi_push_id(struct ata_port *ap, unsigned int ix)
  553. {
  554. acpi_handle handle;
  555. acpi_integer pcidevfn;
  556. int err;
  557. struct device *dev = ap->host->dev;
  558. struct ata_device *atadev = &ap->device[ix];
  559. u32 dev_adr;
  560. acpi_status status;
  561. struct acpi_object_list input;
  562. union acpi_object in_params[1];
  563. if (noacpi)
  564. return 0;
  565. if (ata_msg_probe(ap))
  566. ata_dev_printk(atadev, KERN_DEBUG, "%s: ix = %d, port#: %d\n",
  567. __FUNCTION__, ix, ap->port_no);
  568. /* Don't continue if not a SATA device. */
  569. if (!(ap->cbl == ATA_CBL_SATA)) {
  570. if (ata_msg_probe(ap))
  571. ata_dev_printk(atadev, KERN_DEBUG,
  572. "%s: Not a SATA device\n", __FUNCTION__);
  573. goto out;
  574. }
  575. /* Don't continue if device has no _ADR method.
  576. * _SDD is intended for known motherboard devices. */
  577. err = sata_get_dev_handle(dev, &handle, &pcidevfn);
  578. if (err < 0) {
  579. if (ata_msg_probe(ap))
  580. ata_dev_printk(atadev, KERN_DEBUG,
  581. "%s: sata_get_dev_handle failed (%d\n",
  582. __FUNCTION__, err);
  583. goto out;
  584. }
  585. /* Get this drive's _ADR info, if not already known */
  586. if (!atadev->obj_handle) {
  587. dev_adr = SATA_ADR_RSVD;
  588. err = get_sata_adr(dev, handle, pcidevfn, ix, ap, atadev,
  589. &dev_adr);
  590. if (err < 0 || dev_adr == SATA_ADR_RSVD ||
  591. !atadev->obj_handle) {
  592. if (ata_msg_probe(ap))
  593. ata_dev_printk(atadev, KERN_DEBUG,
  594. "%s: get_sata_adr failed: "
  595. "err=%d, dev_adr=%u, obj_handle=0x%p\n",
  596. __FUNCTION__, err, dev_adr,
  597. atadev->obj_handle);
  598. goto out;
  599. }
  600. }
  601. /* Give the drive Identify data to the drive via the _SDD method */
  602. /* _SDD: set up input parameters */
  603. input.count = 1;
  604. input.pointer = in_params;
  605. in_params[0].type = ACPI_TYPE_BUFFER;
  606. in_params[0].buffer.length = sizeof(atadev->id[0]) * ATA_ID_WORDS;
  607. in_params[0].buffer.pointer = (u8 *)atadev->id;
  608. /* Output buffer: _SDD has no output */
  609. /* It's OK for _SDD to be missing too. */
  610. swap_buf_le16(atadev->id, ATA_ID_WORDS);
  611. status = acpi_evaluate_object(atadev->obj_handle, "_SDD", &input, NULL);
  612. swap_buf_le16(atadev->id, ATA_ID_WORDS);
  613. err = ACPI_FAILURE(status) ? -EIO : 0;
  614. if (err < 0) {
  615. if (ata_msg_probe(ap))
  616. ata_dev_printk(atadev, KERN_DEBUG,
  617. "%s _SDD error: status = 0x%x\n",
  618. __FUNCTION__, status);
  619. }
  620. /* always return success */
  621. out:
  622. return 0;
  623. }