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