ide-acpi.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. /*
  2. * ide-acpi.c
  3. * Provides ACPI support for IDE drives.
  4. *
  5. * Copyright (C) 2005 Intel Corp.
  6. * Copyright (C) 2005 Randy Dunlap
  7. * Copyright (C) 2006 SUSE Linux Products GmbH
  8. * Copyright (C) 2006 Hannes Reinecke
  9. */
  10. #include <linux/ata.h>
  11. #include <linux/delay.h>
  12. #include <linux/device.h>
  13. #include <linux/errno.h>
  14. #include <linux/kernel.h>
  15. #include <acpi/acpi.h>
  16. #include <linux/ide.h>
  17. #include <linux/pci.h>
  18. #include <linux/dmi.h>
  19. #include <acpi/acpi_bus.h>
  20. #include <acpi/acnames.h>
  21. #include <acpi/acnamesp.h>
  22. #include <acpi/acparser.h>
  23. #include <acpi/acexcep.h>
  24. #include <acpi/acmacros.h>
  25. #include <acpi/actypes.h>
  26. #define REGS_PER_GTF 7
  27. struct taskfile_array {
  28. u8 tfa[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */
  29. };
  30. struct GTM_buffer {
  31. u32 PIO_speed0;
  32. u32 DMA_speed0;
  33. u32 PIO_speed1;
  34. u32 DMA_speed1;
  35. u32 GTM_flags;
  36. };
  37. struct ide_acpi_drive_link {
  38. ide_drive_t *drive;
  39. acpi_handle obj_handle;
  40. u8 idbuff[512];
  41. };
  42. struct ide_acpi_hwif_link {
  43. ide_hwif_t *hwif;
  44. acpi_handle obj_handle;
  45. struct GTM_buffer gtm;
  46. struct ide_acpi_drive_link master;
  47. struct ide_acpi_drive_link slave;
  48. };
  49. #undef DEBUGGING
  50. /* note: adds function name and KERN_DEBUG */
  51. #ifdef DEBUGGING
  52. #define DEBPRINT(fmt, args...) \
  53. printk(KERN_DEBUG "%s: " fmt, __FUNCTION__, ## args)
  54. #else
  55. #define DEBPRINT(fmt, args...) do {} while (0)
  56. #endif /* DEBUGGING */
  57. extern int ide_noacpi;
  58. extern int ide_noacpitfs;
  59. extern int ide_noacpionboot;
  60. static bool ide_noacpi_psx;
  61. static int no_acpi_psx(const struct dmi_system_id *id)
  62. {
  63. ide_noacpi_psx = true;
  64. printk(KERN_NOTICE"%s detected - disable ACPI _PSx.\n", id->ident);
  65. return 0;
  66. }
  67. static const struct dmi_system_id ide_acpi_dmi_table[] = {
  68. /* Bug 9673. */
  69. /* We should check if this is because ACPI NVS isn't save/restored. */
  70. {
  71. .callback = no_acpi_psx,
  72. .ident = "HP nx9005",
  73. .matches = {
  74. DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies Ltd."),
  75. DMI_MATCH(DMI_BIOS_VERSION, "KAM1.60")
  76. },
  77. },
  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. if (!drive->acpidata) {
  245. if (port == 0) {
  246. drive->acpidata = &hwif->acpidata->master;
  247. hwif->acpidata->master.drive = drive;
  248. } else {
  249. drive->acpidata = &hwif->acpidata->slave;
  250. hwif->acpidata->slave.drive = drive;
  251. }
  252. }
  253. DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
  254. hwif->name, dev->bus_id, port, hwif->channel);
  255. if (!drive->present) {
  256. DEBPRINT("%s drive %d:%d not present\n",
  257. hwif->name, hwif->channel, port);
  258. goto out;
  259. }
  260. /* Get this drive's _ADR info. if not already known. */
  261. if (!drive->acpidata->obj_handle) {
  262. drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
  263. if (!drive->acpidata->obj_handle) {
  264. DEBPRINT("No ACPI object found for %s\n",
  265. drive->name);
  266. goto out;
  267. }
  268. }
  269. /* Setting up output buffer */
  270. output.length = ACPI_ALLOCATE_BUFFER;
  271. output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
  272. /* _GTF has no input parameters */
  273. err = -EIO;
  274. status = acpi_evaluate_object(drive->acpidata->obj_handle, "_GTF",
  275. NULL, &output);
  276. if (ACPI_FAILURE(status)) {
  277. printk(KERN_DEBUG
  278. "%s: Run _GTF error: status = 0x%x\n",
  279. __FUNCTION__, status);
  280. goto out;
  281. }
  282. if (!output.length || !output.pointer) {
  283. DEBPRINT("Run _GTF: "
  284. "length or ptr is NULL (0x%llx, 0x%p)\n",
  285. (unsigned long long)output.length,
  286. output.pointer);
  287. goto out;
  288. }
  289. out_obj = output.pointer;
  290. if (out_obj->type != ACPI_TYPE_BUFFER) {
  291. DEBPRINT("Run _GTF: error: "
  292. "expected object type of ACPI_TYPE_BUFFER, "
  293. "got 0x%x\n", out_obj->type);
  294. err = -ENOENT;
  295. kfree(output.pointer);
  296. goto out;
  297. }
  298. if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
  299. out_obj->buffer.length % REGS_PER_GTF) {
  300. printk(KERN_ERR
  301. "%s: unexpected GTF length (%d) or addr (0x%p)\n",
  302. __FUNCTION__, out_obj->buffer.length,
  303. out_obj->buffer.pointer);
  304. err = -ENOENT;
  305. kfree(output.pointer);
  306. goto out;
  307. }
  308. *gtf_length = out_obj->buffer.length;
  309. *gtf_address = (unsigned long)out_obj->buffer.pointer;
  310. *obj_loc = (unsigned long)out_obj;
  311. DEBPRINT("returning gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
  312. *gtf_length, *gtf_address, *obj_loc);
  313. err = 0;
  314. out:
  315. return err;
  316. }
  317. /**
  318. * taskfile_load_raw - send taskfile registers to drive
  319. * @drive: drive to which output is sent
  320. * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
  321. *
  322. * Outputs IDE taskfile to the drive.
  323. */
  324. static int taskfile_load_raw(ide_drive_t *drive,
  325. const struct taskfile_array *gtf)
  326. {
  327. ide_task_t args;
  328. int err = 0;
  329. DEBPRINT("(0x1f1-1f7): hex: "
  330. "%02x %02x %02x %02x %02x %02x %02x\n",
  331. gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
  332. gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
  333. memset(&args, 0, sizeof(ide_task_t));
  334. args.command_type = IDE_DRIVE_TASK_NO_DATA;
  335. args.data_phase = TASKFILE_NO_DATA;
  336. args.handler = &task_no_data_intr;
  337. /* convert gtf to IDE Taskfile */
  338. args.tfRegister[1] = gtf->tfa[0]; /* 0x1f1 */
  339. args.tfRegister[2] = gtf->tfa[1]; /* 0x1f2 */
  340. args.tfRegister[3] = gtf->tfa[2]; /* 0x1f3 */
  341. args.tfRegister[4] = gtf->tfa[3]; /* 0x1f4 */
  342. args.tfRegister[5] = gtf->tfa[4]; /* 0x1f5 */
  343. args.tfRegister[6] = gtf->tfa[5]; /* 0x1f6 */
  344. args.tfRegister[7] = gtf->tfa[6]; /* 0x1f7 */
  345. if (ide_noacpitfs) {
  346. DEBPRINT("_GTF execution disabled\n");
  347. return err;
  348. }
  349. err = ide_raw_taskfile(drive, &args, NULL);
  350. if (err)
  351. printk(KERN_ERR "%s: ide_raw_taskfile failed: %u\n",
  352. __FUNCTION__, err);
  353. return err;
  354. }
  355. /**
  356. * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
  357. * @drive: the drive to which the taskfile command should be sent
  358. * @gtf_length: total number of bytes of _GTF taskfiles
  359. * @gtf_address: location of _GTF taskfile arrays
  360. *
  361. * Write {gtf_address, length gtf_length} in groups of
  362. * REGS_PER_GTF bytes.
  363. */
  364. static int do_drive_set_taskfiles(ide_drive_t *drive,
  365. unsigned int gtf_length,
  366. unsigned long gtf_address)
  367. {
  368. int rc = -ENODEV, err;
  369. int gtf_count = gtf_length / REGS_PER_GTF;
  370. int ix;
  371. struct taskfile_array *gtf;
  372. if (ide_noacpi)
  373. return 0;
  374. DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
  375. if (!drive->present)
  376. goto out;
  377. if (!gtf_count) /* shouldn't be here */
  378. goto out;
  379. DEBPRINT("total GTF bytes=%u (0x%x), gtf_count=%d, addr=0x%lx\n",
  380. gtf_length, gtf_length, gtf_count, gtf_address);
  381. if (gtf_length % REGS_PER_GTF) {
  382. printk(KERN_ERR "%s: unexpected GTF length (%d)\n",
  383. __FUNCTION__, gtf_length);
  384. goto out;
  385. }
  386. rc = 0;
  387. for (ix = 0; ix < gtf_count; ix++) {
  388. gtf = (struct taskfile_array *)
  389. (gtf_address + ix * REGS_PER_GTF);
  390. /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
  391. err = taskfile_load_raw(drive, gtf);
  392. if (err)
  393. rc = err;
  394. }
  395. out:
  396. return rc;
  397. }
  398. /**
  399. * ide_acpi_exec_tfs - get then write drive taskfile settings
  400. * @drive: the drive for which the taskfile settings should be
  401. * written.
  402. *
  403. * According to the ACPI spec this should be called after _STM
  404. * has been evaluated for the interface. Some ACPI vendors interpret
  405. * that as a hard requirement and modify the taskfile according
  406. * to the Identify Drive information passed down with _STM.
  407. * So one should really make sure to call this only after _STM has
  408. * been executed.
  409. */
  410. int ide_acpi_exec_tfs(ide_drive_t *drive)
  411. {
  412. int ret;
  413. unsigned int gtf_length;
  414. unsigned long gtf_address;
  415. unsigned long obj_loc;
  416. if (ide_noacpi)
  417. return 0;
  418. DEBPRINT("call get_GTF, drive=%s port=%d\n", drive->name, drive->dn);
  419. ret = do_drive_get_GTF(drive, &gtf_length, &gtf_address, &obj_loc);
  420. if (ret < 0) {
  421. DEBPRINT("get_GTF error (%d)\n", ret);
  422. return ret;
  423. }
  424. DEBPRINT("call set_taskfiles, drive=%s\n", drive->name);
  425. ret = do_drive_set_taskfiles(drive, gtf_length, gtf_address);
  426. kfree((void *)obj_loc);
  427. if (ret < 0) {
  428. DEBPRINT("set_taskfiles error (%d)\n", ret);
  429. }
  430. DEBPRINT("ret=%d\n", ret);
  431. return ret;
  432. }
  433. EXPORT_SYMBOL_GPL(ide_acpi_exec_tfs);
  434. /**
  435. * ide_acpi_get_timing - get the channel (controller) timings
  436. * @hwif: target IDE interface (channel)
  437. *
  438. * This function executes the _GTM ACPI method for the target channel.
  439. *
  440. */
  441. void ide_acpi_get_timing(ide_hwif_t *hwif)
  442. {
  443. acpi_status status;
  444. struct acpi_buffer output;
  445. union acpi_object *out_obj;
  446. if (ide_noacpi)
  447. return;
  448. DEBPRINT("ENTER:\n");
  449. if (!hwif->acpidata) {
  450. DEBPRINT("no ACPI data for %s\n", hwif->name);
  451. return;
  452. }
  453. /* Setting up output buffer for _GTM */
  454. output.length = ACPI_ALLOCATE_BUFFER;
  455. output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
  456. /* _GTM has no input parameters */
  457. status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_GTM",
  458. NULL, &output);
  459. DEBPRINT("_GTM status: %d, outptr: 0x%p, outlen: 0x%llx\n",
  460. status, output.pointer,
  461. (unsigned long long)output.length);
  462. if (ACPI_FAILURE(status)) {
  463. DEBPRINT("Run _GTM error: status = 0x%x\n", status);
  464. return;
  465. }
  466. if (!output.length || !output.pointer) {
  467. DEBPRINT("Run _GTM: length or ptr is NULL (0x%llx, 0x%p)\n",
  468. (unsigned long long)output.length,
  469. output.pointer);
  470. kfree(output.pointer);
  471. return;
  472. }
  473. out_obj = output.pointer;
  474. if (out_obj->type != ACPI_TYPE_BUFFER) {
  475. kfree(output.pointer);
  476. DEBPRINT("Run _GTM: error: "
  477. "expected object type of ACPI_TYPE_BUFFER, "
  478. "got 0x%x\n", out_obj->type);
  479. return;
  480. }
  481. if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
  482. out_obj->buffer.length != sizeof(struct GTM_buffer)) {
  483. kfree(output.pointer);
  484. printk(KERN_ERR
  485. "%s: unexpected _GTM length (0x%x)[should be 0x%zx] or "
  486. "addr (0x%p)\n",
  487. __FUNCTION__, out_obj->buffer.length,
  488. sizeof(struct GTM_buffer), out_obj->buffer.pointer);
  489. return;
  490. }
  491. memcpy(&hwif->acpidata->gtm, out_obj->buffer.pointer,
  492. sizeof(struct GTM_buffer));
  493. DEBPRINT("_GTM info: ptr: 0x%p, len: 0x%x, exp.len: 0x%Zx\n",
  494. out_obj->buffer.pointer, out_obj->buffer.length,
  495. sizeof(struct GTM_buffer));
  496. DEBPRINT("_GTM fields: 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
  497. hwif->acpidata->gtm.PIO_speed0,
  498. hwif->acpidata->gtm.DMA_speed0,
  499. hwif->acpidata->gtm.PIO_speed1,
  500. hwif->acpidata->gtm.DMA_speed1,
  501. hwif->acpidata->gtm.GTM_flags);
  502. kfree(output.pointer);
  503. }
  504. EXPORT_SYMBOL_GPL(ide_acpi_get_timing);
  505. /**
  506. * ide_acpi_push_timing - set the channel (controller) timings
  507. * @hwif: target IDE interface (channel)
  508. *
  509. * This function executes the _STM ACPI method for the target channel.
  510. *
  511. * _STM requires Identify Drive data, which has to passed as an argument.
  512. * Unfortunately hd_driveid is a mangled version which we can't readily
  513. * use; hence we'll get the information afresh.
  514. */
  515. void ide_acpi_push_timing(ide_hwif_t *hwif)
  516. {
  517. acpi_status status;
  518. struct acpi_object_list input;
  519. union acpi_object in_params[3];
  520. struct ide_acpi_drive_link *master = &hwif->acpidata->master;
  521. struct ide_acpi_drive_link *slave = &hwif->acpidata->slave;
  522. if (ide_noacpi)
  523. return;
  524. DEBPRINT("ENTER:\n");
  525. if (!hwif->acpidata) {
  526. DEBPRINT("no ACPI data for %s\n", hwif->name);
  527. return;
  528. }
  529. /* Give the GTM buffer + drive Identify data to the channel via the
  530. * _STM method: */
  531. /* setup input parameters buffer for _STM */
  532. input.count = 3;
  533. input.pointer = in_params;
  534. in_params[0].type = ACPI_TYPE_BUFFER;
  535. in_params[0].buffer.length = sizeof(struct GTM_buffer);
  536. in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm;
  537. in_params[1].type = ACPI_TYPE_BUFFER;
  538. in_params[1].buffer.length = sizeof(struct hd_driveid);
  539. in_params[1].buffer.pointer = (u8 *)&master->idbuff;
  540. in_params[2].type = ACPI_TYPE_BUFFER;
  541. in_params[2].buffer.length = sizeof(struct hd_driveid);
  542. in_params[2].buffer.pointer = (u8 *)&slave->idbuff;
  543. /* Output buffer: _STM has no output */
  544. status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_STM",
  545. &input, NULL);
  546. if (ACPI_FAILURE(status)) {
  547. DEBPRINT("Run _STM error: status = 0x%x\n", status);
  548. }
  549. DEBPRINT("_STM status: %d\n", status);
  550. }
  551. EXPORT_SYMBOL_GPL(ide_acpi_push_timing);
  552. /**
  553. * ide_acpi_set_state - set the channel power state
  554. * @hwif: target IDE interface
  555. * @on: state, on/off
  556. *
  557. * This function executes the _PS0/_PS3 ACPI method to set the power state.
  558. * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
  559. */
  560. void ide_acpi_set_state(ide_hwif_t *hwif, int on)
  561. {
  562. int unit;
  563. if (ide_noacpi || ide_noacpi_psx)
  564. return;
  565. DEBPRINT("ENTER:\n");
  566. if (!hwif->acpidata) {
  567. DEBPRINT("no ACPI data for %s\n", hwif->name);
  568. return;
  569. }
  570. /* channel first and then drives for power on and verse versa for power off */
  571. if (on)
  572. acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
  573. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  574. ide_drive_t *drive = &hwif->drives[unit];
  575. if (!drive->acpidata->obj_handle)
  576. drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
  577. if (drive->acpidata->obj_handle && drive->present) {
  578. acpi_bus_set_power(drive->acpidata->obj_handle,
  579. on? ACPI_STATE_D0: ACPI_STATE_D3);
  580. }
  581. }
  582. if (!on)
  583. acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D3);
  584. }
  585. /**
  586. * ide_acpi_init - initialize the ACPI link for an IDE interface
  587. * @hwif: target IDE interface (channel)
  588. *
  589. * The ACPI spec is not quite clear when the drive identify buffer
  590. * should be obtained. Calling IDENTIFY DEVICE during shutdown
  591. * is not the best of ideas as the drive might already being put to
  592. * sleep. And obviously we can't call it during resume.
  593. * So we get the information during startup; but this means that
  594. * any changes during run-time will be lost after resume.
  595. */
  596. void ide_acpi_init(ide_hwif_t *hwif)
  597. {
  598. int unit;
  599. int err;
  600. struct ide_acpi_drive_link *master;
  601. struct ide_acpi_drive_link *slave;
  602. ide_acpi_blacklist();
  603. hwif->acpidata = kzalloc(sizeof(struct ide_acpi_hwif_link), GFP_KERNEL);
  604. if (!hwif->acpidata)
  605. return;
  606. hwif->acpidata->obj_handle = ide_acpi_hwif_get_handle(hwif);
  607. if (!hwif->acpidata->obj_handle) {
  608. DEBPRINT("no ACPI object for %s found\n", hwif->name);
  609. kfree(hwif->acpidata);
  610. hwif->acpidata = NULL;
  611. return;
  612. }
  613. /*
  614. * The ACPI spec mandates that we send information
  615. * for both drives, regardless whether they are connected
  616. * or not.
  617. */
  618. hwif->acpidata->master.drive = &hwif->drives[0];
  619. hwif->drives[0].acpidata = &hwif->acpidata->master;
  620. master = &hwif->acpidata->master;
  621. hwif->acpidata->slave.drive = &hwif->drives[1];
  622. hwif->drives[1].acpidata = &hwif->acpidata->slave;
  623. slave = &hwif->acpidata->slave;
  624. /*
  625. * Send IDENTIFY for each drive
  626. */
  627. if (master->drive->present) {
  628. err = taskfile_lib_get_identify(master->drive, master->idbuff);
  629. if (err) {
  630. DEBPRINT("identify device %s failed (%d)\n",
  631. master->drive->name, err);
  632. }
  633. }
  634. if (slave->drive->present) {
  635. err = taskfile_lib_get_identify(slave->drive, slave->idbuff);
  636. if (err) {
  637. DEBPRINT("identify device %s failed (%d)\n",
  638. slave->drive->name, err);
  639. }
  640. }
  641. if (ide_noacpionboot) {
  642. DEBPRINT("ACPI methods disabled on boot\n");
  643. return;
  644. }
  645. /* ACPI _PS0 before _STM */
  646. ide_acpi_set_state(hwif, 1);
  647. /*
  648. * ACPI requires us to call _STM on startup
  649. */
  650. ide_acpi_get_timing(hwif);
  651. ide_acpi_push_timing(hwif);
  652. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  653. ide_drive_t *drive = &hwif->drives[unit];
  654. if (drive->present) {
  655. /* Execute ACPI startup code */
  656. ide_acpi_exec_tfs(drive);
  657. }
  658. }
  659. }
  660. EXPORT_SYMBOL_GPL(ide_acpi_init);