libata-acpi.c 18 KB

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