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