libata-acpi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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,
  268. "%s: ENTER: ap->id: %d, port#: %d\n",
  269. __FUNCTION__, ap->id, ap->port_no);
  270. if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED)) {
  271. if (ata_msg_probe(ap))
  272. ata_dev_printk(atadev, KERN_DEBUG, "%s: ERR: "
  273. "ata_dev_present: %d, PORT_DISABLED: %lu\n",
  274. __FUNCTION__, ata_dev_enabled(atadev),
  275. ap->flags & ATA_FLAG_DISABLED);
  276. goto out;
  277. }
  278. /* Don't continue if device has no _ADR method.
  279. * _GTF is intended for known motherboard devices. */
  280. if (!(ap->cbl == ATA_CBL_SATA)) {
  281. err = pata_get_dev_handle(dev, &dev_handle, &pcidevfn);
  282. if (err < 0) {
  283. if (ata_msg_probe(ap))
  284. ata_dev_printk(atadev, KERN_DEBUG,
  285. "%s: pata_get_dev_handle failed (%d)\n",
  286. __FUNCTION__, err);
  287. goto out;
  288. }
  289. } else {
  290. err = sata_get_dev_handle(dev, &dev_handle, &pcidevfn);
  291. if (err < 0) {
  292. if (ata_msg_probe(ap))
  293. ata_dev_printk(atadev, KERN_DEBUG,
  294. "%s: sata_get_dev_handle failed (%d\n",
  295. __FUNCTION__, err);
  296. goto out;
  297. }
  298. }
  299. /* Get this drive's _ADR info. if not already known. */
  300. if (!atadev->obj_handle) {
  301. if (!(ap->cbl == ATA_CBL_SATA)) {
  302. /* get child objects of dev_handle == channel objects,
  303. * + _their_ children == drive objects */
  304. /* channel is ap->port_no */
  305. chan_handle = acpi_get_child(dev_handle,
  306. ap->port_no);
  307. if (ata_msg_probe(ap))
  308. ata_dev_printk(atadev, KERN_DEBUG,
  309. "%s: chan adr=%d: chan_handle=0x%p\n",
  310. __FUNCTION__, ap->port_no,
  311. chan_handle);
  312. if (!chan_handle) {
  313. err = -ENODEV;
  314. goto out;
  315. }
  316. /* TBD: could also check ACPI object VALID bits */
  317. drive_handle = acpi_get_child(chan_handle, ix);
  318. if (!drive_handle) {
  319. err = -ENODEV;
  320. goto out;
  321. }
  322. dev_adr = ix;
  323. atadev->obj_handle = drive_handle;
  324. } else { /* for SATA mode */
  325. dev_adr = SATA_ADR_RSVD;
  326. err = get_sata_adr(dev, dev_handle, pcidevfn, 0,
  327. ap, atadev, &dev_adr);
  328. }
  329. if (err < 0 || dev_adr == SATA_ADR_RSVD ||
  330. !atadev->obj_handle) {
  331. if (ata_msg_probe(ap))
  332. ata_dev_printk(atadev, KERN_DEBUG,
  333. "%s: get_sata/pata_adr failed: "
  334. "err=%d, dev_adr=%u, obj_handle=0x%p\n",
  335. __FUNCTION__, err, dev_adr,
  336. atadev->obj_handle);
  337. goto out;
  338. }
  339. }
  340. /* Setting up output buffer */
  341. output.length = ACPI_ALLOCATE_BUFFER;
  342. output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
  343. /* _GTF has no input parameters */
  344. err = -EIO;
  345. status = acpi_evaluate_object(atadev->obj_handle, "_GTF",
  346. NULL, &output);
  347. if (ACPI_FAILURE(status)) {
  348. if (ata_msg_probe(ap))
  349. ata_dev_printk(atadev, KERN_DEBUG,
  350. "%s: Run _GTF error: status = 0x%x\n",
  351. __FUNCTION__, status);
  352. goto out;
  353. }
  354. if (!output.length || !output.pointer) {
  355. if (ata_msg_probe(ap))
  356. ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: "
  357. "length or ptr is NULL (0x%llx, 0x%p)\n",
  358. __FUNCTION__,
  359. (unsigned long long)output.length,
  360. output.pointer);
  361. kfree(output.pointer);
  362. goto out;
  363. }
  364. out_obj = output.pointer;
  365. if (out_obj->type != ACPI_TYPE_BUFFER) {
  366. kfree(output.pointer);
  367. if (ata_msg_probe(ap))
  368. ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: "
  369. "error: expected object type of "
  370. " ACPI_TYPE_BUFFER, got 0x%x\n",
  371. __FUNCTION__, out_obj->type);
  372. err = -ENOENT;
  373. goto out;
  374. }
  375. if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
  376. out_obj->buffer.length % REGS_PER_GTF) {
  377. if (ata_msg_drv(ap))
  378. ata_dev_printk(atadev, KERN_ERR,
  379. "%s: unexpected GTF length (%d) or addr (0x%p)\n",
  380. __FUNCTION__, out_obj->buffer.length,
  381. out_obj->buffer.pointer);
  382. err = -ENOENT;
  383. goto out;
  384. }
  385. *gtf_length = out_obj->buffer.length;
  386. *gtf_address = (unsigned long)out_obj->buffer.pointer;
  387. *obj_loc = (unsigned long)out_obj;
  388. if (ata_msg_probe(ap))
  389. ata_dev_printk(atadev, KERN_DEBUG, "%s: returning "
  390. "gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
  391. __FUNCTION__, *gtf_length, *gtf_address, *obj_loc);
  392. err = 0;
  393. out:
  394. return err;
  395. }
  396. /**
  397. * taskfile_load_raw - send taskfile registers to host controller
  398. * @ap: Port to which output is sent
  399. * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
  400. *
  401. * Outputs ATA taskfile to standard ATA host controller using MMIO
  402. * or PIO as indicated by the ATA_FLAG_MMIO flag.
  403. * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
  404. * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
  405. * hob_lbal, hob_lbam, and hob_lbah.
  406. *
  407. * This function waits for idle (!BUSY and !DRQ) after writing
  408. * registers. If the control register has a new value, this
  409. * function also waits for idle after writing control and before
  410. * writing the remaining registers.
  411. *
  412. * LOCKING: TBD:
  413. * Inherited from caller.
  414. */
  415. static void taskfile_load_raw(struct ata_port *ap,
  416. struct ata_device *atadev,
  417. const struct taskfile_array *gtf)
  418. {
  419. if (ata_msg_probe(ap))
  420. ata_dev_printk(atadev, KERN_DEBUG, "%s: (0x1f1-1f7): hex: "
  421. "%02x %02x %02x %02x %02x %02x %02x\n",
  422. __FUNCTION__,
  423. gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
  424. gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
  425. if ((gtf->tfa[0] == 0) && (gtf->tfa[1] == 0) && (gtf->tfa[2] == 0)
  426. && (gtf->tfa[3] == 0) && (gtf->tfa[4] == 0) && (gtf->tfa[5] == 0)
  427. && (gtf->tfa[6] == 0))
  428. return;
  429. if (ap->ops->qc_issue) {
  430. struct ata_taskfile tf;
  431. unsigned int err;
  432. ata_tf_init(atadev, &tf);
  433. /* convert gtf to tf */
  434. tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */
  435. tf.protocol = atadev->class == ATA_DEV_ATAPI ?
  436. ATA_PROT_ATAPI_NODATA : ATA_PROT_NODATA;
  437. tf.feature = gtf->tfa[0]; /* 0x1f1 */
  438. tf.nsect = gtf->tfa[1]; /* 0x1f2 */
  439. tf.lbal = gtf->tfa[2]; /* 0x1f3 */
  440. tf.lbam = gtf->tfa[3]; /* 0x1f4 */
  441. tf.lbah = gtf->tfa[4]; /* 0x1f5 */
  442. tf.device = gtf->tfa[5]; /* 0x1f6 */
  443. tf.command = gtf->tfa[6]; /* 0x1f7 */
  444. err = ata_exec_internal(atadev, &tf, NULL, DMA_NONE, NULL, 0);
  445. if (err && ata_msg_probe(ap))
  446. ata_dev_printk(atadev, KERN_ERR,
  447. "%s: ata_exec_internal failed: %u\n",
  448. __FUNCTION__, err);
  449. } else
  450. if (ata_msg_warn(ap))
  451. ata_dev_printk(atadev, KERN_WARNING,
  452. "%s: SATA driver is missing qc_issue function"
  453. " entry points\n",
  454. __FUNCTION__);
  455. }
  456. /**
  457. * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
  458. * @ap: the ata_port for the drive
  459. * @atadev: 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_port *ap,
  469. struct ata_device *atadev, unsigned int gtf_length,
  470. unsigned long gtf_address)
  471. {
  472. int err = -ENODEV;
  473. int gtf_count = gtf_length / REGS_PER_GTF;
  474. int ix;
  475. struct taskfile_array *gtf;
  476. if (ata_msg_probe(ap))
  477. ata_dev_printk(atadev, KERN_DEBUG,
  478. "%s: ENTER: ap->id: %d, port#: %d\n",
  479. __FUNCTION__, ap->id, ap->port_no);
  480. if (noacpi || !(ap->cbl == ATA_CBL_SATA))
  481. return 0;
  482. if (!ata_dev_enabled(atadev) || (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(atadev, 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(ap, atadev, 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 (noacpi)
  517. return 0;
  518. for (ix = 0; ix < ATA_MAX_DEVICES; ix++) {
  519. if (!ata_dev_enabled(&ap->device[ix]))
  520. continue;
  521. ret = do_drive_get_GTF(ap, ix,
  522. &gtf_length, &gtf_address, &obj_loc);
  523. if (ret < 0) {
  524. if (ata_msg_probe(ap))
  525. ata_port_printk(ap, KERN_DEBUG,
  526. "%s: get_GTF error (%d)\n",
  527. __FUNCTION__, ret);
  528. break;
  529. }
  530. ret = do_drive_set_taskfiles(ap, &ap->device[ix],
  531. gtf_length, gtf_address);
  532. kfree((void *)obj_loc);
  533. if (ret < 0) {
  534. if (ata_msg_probe(ap))
  535. ata_port_printk(ap, KERN_DEBUG,
  536. "%s: set_taskfiles error (%d)\n",
  537. __FUNCTION__, ret);
  538. break;
  539. }
  540. }
  541. return ret;
  542. }
  543. /**
  544. * ata_acpi_push_id - send Identify data to drive
  545. * @ap: the ata_port for the drive
  546. * @ix: drive index
  547. *
  548. * _SDD ACPI object: for SATA mode only
  549. * Must be after Identify (Packet) Device -- uses its data
  550. * ATM this function never returns a failure. It is an optional
  551. * method and if it fails for whatever reason, we should still
  552. * just keep going.
  553. */
  554. int ata_acpi_push_id(struct ata_port *ap, unsigned int ix)
  555. {
  556. acpi_handle handle;
  557. acpi_integer pcidevfn;
  558. int err;
  559. struct device *dev = ap->host->dev;
  560. struct ata_device *atadev = &ap->device[ix];
  561. u32 dev_adr;
  562. acpi_status status;
  563. struct acpi_object_list input;
  564. union acpi_object in_params[1];
  565. if (noacpi)
  566. return 0;
  567. if (ata_msg_probe(ap))
  568. ata_dev_printk(atadev, KERN_DEBUG,
  569. "%s: ap->id: %d, ix = %d, port#: %d\n",
  570. __FUNCTION__, ap->id, ix, ap->port_no);
  571. /* Don't continue if not a SATA device. */
  572. if (!(ap->cbl == ATA_CBL_SATA)) {
  573. if (ata_msg_probe(ap))
  574. ata_dev_printk(atadev, KERN_DEBUG,
  575. "%s: Not a SATA device\n", __FUNCTION__);
  576. goto out;
  577. }
  578. /* Don't continue if device has no _ADR method.
  579. * _SDD is intended for known motherboard devices. */
  580. err = sata_get_dev_handle(dev, &handle, &pcidevfn);
  581. if (err < 0) {
  582. if (ata_msg_probe(ap))
  583. ata_dev_printk(atadev, KERN_DEBUG,
  584. "%s: sata_get_dev_handle failed (%d\n",
  585. __FUNCTION__, err);
  586. goto out;
  587. }
  588. /* Get this drive's _ADR info, if not already known */
  589. if (!atadev->obj_handle) {
  590. dev_adr = SATA_ADR_RSVD;
  591. err = get_sata_adr(dev, handle, pcidevfn, ix, ap, atadev,
  592. &dev_adr);
  593. if (err < 0 || dev_adr == SATA_ADR_RSVD ||
  594. !atadev->obj_handle) {
  595. if (ata_msg_probe(ap))
  596. ata_dev_printk(atadev, KERN_DEBUG,
  597. "%s: get_sata_adr failed: "
  598. "err=%d, dev_adr=%u, obj_handle=0x%p\n",
  599. __FUNCTION__, err, dev_adr,
  600. atadev->obj_handle);
  601. goto out;
  602. }
  603. }
  604. /* Give the drive Identify data to the drive via the _SDD method */
  605. /* _SDD: set up input parameters */
  606. input.count = 1;
  607. input.pointer = in_params;
  608. in_params[0].type = ACPI_TYPE_BUFFER;
  609. in_params[0].buffer.length = sizeof(atadev->id[0] * ATA_ID_WORDS);
  610. in_params[0].buffer.pointer = (u8 *)atadev->id;
  611. /* Output buffer: _SDD has no output */
  612. /* It's OK for _SDD to be missing too. */
  613. swap_buf_le16(atadev->id, ATA_ID_WORDS);
  614. status = acpi_evaluate_object(atadev->obj_handle, "_SDD", &input, NULL);
  615. swap_buf_le16(atadev->id, ATA_ID_WORDS);
  616. err = ACPI_FAILURE(status) ? -EIO : 0;
  617. if (err < 0) {
  618. if (ata_msg_probe(ap))
  619. ata_dev_printk(atadev, KERN_DEBUG,
  620. "ata%u(%u): %s _SDD error: status = 0x%x\n",
  621. ap->id, ap->device->devno,
  622. __FUNCTION__, status);
  623. }
  624. /* always return success */
  625. out:
  626. return 0;
  627. }