libata-acpi.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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 <scsi/scsi_device.h>
  17. #include "libata.h"
  18. #include <acpi/acpi_bus.h>
  19. #include <acpi/acnames.h>
  20. #include <acpi/acnamesp.h>
  21. #include <acpi/acparser.h>
  22. #include <acpi/acexcep.h>
  23. #include <acpi/acmacros.h>
  24. #include <acpi/actypes.h>
  25. #define NO_PORT_MULT 0xffff
  26. #define SATA_ADR(root, pmp) (((root) << 16) | (pmp))
  27. #define REGS_PER_GTF 7
  28. struct ata_acpi_gtf {
  29. u8 tf[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */
  30. } __packed;
  31. /*
  32. * Helper - belongs in the PCI layer somewhere eventually
  33. */
  34. static int is_pci_dev(struct device *dev)
  35. {
  36. return (dev->bus == &pci_bus_type);
  37. }
  38. /**
  39. * ata_acpi_associate_sata_port - associate SATA port with ACPI objects
  40. * @ap: target SATA port
  41. *
  42. * Look up ACPI objects associated with @ap and initialize acpi_handle
  43. * fields of @ap, the port and devices accordingly.
  44. *
  45. * LOCKING:
  46. * EH context.
  47. *
  48. * RETURNS:
  49. * 0 on success, -errno on failure.
  50. */
  51. void ata_acpi_associate_sata_port(struct ata_port *ap)
  52. {
  53. WARN_ON(!(ap->flags & ATA_FLAG_ACPI_SATA));
  54. if (!ap->nr_pmp_links) {
  55. acpi_integer adr = SATA_ADR(ap->port_no, NO_PORT_MULT);
  56. ap->link.device->acpi_handle =
  57. acpi_get_child(ap->host->acpi_handle, adr);
  58. } else {
  59. struct ata_link *link;
  60. ap->link.device->acpi_handle = NULL;
  61. ata_port_for_each_link(link, ap) {
  62. acpi_integer adr = SATA_ADR(ap->port_no, link->pmp);
  63. link->device->acpi_handle =
  64. acpi_get_child(ap->host->acpi_handle, adr);
  65. }
  66. }
  67. }
  68. static void ata_acpi_associate_ide_port(struct ata_port *ap)
  69. {
  70. int max_devices, i;
  71. ap->acpi_handle = acpi_get_child(ap->host->acpi_handle, ap->port_no);
  72. if (!ap->acpi_handle)
  73. return;
  74. max_devices = 1;
  75. if (ap->flags & ATA_FLAG_SLAVE_POSS)
  76. max_devices++;
  77. for (i = 0; i < max_devices; i++) {
  78. struct ata_device *dev = &ap->link.device[i];
  79. dev->acpi_handle = acpi_get_child(ap->acpi_handle, i);
  80. }
  81. if (ata_acpi_gtm(ap, &ap->__acpi_init_gtm) == 0)
  82. ap->pflags |= ATA_PFLAG_INIT_GTM_VALID;
  83. }
  84. static void ata_acpi_handle_hotplug(struct ata_port *ap, struct kobject *kobj,
  85. u32 event)
  86. {
  87. char event_string[12];
  88. char *envp[] = { event_string, NULL };
  89. struct ata_eh_info *ehi = &ap->link.eh_info;
  90. if (event == 0 || event == 1) {
  91. unsigned long flags;
  92. spin_lock_irqsave(ap->lock, flags);
  93. ata_ehi_clear_desc(ehi);
  94. ata_ehi_push_desc(ehi, "ACPI event");
  95. ata_ehi_hotplugged(ehi);
  96. ata_port_freeze(ap);
  97. spin_unlock_irqrestore(ap->lock, flags);
  98. }
  99. if (kobj) {
  100. sprintf(event_string, "BAY_EVENT=%d", event);
  101. kobject_uevent_env(kobj, KOBJ_CHANGE, envp);
  102. }
  103. }
  104. static void ata_acpi_dev_notify(acpi_handle handle, u32 event, void *data)
  105. {
  106. struct ata_device *dev = data;
  107. struct kobject *kobj = NULL;
  108. if (dev->sdev)
  109. kobj = &dev->sdev->sdev_gendev.kobj;
  110. ata_acpi_handle_hotplug(dev->link->ap, kobj, event);
  111. }
  112. static void ata_acpi_ap_notify(acpi_handle handle, u32 event, void *data)
  113. {
  114. struct ata_port *ap = data;
  115. ata_acpi_handle_hotplug(ap, &ap->dev->kobj, event);
  116. }
  117. /**
  118. * ata_acpi_associate - associate ATA host with ACPI objects
  119. * @host: target ATA host
  120. *
  121. * Look up ACPI objects associated with @host and initialize
  122. * acpi_handle fields of @host, its ports and devices accordingly.
  123. *
  124. * LOCKING:
  125. * EH context.
  126. *
  127. * RETURNS:
  128. * 0 on success, -errno on failure.
  129. */
  130. void ata_acpi_associate(struct ata_host *host)
  131. {
  132. int i, j;
  133. if (!is_pci_dev(host->dev) || libata_noacpi)
  134. return;
  135. host->acpi_handle = DEVICE_ACPI_HANDLE(host->dev);
  136. if (!host->acpi_handle)
  137. return;
  138. for (i = 0; i < host->n_ports; i++) {
  139. struct ata_port *ap = host->ports[i];
  140. if (host->ports[0]->flags & ATA_FLAG_ACPI_SATA)
  141. ata_acpi_associate_sata_port(ap);
  142. else
  143. ata_acpi_associate_ide_port(ap);
  144. if (ap->acpi_handle)
  145. acpi_install_notify_handler (ap->acpi_handle,
  146. ACPI_SYSTEM_NOTIFY,
  147. ata_acpi_ap_notify,
  148. ap);
  149. for (j = 0; j < ata_link_max_devices(&ap->link); j++) {
  150. struct ata_device *dev = &ap->link.device[j];
  151. if (dev->acpi_handle)
  152. acpi_install_notify_handler (dev->acpi_handle,
  153. ACPI_SYSTEM_NOTIFY,
  154. ata_acpi_dev_notify,
  155. dev);
  156. }
  157. }
  158. }
  159. /**
  160. * ata_acpi_dissociate - dissociate ATA host from ACPI objects
  161. * @host: target ATA host
  162. *
  163. * This function is called during driver detach after the whole host
  164. * is shut down.
  165. *
  166. * LOCKING:
  167. * EH context.
  168. */
  169. void ata_acpi_dissociate(struct ata_host *host)
  170. {
  171. int i;
  172. /* Restore initial _GTM values so that driver which attaches
  173. * afterward can use them too.
  174. */
  175. for (i = 0; i < host->n_ports; i++) {
  176. struct ata_port *ap = host->ports[i];
  177. const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap);
  178. if (ap->acpi_handle && gtm)
  179. ata_acpi_stm(ap, gtm);
  180. }
  181. }
  182. /**
  183. * ata_acpi_gtm - execute _GTM
  184. * @ap: target ATA port
  185. * @gtm: out parameter for _GTM result
  186. *
  187. * Evaluate _GTM and store the result in @gtm.
  188. *
  189. * LOCKING:
  190. * EH context.
  191. *
  192. * RETURNS:
  193. * 0 on success, -ENOENT if _GTM doesn't exist, -errno on failure.
  194. */
  195. int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *gtm)
  196. {
  197. struct acpi_buffer output = { .length = ACPI_ALLOCATE_BUFFER };
  198. union acpi_object *out_obj;
  199. acpi_status status;
  200. int rc = 0;
  201. status = acpi_evaluate_object(ap->acpi_handle, "_GTM", NULL, &output);
  202. rc = -ENOENT;
  203. if (status == AE_NOT_FOUND)
  204. goto out_free;
  205. rc = -EINVAL;
  206. if (ACPI_FAILURE(status)) {
  207. ata_port_printk(ap, KERN_ERR,
  208. "ACPI get timing mode failed (AE 0x%x)\n",
  209. status);
  210. goto out_free;
  211. }
  212. out_obj = output.pointer;
  213. if (out_obj->type != ACPI_TYPE_BUFFER) {
  214. ata_port_printk(ap, KERN_WARNING,
  215. "_GTM returned unexpected object type 0x%x\n",
  216. out_obj->type);
  217. goto out_free;
  218. }
  219. if (out_obj->buffer.length != sizeof(struct ata_acpi_gtm)) {
  220. ata_port_printk(ap, KERN_ERR,
  221. "_GTM returned invalid length %d\n",
  222. out_obj->buffer.length);
  223. goto out_free;
  224. }
  225. memcpy(gtm, out_obj->buffer.pointer, sizeof(struct ata_acpi_gtm));
  226. rc = 0;
  227. out_free:
  228. kfree(output.pointer);
  229. return rc;
  230. }
  231. EXPORT_SYMBOL_GPL(ata_acpi_gtm);
  232. /**
  233. * ata_acpi_stm - execute _STM
  234. * @ap: target ATA port
  235. * @stm: timing parameter to _STM
  236. *
  237. * Evaluate _STM with timing parameter @stm.
  238. *
  239. * LOCKING:
  240. * EH context.
  241. *
  242. * RETURNS:
  243. * 0 on success, -ENOENT if _STM doesn't exist, -errno on failure.
  244. */
  245. int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm)
  246. {
  247. acpi_status status;
  248. struct ata_acpi_gtm stm_buf = *stm;
  249. struct acpi_object_list input;
  250. union acpi_object in_params[3];
  251. in_params[0].type = ACPI_TYPE_BUFFER;
  252. in_params[0].buffer.length = sizeof(struct ata_acpi_gtm);
  253. in_params[0].buffer.pointer = (u8 *)&stm_buf;
  254. /* Buffers for id may need byteswapping ? */
  255. in_params[1].type = ACPI_TYPE_BUFFER;
  256. in_params[1].buffer.length = 512;
  257. in_params[1].buffer.pointer = (u8 *)ap->link.device[0].id;
  258. in_params[2].type = ACPI_TYPE_BUFFER;
  259. in_params[2].buffer.length = 512;
  260. in_params[2].buffer.pointer = (u8 *)ap->link.device[1].id;
  261. input.count = 3;
  262. input.pointer = in_params;
  263. status = acpi_evaluate_object(ap->acpi_handle, "_STM", &input, NULL);
  264. if (status == AE_NOT_FOUND)
  265. return -ENOENT;
  266. if (ACPI_FAILURE(status)) {
  267. ata_port_printk(ap, KERN_ERR,
  268. "ACPI set timing mode failed (status=0x%x)\n", status);
  269. return -EINVAL;
  270. }
  271. return 0;
  272. }
  273. EXPORT_SYMBOL_GPL(ata_acpi_stm);
  274. /**
  275. * ata_dev_get_GTF - get the drive bootup default taskfile settings
  276. * @dev: target ATA device
  277. * @gtf: output parameter for buffer containing _GTF taskfile arrays
  278. * @ptr_to_free: pointer which should be freed
  279. *
  280. * This applies to both PATA and SATA drives.
  281. *
  282. * The _GTF method has no input parameters.
  283. * It returns a variable number of register set values (registers
  284. * hex 1F1..1F7, taskfiles).
  285. * The <variable number> is not known in advance, so have ACPI-CA
  286. * allocate the buffer as needed and return it, then free it later.
  287. *
  288. * LOCKING:
  289. * EH context.
  290. *
  291. * RETURNS:
  292. * Number of taskfiles on success, 0 if _GTF doesn't exist or doesn't
  293. * contain valid data.
  294. */
  295. static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
  296. void **ptr_to_free)
  297. {
  298. struct ata_port *ap = dev->link->ap;
  299. acpi_status status;
  300. struct acpi_buffer output;
  301. union acpi_object *out_obj;
  302. int rc = 0;
  303. /* set up output buffer */
  304. output.length = ACPI_ALLOCATE_BUFFER;
  305. output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
  306. if (ata_msg_probe(ap))
  307. ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
  308. __FUNCTION__, ap->port_no);
  309. /* _GTF has no input parameters */
  310. status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output);
  311. if (ACPI_FAILURE(status)) {
  312. if (status != AE_NOT_FOUND) {
  313. ata_dev_printk(dev, KERN_WARNING,
  314. "_GTF evaluation failed (AE 0x%x)\n",
  315. status);
  316. }
  317. goto out_free;
  318. }
  319. if (!output.length || !output.pointer) {
  320. if (ata_msg_probe(ap))
  321. ata_dev_printk(dev, KERN_DEBUG, "%s: Run _GTF: "
  322. "length or ptr is NULL (0x%llx, 0x%p)\n",
  323. __FUNCTION__,
  324. (unsigned long long)output.length,
  325. output.pointer);
  326. goto out_free;
  327. }
  328. out_obj = output.pointer;
  329. if (out_obj->type != ACPI_TYPE_BUFFER) {
  330. ata_dev_printk(dev, KERN_WARNING,
  331. "_GTF unexpected object type 0x%x\n",
  332. out_obj->type);
  333. goto out_free;
  334. }
  335. if (out_obj->buffer.length % REGS_PER_GTF) {
  336. ata_dev_printk(dev, KERN_WARNING,
  337. "unexpected _GTF length (%d)\n",
  338. out_obj->buffer.length);
  339. goto out_free;
  340. }
  341. *ptr_to_free = out_obj;
  342. *gtf = (void *)out_obj->buffer.pointer;
  343. rc = out_obj->buffer.length / REGS_PER_GTF;
  344. if (ata_msg_probe(ap))
  345. ata_dev_printk(dev, KERN_DEBUG, "%s: returning "
  346. "gtf=%p, gtf_count=%d, ptr_to_free=%p\n",
  347. __FUNCTION__, *gtf, rc, *ptr_to_free);
  348. return rc;
  349. out_free:
  350. kfree(output.pointer);
  351. return rc;
  352. }
  353. /**
  354. * ata_acpi_cbl_80wire - Check for 80 wire cable
  355. * @ap: Port to check
  356. *
  357. * Return 1 if the ACPI mode data for this port indicates the BIOS selected
  358. * an 80wire mode.
  359. */
  360. int ata_acpi_cbl_80wire(struct ata_port *ap)
  361. {
  362. const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap);
  363. int valid = 0;
  364. if (!gtm)
  365. return 0;
  366. /* Split timing, DMA enabled */
  367. if ((gtm->flags & 0x11) == 0x11 && gtm->drive[0].dma < 55)
  368. valid |= 1;
  369. if ((gtm->flags & 0x14) == 0x14 && gtm->drive[1].dma < 55)
  370. valid |= 2;
  371. /* Shared timing, DMA enabled */
  372. if ((gtm->flags & 0x11) == 0x01 && gtm->drive[0].dma < 55)
  373. valid |= 1;
  374. if ((gtm->flags & 0x14) == 0x04 && gtm->drive[0].dma < 55)
  375. valid |= 2;
  376. /* Drive check */
  377. if ((valid & 1) && ata_dev_enabled(&ap->link.device[0]))
  378. return 1;
  379. if ((valid & 2) && ata_dev_enabled(&ap->link.device[1]))
  380. return 1;
  381. return 0;
  382. }
  383. EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire);
  384. /**
  385. * taskfile_load_raw - send taskfile registers to host controller
  386. * @dev: target ATA device
  387. * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
  388. *
  389. * Outputs ATA taskfile to standard ATA host controller using MMIO
  390. * or PIO as indicated by the ATA_FLAG_MMIO flag.
  391. * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
  392. * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
  393. * hob_lbal, hob_lbam, and hob_lbah.
  394. *
  395. * This function waits for idle (!BUSY and !DRQ) after writing
  396. * registers. If the control register has a new value, this
  397. * function also waits for idle after writing control and before
  398. * writing the remaining registers.
  399. *
  400. * LOCKING:
  401. * EH context.
  402. *
  403. * RETURNS:
  404. * 0 on success, -errno on failure.
  405. */
  406. static int taskfile_load_raw(struct ata_device *dev,
  407. const struct ata_acpi_gtf *gtf)
  408. {
  409. struct ata_port *ap = dev->link->ap;
  410. struct ata_taskfile tf, rtf;
  411. unsigned int err_mask;
  412. if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0)
  413. && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0)
  414. && (gtf->tf[6] == 0))
  415. return 0;
  416. ata_tf_init(dev, &tf);
  417. /* convert gtf to tf */
  418. tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */
  419. tf.protocol = ATA_PROT_NODATA;
  420. tf.feature = gtf->tf[0]; /* 0x1f1 */
  421. tf.nsect = gtf->tf[1]; /* 0x1f2 */
  422. tf.lbal = gtf->tf[2]; /* 0x1f3 */
  423. tf.lbam = gtf->tf[3]; /* 0x1f4 */
  424. tf.lbah = gtf->tf[4]; /* 0x1f5 */
  425. tf.device = gtf->tf[5]; /* 0x1f6 */
  426. tf.command = gtf->tf[6]; /* 0x1f7 */
  427. if (ata_msg_probe(ap))
  428. ata_dev_printk(dev, KERN_DEBUG, "executing ACPI cmd "
  429. "%02x/%02x:%02x:%02x:%02x:%02x:%02x\n",
  430. tf.command, tf.feature, tf.nsect,
  431. tf.lbal, tf.lbam, tf.lbah, tf.device);
  432. rtf = tf;
  433. err_mask = ata_exec_internal(dev, &rtf, NULL, DMA_NONE, NULL, 0, 0);
  434. if (err_mask) {
  435. ata_dev_printk(dev, KERN_ERR,
  436. "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x failed "
  437. "(Emask=0x%x Stat=0x%02x Err=0x%02x)\n",
  438. tf.command, tf.feature, tf.nsect, tf.lbal, tf.lbam,
  439. tf.lbah, tf.device, err_mask, rtf.command, rtf.feature);
  440. return -EIO;
  441. }
  442. return 0;
  443. }
  444. /**
  445. * ata_acpi_exec_tfs - get then write drive taskfile settings
  446. * @dev: target ATA device
  447. *
  448. * Evaluate _GTF and excute returned taskfiles.
  449. *
  450. * LOCKING:
  451. * EH context.
  452. *
  453. * RETURNS:
  454. * Number of executed taskfiles on success, 0 if _GTF doesn't exist or
  455. * doesn't contain valid data. -errno on other errors.
  456. */
  457. static int ata_acpi_exec_tfs(struct ata_device *dev)
  458. {
  459. struct ata_acpi_gtf *gtf = NULL;
  460. void *ptr_to_free = NULL;
  461. int gtf_count, i, rc;
  462. /* get taskfiles */
  463. gtf_count = ata_dev_get_GTF(dev, &gtf, &ptr_to_free);
  464. /* execute them */
  465. for (i = 0, rc = 0; i < gtf_count; i++) {
  466. int tmp;
  467. /* ACPI errors are eventually ignored. Run till the
  468. * end even after errors.
  469. */
  470. tmp = taskfile_load_raw(dev, gtf++);
  471. if (!rc)
  472. rc = tmp;
  473. }
  474. kfree(ptr_to_free);
  475. if (rc == 0)
  476. return gtf_count;
  477. return rc;
  478. }
  479. /**
  480. * ata_acpi_push_id - send Identify data to drive
  481. * @dev: target ATA device
  482. *
  483. * _SDD ACPI object: for SATA mode only
  484. * Must be after Identify (Packet) Device -- uses its data
  485. * ATM this function never returns a failure. It is an optional
  486. * method and if it fails for whatever reason, we should still
  487. * just keep going.
  488. *
  489. * LOCKING:
  490. * EH context.
  491. *
  492. * RETURNS:
  493. * 0 on success, -errno on failure.
  494. */
  495. static int ata_acpi_push_id(struct ata_device *dev)
  496. {
  497. struct ata_port *ap = dev->link->ap;
  498. int err;
  499. acpi_status status;
  500. struct acpi_object_list input;
  501. union acpi_object in_params[1];
  502. if (ata_msg_probe(ap))
  503. ata_dev_printk(dev, KERN_DEBUG, "%s: ix = %d, port#: %d\n",
  504. __FUNCTION__, dev->devno, ap->port_no);
  505. /* Give the drive Identify data to the drive via the _SDD method */
  506. /* _SDD: set up input parameters */
  507. input.count = 1;
  508. input.pointer = in_params;
  509. in_params[0].type = ACPI_TYPE_BUFFER;
  510. in_params[0].buffer.length = sizeof(dev->id[0]) * ATA_ID_WORDS;
  511. in_params[0].buffer.pointer = (u8 *)dev->id;
  512. /* Output buffer: _SDD has no output */
  513. /* It's OK for _SDD to be missing too. */
  514. swap_buf_le16(dev->id, ATA_ID_WORDS);
  515. status = acpi_evaluate_object(dev->acpi_handle, "_SDD", &input, NULL);
  516. swap_buf_le16(dev->id, ATA_ID_WORDS);
  517. err = ACPI_FAILURE(status) ? -EIO : 0;
  518. if (err < 0)
  519. ata_dev_printk(dev, KERN_WARNING,
  520. "ACPI _SDD failed (AE 0x%x)\n", status);
  521. return err;
  522. }
  523. /**
  524. * ata_acpi_on_suspend - ATA ACPI hook called on suspend
  525. * @ap: target ATA port
  526. *
  527. * This function is called when @ap is about to be suspended. All
  528. * devices are already put to sleep but the port_suspend() callback
  529. * hasn't been executed yet. Error return from this function aborts
  530. * suspend.
  531. *
  532. * LOCKING:
  533. * EH context.
  534. *
  535. * RETURNS:
  536. * 0 on success, -errno on failure.
  537. */
  538. int ata_acpi_on_suspend(struct ata_port *ap)
  539. {
  540. /* nada */
  541. return 0;
  542. }
  543. /**
  544. * ata_acpi_on_resume - ATA ACPI hook called on resume
  545. * @ap: target ATA port
  546. *
  547. * This function is called when @ap is resumed - right after port
  548. * itself is resumed but before any EH action is taken.
  549. *
  550. * LOCKING:
  551. * EH context.
  552. */
  553. void ata_acpi_on_resume(struct ata_port *ap)
  554. {
  555. const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap);
  556. struct ata_device *dev;
  557. /* restore timing parameters */
  558. if (ap->acpi_handle && gtm)
  559. ata_acpi_stm(ap, gtm);
  560. /* schedule _GTF */
  561. ata_link_for_each_dev(dev, &ap->link)
  562. dev->flags |= ATA_DFLAG_ACPI_PENDING;
  563. }
  564. /**
  565. * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration
  566. * @dev: target ATA device
  567. *
  568. * This function is called when @dev is about to be configured.
  569. * IDENTIFY data might have been modified after this hook is run.
  570. *
  571. * LOCKING:
  572. * EH context.
  573. *
  574. * RETURNS:
  575. * Positive number if IDENTIFY data needs to be refreshed, 0 if not,
  576. * -errno on failure.
  577. */
  578. int ata_acpi_on_devcfg(struct ata_device *dev)
  579. {
  580. struct ata_port *ap = dev->link->ap;
  581. struct ata_eh_context *ehc = &ap->link.eh_context;
  582. int acpi_sata = ap->flags & ATA_FLAG_ACPI_SATA;
  583. int rc;
  584. if (!dev->acpi_handle)
  585. return 0;
  586. /* do we need to do _GTF? */
  587. if (!(dev->flags & ATA_DFLAG_ACPI_PENDING) &&
  588. !(acpi_sata && (ehc->i.flags & ATA_EHI_DID_HARDRESET)))
  589. return 0;
  590. /* do _SDD if SATA */
  591. if (acpi_sata) {
  592. rc = ata_acpi_push_id(dev);
  593. if (rc)
  594. goto acpi_err;
  595. }
  596. /* do _GTF */
  597. rc = ata_acpi_exec_tfs(dev);
  598. if (rc < 0)
  599. goto acpi_err;
  600. dev->flags &= ~ATA_DFLAG_ACPI_PENDING;
  601. /* refresh IDENTIFY page if any _GTF command has been executed */
  602. if (rc > 0) {
  603. rc = ata_dev_reread_id(dev, 0);
  604. if (rc < 0) {
  605. ata_dev_printk(dev, KERN_ERR, "failed to IDENTIFY "
  606. "after ACPI commands\n");
  607. return rc;
  608. }
  609. }
  610. return 0;
  611. acpi_err:
  612. /* let EH retry on the first failure, disable ACPI on the second */
  613. if (dev->flags & ATA_DFLAG_ACPI_FAILED) {
  614. ata_dev_printk(dev, KERN_WARNING, "ACPI on devcfg failed the "
  615. "second time, disabling (errno=%d)\n", rc);
  616. dev->acpi_handle = NULL;
  617. /* if port is working, request IDENTIFY reload and continue */
  618. if (!(ap->pflags & ATA_PFLAG_FROZEN))
  619. rc = 1;
  620. }
  621. dev->flags |= ATA_DFLAG_ACPI_FAILED;
  622. return rc;
  623. }
  624. /**
  625. * ata_acpi_on_disable - ATA ACPI hook called when a device is disabled
  626. * @dev: target ATA device
  627. *
  628. * This function is called when @dev is about to be disabled.
  629. *
  630. * LOCKING:
  631. * EH context.
  632. */
  633. void ata_acpi_on_disable(struct ata_device *dev)
  634. {
  635. }