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