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