ide-acpi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. /*
  2. * Provides ACPI support for IDE drives.
  3. *
  4. * Copyright (C) 2005 Intel Corp.
  5. * Copyright (C) 2005 Randy Dunlap
  6. * Copyright (C) 2006 SUSE Linux Products GmbH
  7. * Copyright (C) 2006 Hannes Reinecke
  8. */
  9. #include <linux/ata.h>
  10. #include <linux/delay.h>
  11. #include <linux/device.h>
  12. #include <linux/errno.h>
  13. #include <linux/kernel.h>
  14. #include <acpi/acpi.h>
  15. #include <linux/ide.h>
  16. #include <linux/pci.h>
  17. #include <linux/dmi.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 REGS_PER_GTF 7
  26. struct taskfile_array {
  27. u8 tfa[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */
  28. };
  29. struct GTM_buffer {
  30. u32 PIO_speed0;
  31. u32 DMA_speed0;
  32. u32 PIO_speed1;
  33. u32 DMA_speed1;
  34. u32 GTM_flags;
  35. };
  36. struct ide_acpi_drive_link {
  37. ide_drive_t *drive;
  38. acpi_handle obj_handle;
  39. u8 idbuff[512];
  40. };
  41. struct ide_acpi_hwif_link {
  42. ide_hwif_t *hwif;
  43. acpi_handle obj_handle;
  44. struct GTM_buffer gtm;
  45. struct ide_acpi_drive_link master;
  46. struct ide_acpi_drive_link slave;
  47. };
  48. #undef DEBUGGING
  49. /* note: adds function name and KERN_DEBUG */
  50. #ifdef DEBUGGING
  51. #define DEBPRINT(fmt, args...) \
  52. printk(KERN_DEBUG "%s: " fmt, __FUNCTION__, ## args)
  53. #else
  54. #define DEBPRINT(fmt, args...) do {} while (0)
  55. #endif /* DEBUGGING */
  56. extern int ide_noacpi;
  57. extern int ide_noacpitfs;
  58. extern int ide_noacpionboot;
  59. static bool ide_noacpi_psx;
  60. static int no_acpi_psx(const struct dmi_system_id *id)
  61. {
  62. ide_noacpi_psx = true;
  63. printk(KERN_NOTICE"%s detected - disable ACPI _PSx.\n", id->ident);
  64. return 0;
  65. }
  66. static const struct dmi_system_id ide_acpi_dmi_table[] = {
  67. /* Bug 9673. */
  68. /* We should check if this is because ACPI NVS isn't save/restored. */
  69. {
  70. .callback = no_acpi_psx,
  71. .ident = "HP nx9005",
  72. .matches = {
  73. DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies Ltd."),
  74. DMI_MATCH(DMI_BIOS_VERSION, "KAM1.60")
  75. },
  76. },
  77. { } /* terminate list */
  78. };
  79. static int ide_acpi_blacklist(void)
  80. {
  81. static int done;
  82. if (done)
  83. return 0;
  84. done = 1;
  85. dmi_check_system(ide_acpi_dmi_table);
  86. return 0;
  87. }
  88. /**
  89. * ide_get_dev_handle - finds acpi_handle and PCI device.function
  90. * @dev: device to locate
  91. * @handle: returned acpi_handle for @dev
  92. * @pcidevfn: return PCI device.func for @dev
  93. *
  94. * Returns the ACPI object handle to the corresponding PCI device.
  95. *
  96. * Returns 0 on success, <0 on error.
  97. */
  98. static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,
  99. acpi_integer *pcidevfn)
  100. {
  101. struct pci_dev *pdev = to_pci_dev(dev);
  102. unsigned int bus, devnum, func;
  103. acpi_integer addr;
  104. acpi_handle dev_handle;
  105. struct acpi_buffer buffer = {.length = ACPI_ALLOCATE_BUFFER,
  106. .pointer = NULL};
  107. acpi_status status;
  108. struct acpi_device_info *dinfo = NULL;
  109. int ret = -ENODEV;
  110. bus = pdev->bus->number;
  111. devnum = PCI_SLOT(pdev->devfn);
  112. func = PCI_FUNC(pdev->devfn);
  113. /* ACPI _ADR encoding for PCI bus: */
  114. addr = (acpi_integer)(devnum << 16 | func);
  115. DEBPRINT("ENTER: pci %02x:%02x.%01x\n", bus, devnum, func);
  116. dev_handle = DEVICE_ACPI_HANDLE(dev);
  117. if (!dev_handle) {
  118. DEBPRINT("no acpi handle for device\n");
  119. goto err;
  120. }
  121. status = acpi_get_object_info(dev_handle, &buffer);
  122. if (ACPI_FAILURE(status)) {
  123. DEBPRINT("get_object_info for device failed\n");
  124. goto err;
  125. }
  126. dinfo = buffer.pointer;
  127. if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
  128. dinfo->address == addr) {
  129. *pcidevfn = addr;
  130. *handle = dev_handle;
  131. } else {
  132. DEBPRINT("get_object_info for device has wrong "
  133. " address: %llu, should be %u\n",
  134. dinfo ? (unsigned long long)dinfo->address : -1ULL,
  135. (unsigned int)addr);
  136. goto err;
  137. }
  138. DEBPRINT("for dev=0x%x.%x, addr=0x%llx, *handle=0x%p\n",
  139. devnum, func, (unsigned long long)addr, *handle);
  140. ret = 0;
  141. err:
  142. kfree(dinfo);
  143. return ret;
  144. }
  145. /**
  146. * ide_acpi_hwif_get_handle - Get ACPI object handle for a given hwif
  147. * @hwif: device to locate
  148. *
  149. * Retrieves the object handle for a given hwif.
  150. *
  151. * Returns handle on success, 0 on error.
  152. */
  153. static acpi_handle ide_acpi_hwif_get_handle(ide_hwif_t *hwif)
  154. {
  155. struct device *dev = hwif->gendev.parent;
  156. acpi_handle dev_handle;
  157. acpi_integer pcidevfn;
  158. acpi_handle chan_handle;
  159. int err;
  160. DEBPRINT("ENTER: device %s\n", hwif->name);
  161. if (!dev) {
  162. DEBPRINT("no PCI device for %s\n", hwif->name);
  163. return NULL;
  164. }
  165. err = ide_get_dev_handle(dev, &dev_handle, &pcidevfn);
  166. if (err < 0) {
  167. DEBPRINT("ide_get_dev_handle failed (%d)\n", err);
  168. return NULL;
  169. }
  170. /* get child objects of dev_handle == channel objects,
  171. * + _their_ children == drive objects */
  172. /* channel is hwif->channel */
  173. chan_handle = acpi_get_child(dev_handle, hwif->channel);
  174. DEBPRINT("chan adr=%d: handle=0x%p\n",
  175. hwif->channel, chan_handle);
  176. return chan_handle;
  177. }
  178. /**
  179. * ide_acpi_drive_get_handle - Get ACPI object handle for a given drive
  180. * @drive: device to locate
  181. *
  182. * Retrieves the object handle of a given drive. According to the ACPI
  183. * spec the drive is a child of the hwif.
  184. *
  185. * Returns handle on success, 0 on error.
  186. */
  187. static acpi_handle ide_acpi_drive_get_handle(ide_drive_t *drive)
  188. {
  189. ide_hwif_t *hwif = HWIF(drive);
  190. int port;
  191. acpi_handle drive_handle;
  192. if (!hwif->acpidata)
  193. return NULL;
  194. if (!hwif->acpidata->obj_handle)
  195. return NULL;
  196. port = hwif->channel ? drive->dn - 2: drive->dn;
  197. DEBPRINT("ENTER: %s at channel#: %d port#: %d\n",
  198. drive->name, hwif->channel, port);
  199. /* TBD: could also check ACPI object VALID bits */
  200. drive_handle = acpi_get_child(hwif->acpidata->obj_handle, port);
  201. DEBPRINT("drive %s handle 0x%p\n", drive->name, drive_handle);
  202. return drive_handle;
  203. }
  204. /**
  205. * do_drive_get_GTF - get the drive bootup default taskfile settings
  206. * @drive: the drive for which the taskfile settings should be retrieved
  207. * @gtf_length: number of bytes of _GTF data returned at @gtf_address
  208. * @gtf_address: buffer containing _GTF taskfile arrays
  209. *
  210. * The _GTF method has no input parameters.
  211. * It returns a variable number of register set values (registers
  212. * hex 1F1..1F7, taskfiles).
  213. * The <variable number> is not known in advance, so have ACPI-CA
  214. * allocate the buffer as needed and return it, then free it later.
  215. *
  216. * The returned @gtf_length and @gtf_address are only valid if the
  217. * function return value is 0.
  218. */
  219. static int do_drive_get_GTF(ide_drive_t *drive,
  220. unsigned int *gtf_length, unsigned long *gtf_address,
  221. unsigned long *obj_loc)
  222. {
  223. acpi_status status;
  224. struct acpi_buffer output;
  225. union acpi_object *out_obj;
  226. ide_hwif_t *hwif = HWIF(drive);
  227. struct device *dev = hwif->gendev.parent;
  228. int err = -ENODEV;
  229. int port;
  230. *gtf_length = 0;
  231. *gtf_address = 0UL;
  232. *obj_loc = 0UL;
  233. if (ide_noacpi)
  234. return 0;
  235. if (!dev) {
  236. DEBPRINT("no PCI device for %s\n", hwif->name);
  237. goto out;
  238. }
  239. if (!hwif->acpidata) {
  240. DEBPRINT("no ACPI data for %s\n", hwif->name);
  241. goto out;
  242. }
  243. port = hwif->channel ? drive->dn - 2: drive->dn;
  244. DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
  245. hwif->name, dev->bus_id, port, hwif->channel);
  246. if (!drive->present) {
  247. DEBPRINT("%s drive %d:%d not present\n",
  248. hwif->name, hwif->channel, port);
  249. goto out;
  250. }
  251. /* Get this drive's _ADR info. if not already known. */
  252. if (!drive->acpidata->obj_handle) {
  253. drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
  254. if (!drive->acpidata->obj_handle) {
  255. DEBPRINT("No ACPI object found for %s\n",
  256. drive->name);
  257. goto out;
  258. }
  259. }
  260. /* Setting up output buffer */
  261. output.length = ACPI_ALLOCATE_BUFFER;
  262. output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
  263. /* _GTF has no input parameters */
  264. err = -EIO;
  265. status = acpi_evaluate_object(drive->acpidata->obj_handle, "_GTF",
  266. NULL, &output);
  267. if (ACPI_FAILURE(status)) {
  268. printk(KERN_DEBUG
  269. "%s: Run _GTF error: status = 0x%x\n",
  270. __FUNCTION__, status);
  271. goto out;
  272. }
  273. if (!output.length || !output.pointer) {
  274. DEBPRINT("Run _GTF: "
  275. "length or ptr is NULL (0x%llx, 0x%p)\n",
  276. (unsigned long long)output.length,
  277. output.pointer);
  278. goto out;
  279. }
  280. out_obj = output.pointer;
  281. if (out_obj->type != ACPI_TYPE_BUFFER) {
  282. DEBPRINT("Run _GTF: error: "
  283. "expected object type of ACPI_TYPE_BUFFER, "
  284. "got 0x%x\n", out_obj->type);
  285. err = -ENOENT;
  286. kfree(output.pointer);
  287. goto out;
  288. }
  289. if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
  290. out_obj->buffer.length % REGS_PER_GTF) {
  291. printk(KERN_ERR
  292. "%s: unexpected GTF length (%d) or addr (0x%p)\n",
  293. __FUNCTION__, out_obj->buffer.length,
  294. out_obj->buffer.pointer);
  295. err = -ENOENT;
  296. kfree(output.pointer);
  297. goto out;
  298. }
  299. *gtf_length = out_obj->buffer.length;
  300. *gtf_address = (unsigned long)out_obj->buffer.pointer;
  301. *obj_loc = (unsigned long)out_obj;
  302. DEBPRINT("returning gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
  303. *gtf_length, *gtf_address, *obj_loc);
  304. err = 0;
  305. out:
  306. return err;
  307. }
  308. /**
  309. * taskfile_load_raw - send taskfile registers to drive
  310. * @drive: drive to which output is sent
  311. * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
  312. *
  313. * Outputs IDE taskfile to the drive.
  314. */
  315. static int taskfile_load_raw(ide_drive_t *drive,
  316. const struct taskfile_array *gtf)
  317. {
  318. ide_task_t args;
  319. int err = 0;
  320. DEBPRINT("(0x1f1-1f7): hex: "
  321. "%02x %02x %02x %02x %02x %02x %02x\n",
  322. gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
  323. gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
  324. memset(&args, 0, sizeof(ide_task_t));
  325. /* convert gtf to IDE Taskfile */
  326. memcpy(&args.tf_array[7], &gtf->tfa, 7);
  327. args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
  328. if (ide_noacpitfs) {
  329. DEBPRINT("_GTF execution disabled\n");
  330. return err;
  331. }
  332. err = ide_no_data_taskfile(drive, &args);
  333. if (err)
  334. printk(KERN_ERR "%s: ide_no_data_taskfile failed: %u\n",
  335. __FUNCTION__, err);
  336. return err;
  337. }
  338. /**
  339. * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
  340. * @drive: the drive to which the taskfile command should be sent
  341. * @gtf_length: total number of bytes of _GTF taskfiles
  342. * @gtf_address: location of _GTF taskfile arrays
  343. *
  344. * Write {gtf_address, length gtf_length} in groups of
  345. * REGS_PER_GTF bytes.
  346. */
  347. static int do_drive_set_taskfiles(ide_drive_t *drive,
  348. unsigned int gtf_length,
  349. unsigned long gtf_address)
  350. {
  351. int rc = -ENODEV, err;
  352. int gtf_count = gtf_length / REGS_PER_GTF;
  353. int ix;
  354. struct taskfile_array *gtf;
  355. if (ide_noacpi)
  356. return 0;
  357. DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
  358. if (!drive->present)
  359. goto out;
  360. if (!gtf_count) /* shouldn't be here */
  361. goto out;
  362. DEBPRINT("total GTF bytes=%u (0x%x), gtf_count=%d, addr=0x%lx\n",
  363. gtf_length, gtf_length, gtf_count, gtf_address);
  364. if (gtf_length % REGS_PER_GTF) {
  365. printk(KERN_ERR "%s: unexpected GTF length (%d)\n",
  366. __FUNCTION__, gtf_length);
  367. goto out;
  368. }
  369. rc = 0;
  370. for (ix = 0; ix < gtf_count; ix++) {
  371. gtf = (struct taskfile_array *)
  372. (gtf_address + ix * REGS_PER_GTF);
  373. /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
  374. err = taskfile_load_raw(drive, gtf);
  375. if (err)
  376. rc = err;
  377. }
  378. out:
  379. return rc;
  380. }
  381. /**
  382. * ide_acpi_exec_tfs - get then write drive taskfile settings
  383. * @drive: the drive for which the taskfile settings should be
  384. * written.
  385. *
  386. * According to the ACPI spec this should be called after _STM
  387. * has been evaluated for the interface. Some ACPI vendors interpret
  388. * that as a hard requirement and modify the taskfile according
  389. * to the Identify Drive information passed down with _STM.
  390. * So one should really make sure to call this only after _STM has
  391. * been executed.
  392. */
  393. int ide_acpi_exec_tfs(ide_drive_t *drive)
  394. {
  395. int ret;
  396. unsigned int gtf_length;
  397. unsigned long gtf_address;
  398. unsigned long obj_loc;
  399. if (ide_noacpi)
  400. return 0;
  401. DEBPRINT("call get_GTF, drive=%s port=%d\n", drive->name, drive->dn);
  402. ret = do_drive_get_GTF(drive, &gtf_length, &gtf_address, &obj_loc);
  403. if (ret < 0) {
  404. DEBPRINT("get_GTF error (%d)\n", ret);
  405. return ret;
  406. }
  407. DEBPRINT("call set_taskfiles, drive=%s\n", drive->name);
  408. ret = do_drive_set_taskfiles(drive, gtf_length, gtf_address);
  409. kfree((void *)obj_loc);
  410. if (ret < 0) {
  411. DEBPRINT("set_taskfiles error (%d)\n", ret);
  412. }
  413. DEBPRINT("ret=%d\n", ret);
  414. return ret;
  415. }
  416. /**
  417. * ide_acpi_get_timing - get the channel (controller) timings
  418. * @hwif: target IDE interface (channel)
  419. *
  420. * This function executes the _GTM ACPI method for the target channel.
  421. *
  422. */
  423. void ide_acpi_get_timing(ide_hwif_t *hwif)
  424. {
  425. acpi_status status;
  426. struct acpi_buffer output;
  427. union acpi_object *out_obj;
  428. if (ide_noacpi)
  429. return;
  430. DEBPRINT("ENTER:\n");
  431. if (!hwif->acpidata) {
  432. DEBPRINT("no ACPI data for %s\n", hwif->name);
  433. return;
  434. }
  435. /* Setting up output buffer for _GTM */
  436. output.length = ACPI_ALLOCATE_BUFFER;
  437. output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
  438. /* _GTM has no input parameters */
  439. status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_GTM",
  440. NULL, &output);
  441. DEBPRINT("_GTM status: %d, outptr: 0x%p, outlen: 0x%llx\n",
  442. status, output.pointer,
  443. (unsigned long long)output.length);
  444. if (ACPI_FAILURE(status)) {
  445. DEBPRINT("Run _GTM error: status = 0x%x\n", status);
  446. return;
  447. }
  448. if (!output.length || !output.pointer) {
  449. DEBPRINT("Run _GTM: length or ptr is NULL (0x%llx, 0x%p)\n",
  450. (unsigned long long)output.length,
  451. output.pointer);
  452. kfree(output.pointer);
  453. return;
  454. }
  455. out_obj = output.pointer;
  456. if (out_obj->type != ACPI_TYPE_BUFFER) {
  457. kfree(output.pointer);
  458. DEBPRINT("Run _GTM: error: "
  459. "expected object type of ACPI_TYPE_BUFFER, "
  460. "got 0x%x\n", out_obj->type);
  461. return;
  462. }
  463. if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
  464. out_obj->buffer.length != sizeof(struct GTM_buffer)) {
  465. kfree(output.pointer);
  466. printk(KERN_ERR
  467. "%s: unexpected _GTM length (0x%x)[should be 0x%zx] or "
  468. "addr (0x%p)\n",
  469. __FUNCTION__, out_obj->buffer.length,
  470. sizeof(struct GTM_buffer), out_obj->buffer.pointer);
  471. return;
  472. }
  473. memcpy(&hwif->acpidata->gtm, out_obj->buffer.pointer,
  474. sizeof(struct GTM_buffer));
  475. DEBPRINT("_GTM info: ptr: 0x%p, len: 0x%x, exp.len: 0x%Zx\n",
  476. out_obj->buffer.pointer, out_obj->buffer.length,
  477. sizeof(struct GTM_buffer));
  478. DEBPRINT("_GTM fields: 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
  479. hwif->acpidata->gtm.PIO_speed0,
  480. hwif->acpidata->gtm.DMA_speed0,
  481. hwif->acpidata->gtm.PIO_speed1,
  482. hwif->acpidata->gtm.DMA_speed1,
  483. hwif->acpidata->gtm.GTM_flags);
  484. kfree(output.pointer);
  485. }
  486. /**
  487. * ide_acpi_push_timing - set the channel (controller) timings
  488. * @hwif: target IDE interface (channel)
  489. *
  490. * This function executes the _STM ACPI method for the target channel.
  491. *
  492. * _STM requires Identify Drive data, which has to passed as an argument.
  493. * Unfortunately hd_driveid is a mangled version which we can't readily
  494. * use; hence we'll get the information afresh.
  495. */
  496. void ide_acpi_push_timing(ide_hwif_t *hwif)
  497. {
  498. acpi_status status;
  499. struct acpi_object_list input;
  500. union acpi_object in_params[3];
  501. struct ide_acpi_drive_link *master = &hwif->acpidata->master;
  502. struct ide_acpi_drive_link *slave = &hwif->acpidata->slave;
  503. if (ide_noacpi)
  504. return;
  505. DEBPRINT("ENTER:\n");
  506. if (!hwif->acpidata) {
  507. DEBPRINT("no ACPI data for %s\n", hwif->name);
  508. return;
  509. }
  510. /* Give the GTM buffer + drive Identify data to the channel via the
  511. * _STM method: */
  512. /* setup input parameters buffer for _STM */
  513. input.count = 3;
  514. input.pointer = in_params;
  515. in_params[0].type = ACPI_TYPE_BUFFER;
  516. in_params[0].buffer.length = sizeof(struct GTM_buffer);
  517. in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm;
  518. in_params[1].type = ACPI_TYPE_BUFFER;
  519. in_params[1].buffer.length = sizeof(struct hd_driveid);
  520. in_params[1].buffer.pointer = (u8 *)&master->idbuff;
  521. in_params[2].type = ACPI_TYPE_BUFFER;
  522. in_params[2].buffer.length = sizeof(struct hd_driveid);
  523. in_params[2].buffer.pointer = (u8 *)&slave->idbuff;
  524. /* Output buffer: _STM has no output */
  525. status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_STM",
  526. &input, NULL);
  527. if (ACPI_FAILURE(status)) {
  528. DEBPRINT("Run _STM error: status = 0x%x\n", status);
  529. }
  530. DEBPRINT("_STM status: %d\n", status);
  531. }
  532. /**
  533. * ide_acpi_set_state - set the channel power state
  534. * @hwif: target IDE interface
  535. * @on: state, on/off
  536. *
  537. * This function executes the _PS0/_PS3 ACPI method to set the power state.
  538. * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
  539. */
  540. void ide_acpi_set_state(ide_hwif_t *hwif, int on)
  541. {
  542. int unit;
  543. if (ide_noacpi || ide_noacpi_psx)
  544. return;
  545. DEBPRINT("ENTER:\n");
  546. if (!hwif->acpidata) {
  547. DEBPRINT("no ACPI data for %s\n", hwif->name);
  548. return;
  549. }
  550. /* channel first and then drives for power on and verse versa for power off */
  551. if (on)
  552. acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
  553. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  554. ide_drive_t *drive = &hwif->drives[unit];
  555. if (!drive->acpidata->obj_handle)
  556. drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
  557. if (drive->acpidata->obj_handle && drive->present) {
  558. acpi_bus_set_power(drive->acpidata->obj_handle,
  559. on? ACPI_STATE_D0: ACPI_STATE_D3);
  560. }
  561. }
  562. if (!on)
  563. acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D3);
  564. }
  565. /**
  566. * ide_acpi_init - initialize the ACPI link for an IDE interface
  567. * @hwif: target IDE interface (channel)
  568. *
  569. * The ACPI spec is not quite clear when the drive identify buffer
  570. * should be obtained. Calling IDENTIFY DEVICE during shutdown
  571. * is not the best of ideas as the drive might already being put to
  572. * sleep. And obviously we can't call it during resume.
  573. * So we get the information during startup; but this means that
  574. * any changes during run-time will be lost after resume.
  575. */
  576. void ide_acpi_init(ide_hwif_t *hwif)
  577. {
  578. int unit;
  579. int err;
  580. struct ide_acpi_drive_link *master;
  581. struct ide_acpi_drive_link *slave;
  582. ide_acpi_blacklist();
  583. hwif->acpidata = kzalloc(sizeof(struct ide_acpi_hwif_link), GFP_KERNEL);
  584. if (!hwif->acpidata)
  585. return;
  586. hwif->acpidata->obj_handle = ide_acpi_hwif_get_handle(hwif);
  587. if (!hwif->acpidata->obj_handle) {
  588. DEBPRINT("no ACPI object for %s found\n", hwif->name);
  589. kfree(hwif->acpidata);
  590. hwif->acpidata = NULL;
  591. return;
  592. }
  593. /*
  594. * The ACPI spec mandates that we send information
  595. * for both drives, regardless whether they are connected
  596. * or not.
  597. */
  598. hwif->acpidata->master.drive = &hwif->drives[0];
  599. hwif->drives[0].acpidata = &hwif->acpidata->master;
  600. master = &hwif->acpidata->master;
  601. hwif->acpidata->slave.drive = &hwif->drives[1];
  602. hwif->drives[1].acpidata = &hwif->acpidata->slave;
  603. slave = &hwif->acpidata->slave;
  604. /*
  605. * Send IDENTIFY for each drive
  606. */
  607. if (master->drive->present) {
  608. err = taskfile_lib_get_identify(master->drive, master->idbuff);
  609. if (err) {
  610. DEBPRINT("identify device %s failed (%d)\n",
  611. master->drive->name, err);
  612. }
  613. }
  614. if (slave->drive->present) {
  615. err = taskfile_lib_get_identify(slave->drive, slave->idbuff);
  616. if (err) {
  617. DEBPRINT("identify device %s failed (%d)\n",
  618. slave->drive->name, err);
  619. }
  620. }
  621. if (ide_noacpionboot) {
  622. DEBPRINT("ACPI methods disabled on boot\n");
  623. return;
  624. }
  625. /* ACPI _PS0 before _STM */
  626. ide_acpi_set_state(hwif, 1);
  627. /*
  628. * ACPI requires us to call _STM on startup
  629. */
  630. ide_acpi_get_timing(hwif);
  631. ide_acpi_push_timing(hwif);
  632. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  633. ide_drive_t *drive = &hwif->drives[unit];
  634. if (drive->present) {
  635. /* Execute ACPI startup code */
  636. ide_acpi_exec_tfs(drive);
  637. }
  638. }
  639. }