Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * libata-acpi.c |
| 3 | * Provides ACPI support for PATA/SATA. |
| 4 | * |
| 5 | * Copyright (C) 2006 Intel Corp. |
| 6 | * Copyright (C) 2006 Randy Dunlap |
| 7 | */ |
| 8 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 9 | #include <linux/module.h> |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 10 | #include <linux/ata.h> |
| 11 | #include <linux/delay.h> |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/acpi.h> |
| 16 | #include <linux/libata.h> |
| 17 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 19 | #include <scsi/scsi_device.h> |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 20 | #include "libata.h" |
| 21 | |
| 22 | #include <acpi/acpi_bus.h> |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 23 | |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 24 | unsigned int ata_acpi_gtf_filter = ATA_ACPI_FILTER_DEFAULT; |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 25 | module_param_named(acpi_gtf_filter, ata_acpi_gtf_filter, int, 0644); |
Tejun Heo | fa5b561 | 2009-09-16 04:17:02 +0900 | [diff] [blame] | 26 | MODULE_PARM_DESC(acpi_gtf_filter, "filter mask for ACPI _GTF commands, set to filter out (0x1=set xfermode, 0x2=lock/freeze lock, 0x4=DIPM, 0x8=FPDMA non-zero offset, 0x10=FPDMA DMA Setup FIS auto-activate)"); |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 27 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 28 | #define NO_PORT_MULT 0xffff |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 29 | #define SATA_ADR(root, pmp) (((root) << 16) | (pmp)) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 30 | |
| 31 | #define REGS_PER_GTF 7 |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 32 | struct ata_acpi_gtf { |
| 33 | u8 tf[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */ |
| 34 | } __packed; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 35 | |
Alan Cox | ca42663 | 2007-03-08 23:13:50 +0000 | [diff] [blame] | 36 | /* |
| 37 | * Helper - belongs in the PCI layer somewhere eventually |
| 38 | */ |
| 39 | static int is_pci_dev(struct device *dev) |
| 40 | { |
| 41 | return (dev->bus == &pci_bus_type); |
| 42 | } |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 43 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 44 | static void ata_acpi_clear_gtf(struct ata_device *dev) |
| 45 | { |
| 46 | kfree(dev->gtf_cache); |
| 47 | dev->gtf_cache = NULL; |
| 48 | } |
| 49 | |
Matthew Garrett | 6b66d95 | 2012-06-25 16:13:03 +0800 | [diff] [blame^] | 50 | static acpi_handle ap_acpi_handle(struct ata_port *ap) |
| 51 | { |
| 52 | if (ap->flags & ATA_FLAG_ACPI_SATA) |
| 53 | return NULL; |
| 54 | |
| 55 | /* |
| 56 | * If acpi bind operation has already happened, we can get the handle |
| 57 | * for the port by checking the corresponding scsi_host device's |
| 58 | * firmware node, otherwise we will need to find out the handle from |
| 59 | * its parent's acpi node. |
| 60 | */ |
| 61 | if (ap->scsi_host) |
| 62 | return DEVICE_ACPI_HANDLE(&ap->scsi_host->shost_gendev); |
| 63 | else |
| 64 | return acpi_get_child(DEVICE_ACPI_HANDLE(ap->host->dev), |
| 65 | ap->port_no); |
| 66 | } |
| 67 | |
| 68 | static acpi_handle dev_acpi_handle(struct ata_device *dev) |
| 69 | { |
| 70 | acpi_integer adr; |
| 71 | struct ata_port *ap = dev->link->ap; |
| 72 | |
| 73 | if (ap->flags & ATA_FLAG_ACPI_SATA) { |
| 74 | if (!sata_pmp_attached(ap)) |
| 75 | adr = SATA_ADR(ap->port_no, NO_PORT_MULT); |
| 76 | else |
| 77 | adr = SATA_ADR(ap->port_no, dev->link->pmp); |
| 78 | return acpi_get_child(DEVICE_ACPI_HANDLE(ap->host->dev), adr); |
| 79 | } else |
| 80 | return acpi_get_child(ap_acpi_handle(ap), dev->devno); |
| 81 | } |
| 82 | |
Tejun Heo | d0df8b5d | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 83 | /** |
| 84 | * ata_acpi_associate_sata_port - associate SATA port with ACPI objects |
| 85 | * @ap: target SATA port |
| 86 | * |
| 87 | * Look up ACPI objects associated with @ap and initialize acpi_handle |
| 88 | * fields of @ap, the port and devices accordingly. |
| 89 | * |
| 90 | * LOCKING: |
| 91 | * EH context. |
| 92 | * |
| 93 | * RETURNS: |
| 94 | * 0 on success, -errno on failure. |
| 95 | */ |
| 96 | void ata_acpi_associate_sata_port(struct ata_port *ap) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 97 | { |
Tejun Heo | d0df8b5d | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 98 | WARN_ON(!(ap->flags & ATA_FLAG_ACPI_SATA)); |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 99 | |
Tejun Heo | 071f44b | 2008-04-07 22:47:22 +0900 | [diff] [blame] | 100 | if (!sata_pmp_attached(ap)) { |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 101 | u64 adr = SATA_ADR(ap->port_no, NO_PORT_MULT); |
Tejun Heo | d0df8b5d | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 102 | |
| 103 | ap->link.device->acpi_handle = |
| 104 | acpi_get_child(ap->host->acpi_handle, adr); |
| 105 | } else { |
| 106 | struct ata_link *link; |
| 107 | |
| 108 | ap->link.device->acpi_handle = NULL; |
| 109 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 110 | ata_for_each_link(link, ap, EDGE) { |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 111 | u64 adr = SATA_ADR(ap->port_no, link->pmp); |
Tejun Heo | d0df8b5d | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 112 | |
| 113 | link->device->acpi_handle = |
| 114 | acpi_get_child(ap->host->acpi_handle, adr); |
| 115 | } |
| 116 | } |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 117 | } |
Alan Cox | ca42663 | 2007-03-08 23:13:50 +0000 | [diff] [blame] | 118 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 119 | static void ata_acpi_associate_ide_port(struct ata_port *ap) |
| 120 | { |
| 121 | int max_devices, i; |
| 122 | |
| 123 | ap->acpi_handle = acpi_get_child(ap->host->acpi_handle, ap->port_no); |
| 124 | if (!ap->acpi_handle) |
| 125 | return; |
| 126 | |
| 127 | max_devices = 1; |
| 128 | if (ap->flags & ATA_FLAG_SLAVE_POSS) |
| 129 | max_devices++; |
| 130 | |
| 131 | for (i = 0; i < max_devices; i++) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 132 | struct ata_device *dev = &ap->link.device[i]; |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 133 | |
| 134 | dev->acpi_handle = acpi_get_child(ap->acpi_handle, i); |
| 135 | } |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 136 | |
| 137 | if (ata_acpi_gtm(ap, &ap->__acpi_init_gtm) == 0) |
| 138 | ap->pflags |= ATA_PFLAG_INIT_GTM_VALID; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 141 | /* @ap and @dev are the same as ata_acpi_handle_hotplug() */ |
| 142 | static void ata_acpi_detach_device(struct ata_port *ap, struct ata_device *dev) |
| 143 | { |
| 144 | if (dev) |
| 145 | dev->flags |= ATA_DFLAG_DETACH; |
| 146 | else { |
| 147 | struct ata_link *tlink; |
| 148 | struct ata_device *tdev; |
| 149 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 150 | ata_for_each_link(tlink, ap, EDGE) |
| 151 | ata_for_each_dev(tdev, tlink, ALL) |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 152 | tdev->flags |= ATA_DFLAG_DETACH; |
| 153 | } |
| 154 | |
| 155 | ata_port_schedule_eh(ap); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * ata_acpi_handle_hotplug - ACPI event handler backend |
| 160 | * @ap: ATA port ACPI event occurred |
| 161 | * @dev: ATA device ACPI event occurred (can be NULL) |
| 162 | * @event: ACPI event which occurred |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 163 | * |
| 164 | * All ACPI bay / device realted events end up in this function. If |
| 165 | * the event is port-wide @dev is NULL. If the event is specific to a |
| 166 | * device, @dev points to it. |
| 167 | * |
| 168 | * Hotplug (as opposed to unplug) notification is always handled as |
| 169 | * port-wide while unplug only kills the target device on device-wide |
| 170 | * event. |
| 171 | * |
| 172 | * LOCKING: |
| 173 | * ACPI notify handler context. May sleep. |
| 174 | */ |
| 175 | static void ata_acpi_handle_hotplug(struct ata_port *ap, struct ata_device *dev, |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 176 | u32 event) |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 177 | { |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 178 | struct ata_eh_info *ehi = &ap->link.eh_info; |
Tejun Heo | 233f112 | 2008-03-12 14:24:43 +0900 | [diff] [blame] | 179 | int wait = 0; |
| 180 | unsigned long flags; |
Zhang Rui | 3c1e389 | 2008-07-11 09:42:03 -0400 | [diff] [blame] | 181 | |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 182 | spin_lock_irqsave(ap->lock, flags); |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 183 | /* |
| 184 | * When dock driver calls into the routine, it will always use |
| 185 | * ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and |
| 186 | * ACPI_NOTIFY_EJECT_REQUEST for remove |
| 187 | */ |
Tejun Heo | 233f112 | 2008-03-12 14:24:43 +0900 | [diff] [blame] | 188 | switch (event) { |
| 189 | case ACPI_NOTIFY_BUS_CHECK: |
| 190 | case ACPI_NOTIFY_DEVICE_CHECK: |
| 191 | ata_ehi_push_desc(ehi, "ACPI event"); |
Jeff Garzik | c85665f | 2008-05-19 17:56:10 -0400 | [diff] [blame] | 192 | |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 193 | ata_ehi_hotplugged(ehi); |
| 194 | ata_port_freeze(ap); |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 195 | break; |
| 196 | case ACPI_NOTIFY_EJECT_REQUEST: |
| 197 | ata_ehi_push_desc(ehi, "ACPI event"); |
| 198 | |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 199 | ata_acpi_detach_device(ap, dev); |
| 200 | wait = 1; |
| 201 | break; |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 202 | } |
| 203 | |
Matthew Garrett | ae6c23c | 2008-05-19 17:29:34 +0100 | [diff] [blame] | 204 | spin_unlock_irqrestore(ap->lock, flags); |
| 205 | |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 206 | if (wait) |
Matthew Garrett | ae6c23c | 2008-05-19 17:29:34 +0100 | [diff] [blame] | 207 | ata_port_wait_eh(ap); |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static void ata_acpi_dev_notify_dock(acpi_handle handle, u32 event, void *data) |
| 211 | { |
| 212 | struct ata_device *dev = data; |
| 213 | |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 214 | ata_acpi_handle_hotplug(dev->link->ap, dev, event); |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static void ata_acpi_ap_notify_dock(acpi_handle handle, u32 event, void *data) |
| 218 | { |
| 219 | struct ata_port *ap = data; |
| 220 | |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 221 | ata_acpi_handle_hotplug(ap, NULL, event); |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 222 | } |
| 223 | |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 224 | static void ata_acpi_uevent(struct ata_port *ap, struct ata_device *dev, |
| 225 | u32 event) |
| 226 | { |
| 227 | struct kobject *kobj = NULL; |
| 228 | char event_string[20]; |
| 229 | char *envp[] = { event_string, NULL }; |
| 230 | |
| 231 | if (dev) { |
| 232 | if (dev->sdev) |
| 233 | kobj = &dev->sdev->sdev_gendev.kobj; |
| 234 | } else |
| 235 | kobj = &ap->dev->kobj; |
| 236 | |
| 237 | if (kobj) { |
| 238 | snprintf(event_string, 20, "BAY_EVENT=%d", event); |
| 239 | kobject_uevent_env(kobj, KOBJ_CHANGE, envp); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | static void ata_acpi_ap_uevent(acpi_handle handle, u32 event, void *data) |
| 244 | { |
| 245 | ata_acpi_uevent(data, NULL, event); |
| 246 | } |
| 247 | |
| 248 | static void ata_acpi_dev_uevent(acpi_handle handle, u32 event, void *data) |
| 249 | { |
| 250 | struct ata_device *dev = data; |
| 251 | ata_acpi_uevent(dev->link->ap, dev, event); |
| 252 | } |
| 253 | |
Vasiliy Kulikov | 9c8b04b | 2011-06-25 21:07:52 +0400 | [diff] [blame] | 254 | static const struct acpi_dock_ops ata_acpi_dev_dock_ops = { |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 255 | .handler = ata_acpi_dev_notify_dock, |
| 256 | .uevent = ata_acpi_dev_uevent, |
| 257 | }; |
| 258 | |
Vasiliy Kulikov | 9c8b04b | 2011-06-25 21:07:52 +0400 | [diff] [blame] | 259 | static const struct acpi_dock_ops ata_acpi_ap_dock_ops = { |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 260 | .handler = ata_acpi_ap_notify_dock, |
| 261 | .uevent = ata_acpi_ap_uevent, |
| 262 | }; |
| 263 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 264 | /** |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 265 | * ata_acpi_associate - associate ATA host with ACPI objects |
| 266 | * @host: target ATA host |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 267 | * |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 268 | * Look up ACPI objects associated with @host and initialize |
| 269 | * acpi_handle fields of @host, its ports and devices accordingly. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 270 | * |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 271 | * LOCKING: |
| 272 | * EH context. |
| 273 | * |
| 274 | * RETURNS: |
| 275 | * 0 on success, -errno on failure. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 276 | */ |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 277 | void ata_acpi_associate(struct ata_host *host) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 278 | { |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 279 | int i, j; |
Alan Cox | ca42663 | 2007-03-08 23:13:50 +0000 | [diff] [blame] | 280 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 281 | if (!is_pci_dev(host->dev) || libata_noacpi) |
| 282 | return; |
Alan Cox | ca42663 | 2007-03-08 23:13:50 +0000 | [diff] [blame] | 283 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 284 | host->acpi_handle = DEVICE_ACPI_HANDLE(host->dev); |
| 285 | if (!host->acpi_handle) |
| 286 | return; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 287 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 288 | for (i = 0; i < host->n_ports; i++) { |
| 289 | struct ata_port *ap = host->ports[i]; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 290 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 291 | if (host->ports[0]->flags & ATA_FLAG_ACPI_SATA) |
| 292 | ata_acpi_associate_sata_port(ap); |
| 293 | else |
| 294 | ata_acpi_associate_ide_port(ap); |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 295 | |
Tejun Heo | 233f112 | 2008-03-12 14:24:43 +0900 | [diff] [blame] | 296 | if (ap->acpi_handle) { |
Tejun Heo | 233f112 | 2008-03-12 14:24:43 +0900 | [diff] [blame] | 297 | /* we might be on a docking station */ |
| 298 | register_hotplug_dock_device(ap->acpi_handle, |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 299 | &ata_acpi_ap_dock_ops, ap); |
Tejun Heo | 233f112 | 2008-03-12 14:24:43 +0900 | [diff] [blame] | 300 | } |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 301 | |
| 302 | for (j = 0; j < ata_link_max_devices(&ap->link); j++) { |
| 303 | struct ata_device *dev = &ap->link.device[j]; |
| 304 | |
Tejun Heo | 233f112 | 2008-03-12 14:24:43 +0900 | [diff] [blame] | 305 | if (dev->acpi_handle) { |
Tejun Heo | 233f112 | 2008-03-12 14:24:43 +0900 | [diff] [blame] | 306 | /* we might be on a docking station */ |
| 307 | register_hotplug_dock_device(dev->acpi_handle, |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 308 | &ata_acpi_dev_dock_ops, dev); |
Tejun Heo | 233f112 | 2008-03-12 14:24:43 +0900 | [diff] [blame] | 309 | } |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 310 | } |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 311 | } |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /** |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 315 | * ata_acpi_dissociate - dissociate ATA host from ACPI objects |
| 316 | * @host: target ATA host |
| 317 | * |
| 318 | * This function is called during driver detach after the whole host |
| 319 | * is shut down. |
| 320 | * |
| 321 | * LOCKING: |
| 322 | * EH context. |
| 323 | */ |
| 324 | void ata_acpi_dissociate(struct ata_host *host) |
| 325 | { |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 326 | int i; |
| 327 | |
| 328 | /* Restore initial _GTM values so that driver which attaches |
| 329 | * afterward can use them too. |
| 330 | */ |
| 331 | for (i = 0; i < host->n_ports; i++) { |
| 332 | struct ata_port *ap = host->ports[i]; |
| 333 | const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); |
| 334 | |
| 335 | if (ap->acpi_handle && gtm) |
| 336 | ata_acpi_stm(ap, gtm); |
| 337 | } |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /** |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 341 | * ata_acpi_gtm - execute _GTM |
| 342 | * @ap: target ATA port |
| 343 | * @gtm: out parameter for _GTM result |
| 344 | * |
| 345 | * Evaluate _GTM and store the result in @gtm. |
| 346 | * |
| 347 | * LOCKING: |
| 348 | * EH context. |
| 349 | * |
| 350 | * RETURNS: |
| 351 | * 0 on success, -ENOENT if _GTM doesn't exist, -errno on failure. |
| 352 | */ |
Tejun Heo | 0d02f0b | 2007-12-15 15:04:57 +0900 | [diff] [blame] | 353 | int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *gtm) |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 354 | { |
| 355 | struct acpi_buffer output = { .length = ACPI_ALLOCATE_BUFFER }; |
| 356 | union acpi_object *out_obj; |
| 357 | acpi_status status; |
| 358 | int rc = 0; |
| 359 | |
| 360 | status = acpi_evaluate_object(ap->acpi_handle, "_GTM", NULL, &output); |
| 361 | |
| 362 | rc = -ENOENT; |
| 363 | if (status == AE_NOT_FOUND) |
| 364 | goto out_free; |
| 365 | |
| 366 | rc = -EINVAL; |
| 367 | if (ACPI_FAILURE(status)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 368 | ata_port_err(ap, "ACPI get timing mode failed (AE 0x%x)\n", |
| 369 | status); |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 370 | goto out_free; |
| 371 | } |
| 372 | |
| 373 | out_obj = output.pointer; |
| 374 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 375 | ata_port_warn(ap, "_GTM returned unexpected object type 0x%x\n", |
| 376 | out_obj->type); |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 377 | |
| 378 | goto out_free; |
| 379 | } |
| 380 | |
| 381 | if (out_obj->buffer.length != sizeof(struct ata_acpi_gtm)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 382 | ata_port_err(ap, "_GTM returned invalid length %d\n", |
| 383 | out_obj->buffer.length); |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 384 | goto out_free; |
| 385 | } |
| 386 | |
| 387 | memcpy(gtm, out_obj->buffer.pointer, sizeof(struct ata_acpi_gtm)); |
| 388 | rc = 0; |
| 389 | out_free: |
| 390 | kfree(output.pointer); |
| 391 | return rc; |
| 392 | } |
| 393 | |
Alan Cox | badff03 | 2007-10-04 21:28:18 +0100 | [diff] [blame] | 394 | EXPORT_SYMBOL_GPL(ata_acpi_gtm); |
| 395 | |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 396 | /** |
| 397 | * ata_acpi_stm - execute _STM |
| 398 | * @ap: target ATA port |
| 399 | * @stm: timing parameter to _STM |
| 400 | * |
| 401 | * Evaluate _STM with timing parameter @stm. |
| 402 | * |
| 403 | * LOCKING: |
| 404 | * EH context. |
| 405 | * |
| 406 | * RETURNS: |
| 407 | * 0 on success, -ENOENT if _STM doesn't exist, -errno on failure. |
| 408 | */ |
Tejun Heo | 0d02f0b | 2007-12-15 15:04:57 +0900 | [diff] [blame] | 409 | int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm) |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 410 | { |
| 411 | acpi_status status; |
Tejun Heo | 0d02f0b | 2007-12-15 15:04:57 +0900 | [diff] [blame] | 412 | struct ata_acpi_gtm stm_buf = *stm; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 413 | struct acpi_object_list input; |
| 414 | union acpi_object in_params[3]; |
| 415 | |
| 416 | in_params[0].type = ACPI_TYPE_BUFFER; |
| 417 | in_params[0].buffer.length = sizeof(struct ata_acpi_gtm); |
Tejun Heo | 0d02f0b | 2007-12-15 15:04:57 +0900 | [diff] [blame] | 418 | in_params[0].buffer.pointer = (u8 *)&stm_buf; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 419 | /* Buffers for id may need byteswapping ? */ |
| 420 | in_params[1].type = ACPI_TYPE_BUFFER; |
| 421 | in_params[1].buffer.length = 512; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 422 | in_params[1].buffer.pointer = (u8 *)ap->link.device[0].id; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 423 | in_params[2].type = ACPI_TYPE_BUFFER; |
| 424 | in_params[2].buffer.length = 512; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 425 | in_params[2].buffer.pointer = (u8 *)ap->link.device[1].id; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 426 | |
| 427 | input.count = 3; |
| 428 | input.pointer = in_params; |
| 429 | |
| 430 | status = acpi_evaluate_object(ap->acpi_handle, "_STM", &input, NULL); |
| 431 | |
| 432 | if (status == AE_NOT_FOUND) |
| 433 | return -ENOENT; |
| 434 | if (ACPI_FAILURE(status)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 435 | ata_port_err(ap, "ACPI set timing mode failed (status=0x%x)\n", |
| 436 | status); |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 437 | return -EINVAL; |
| 438 | } |
| 439 | return 0; |
| 440 | } |
| 441 | |
Alan Cox | badff03 | 2007-10-04 21:28:18 +0100 | [diff] [blame] | 442 | EXPORT_SYMBOL_GPL(ata_acpi_stm); |
| 443 | |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 444 | /** |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 445 | * ata_dev_get_GTF - get the drive bootup default taskfile settings |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 446 | * @dev: target ATA device |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 447 | * @gtf: output parameter for buffer containing _GTF taskfile arrays |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 448 | * |
| 449 | * This applies to both PATA and SATA drives. |
| 450 | * |
| 451 | * The _GTF method has no input parameters. |
| 452 | * It returns a variable number of register set values (registers |
| 453 | * hex 1F1..1F7, taskfiles). |
| 454 | * The <variable number> is not known in advance, so have ACPI-CA |
| 455 | * allocate the buffer as needed and return it, then free it later. |
| 456 | * |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 457 | * LOCKING: |
| 458 | * EH context. |
| 459 | * |
| 460 | * RETURNS: |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 461 | * Number of taskfiles on success, 0 if _GTF doesn't exist. -EINVAL |
| 462 | * if _GTF is invalid. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 463 | */ |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 464 | static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 465 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 466 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 467 | acpi_status status; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 468 | struct acpi_buffer output; |
| 469 | union acpi_object *out_obj; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 470 | int rc = 0; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 471 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 472 | /* if _GTF is cached, use the cached value */ |
| 473 | if (dev->gtf_cache) { |
| 474 | out_obj = dev->gtf_cache; |
| 475 | goto done; |
| 476 | } |
| 477 | |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 478 | /* set up output buffer */ |
| 479 | output.length = ACPI_ALLOCATE_BUFFER; |
| 480 | output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 481 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 482 | if (ata_msg_probe(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 483 | ata_dev_dbg(dev, "%s: ENTER: port#: %d\n", |
| 484 | __func__, ap->port_no); |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 485 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 486 | /* _GTF has no input parameters */ |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 487 | status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output); |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 488 | out_obj = dev->gtf_cache = output.pointer; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 489 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 490 | if (ACPI_FAILURE(status)) { |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 491 | if (status != AE_NOT_FOUND) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 492 | ata_dev_warn(dev, "_GTF evaluation failed (AE 0x%x)\n", |
| 493 | status); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 494 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 495 | } |
| 496 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | if (!output.length || !output.pointer) { |
| 500 | if (ata_msg_probe(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 501 | ata_dev_dbg(dev, "%s: Run _GTF: length or ptr is NULL (0x%llx, 0x%p)\n", |
| 502 | __func__, |
| 503 | (unsigned long long)output.length, |
| 504 | output.pointer); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 505 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 506 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 509 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 510 | ata_dev_warn(dev, "_GTF unexpected object type 0x%x\n", |
| 511 | out_obj->type); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 512 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 513 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 516 | if (out_obj->buffer.length % REGS_PER_GTF) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 517 | ata_dev_warn(dev, "unexpected _GTF length (%d)\n", |
| 518 | out_obj->buffer.length); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 519 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 520 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 523 | done: |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 524 | rc = out_obj->buffer.length / REGS_PER_GTF; |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 525 | if (gtf) { |
| 526 | *gtf = (void *)out_obj->buffer.pointer; |
| 527 | if (ata_msg_probe(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 528 | ata_dev_dbg(dev, "%s: returning gtf=%p, gtf_count=%d\n", |
| 529 | __func__, *gtf, rc); |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 530 | } |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 531 | return rc; |
| 532 | |
| 533 | out_free: |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 534 | ata_acpi_clear_gtf(dev); |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 535 | return rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Tejun Heo | 7c77fa4 | 2007-12-18 16:33:03 +0900 | [diff] [blame] | 538 | /** |
| 539 | * ata_acpi_gtm_xfermode - determine xfermode from GTM parameter |
| 540 | * @dev: target device |
| 541 | * @gtm: GTM parameter to use |
| 542 | * |
| 543 | * Determine xfermask for @dev from @gtm. |
| 544 | * |
| 545 | * LOCKING: |
| 546 | * None. |
| 547 | * |
| 548 | * RETURNS: |
| 549 | * Determined xfermask. |
| 550 | */ |
| 551 | unsigned long ata_acpi_gtm_xfermask(struct ata_device *dev, |
| 552 | const struct ata_acpi_gtm *gtm) |
| 553 | { |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 554 | unsigned long xfer_mask = 0; |
| 555 | unsigned int type; |
| 556 | int unit; |
| 557 | u8 mode; |
Tejun Heo | 7c77fa4 | 2007-12-18 16:33:03 +0900 | [diff] [blame] | 558 | |
| 559 | /* we always use the 0 slot for crap hardware */ |
| 560 | unit = dev->devno; |
| 561 | if (!(gtm->flags & 0x10)) |
| 562 | unit = 0; |
| 563 | |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 564 | /* PIO */ |
| 565 | mode = ata_timing_cycle2mode(ATA_SHIFT_PIO, gtm->drive[unit].pio); |
| 566 | xfer_mask |= ata_xfer_mode2mask(mode); |
Tejun Heo | 7c77fa4 | 2007-12-18 16:33:03 +0900 | [diff] [blame] | 567 | |
| 568 | /* See if we have MWDMA or UDMA data. We don't bother with |
| 569 | * MWDMA if UDMA is available as this means the BIOS set UDMA |
| 570 | * and our error changedown if it works is UDMA to PIO anyway. |
| 571 | */ |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 572 | if (!(gtm->flags & (1 << (2 * unit)))) |
| 573 | type = ATA_SHIFT_MWDMA; |
| 574 | else |
| 575 | type = ATA_SHIFT_UDMA; |
Tejun Heo | 7c77fa4 | 2007-12-18 16:33:03 +0900 | [diff] [blame] | 576 | |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 577 | mode = ata_timing_cycle2mode(type, gtm->drive[unit].dma); |
| 578 | xfer_mask |= ata_xfer_mode2mask(mode); |
| 579 | |
| 580 | return xfer_mask; |
Tejun Heo | 7c77fa4 | 2007-12-18 16:33:03 +0900 | [diff] [blame] | 581 | } |
| 582 | EXPORT_SYMBOL_GPL(ata_acpi_gtm_xfermask); |
| 583 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 584 | /** |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 585 | * ata_acpi_cbl_80wire - Check for 80 wire cable |
| 586 | * @ap: Port to check |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 587 | * @gtm: GTM data to use |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 588 | * |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 589 | * Return 1 if the @gtm indicates the BIOS selected an 80wire mode. |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 590 | */ |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 591 | int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm) |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 592 | { |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 593 | struct ata_device *dev; |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 594 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 595 | ata_for_each_dev(dev, &ap->link, ENABLED) { |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 596 | unsigned long xfer_mask, udma_mask; |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 597 | |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 598 | xfer_mask = ata_acpi_gtm_xfermask(dev, gtm); |
| 599 | ata_unpack_xfermask(xfer_mask, NULL, NULL, &udma_mask); |
| 600 | |
| 601 | if (udma_mask & ~ATA_UDMA_MASK_40C) |
| 602 | return 1; |
| 603 | } |
| 604 | |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 605 | return 0; |
| 606 | } |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 607 | EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire); |
| 608 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 609 | static void ata_acpi_gtf_to_tf(struct ata_device *dev, |
| 610 | const struct ata_acpi_gtf *gtf, |
| 611 | struct ata_taskfile *tf) |
| 612 | { |
| 613 | ata_tf_init(dev, tf); |
| 614 | |
| 615 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 616 | tf->protocol = ATA_PROT_NODATA; |
| 617 | tf->feature = gtf->tf[0]; /* 0x1f1 */ |
| 618 | tf->nsect = gtf->tf[1]; /* 0x1f2 */ |
| 619 | tf->lbal = gtf->tf[2]; /* 0x1f3 */ |
| 620 | tf->lbam = gtf->tf[3]; /* 0x1f4 */ |
| 621 | tf->lbah = gtf->tf[4]; /* 0x1f5 */ |
| 622 | tf->device = gtf->tf[5]; /* 0x1f6 */ |
| 623 | tf->command = gtf->tf[6]; /* 0x1f7 */ |
| 624 | } |
| 625 | |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 626 | static int ata_acpi_filter_tf(struct ata_device *dev, |
| 627 | const struct ata_taskfile *tf, |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 628 | const struct ata_taskfile *ptf) |
| 629 | { |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 630 | if (dev->gtf_filter & ATA_ACPI_FILTER_SETXFER) { |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 631 | /* libata doesn't use ACPI to configure transfer mode. |
| 632 | * It will only confuse device configuration. Skip. |
| 633 | */ |
| 634 | if (tf->command == ATA_CMD_SET_FEATURES && |
| 635 | tf->feature == SETFEATURES_XFER) |
| 636 | return 1; |
| 637 | } |
| 638 | |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 639 | if (dev->gtf_filter & ATA_ACPI_FILTER_LOCK) { |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 640 | /* BIOS writers, sorry but we don't wanna lock |
| 641 | * features unless the user explicitly said so. |
| 642 | */ |
| 643 | |
| 644 | /* DEVICE CONFIGURATION FREEZE LOCK */ |
| 645 | if (tf->command == ATA_CMD_CONF_OVERLAY && |
| 646 | tf->feature == ATA_DCO_FREEZE_LOCK) |
| 647 | return 1; |
| 648 | |
| 649 | /* SECURITY FREEZE LOCK */ |
| 650 | if (tf->command == ATA_CMD_SEC_FREEZE_LOCK) |
| 651 | return 1; |
| 652 | |
| 653 | /* SET MAX LOCK and SET MAX FREEZE LOCK */ |
| 654 | if ((!ptf || ptf->command != ATA_CMD_READ_NATIVE_MAX) && |
| 655 | tf->command == ATA_CMD_SET_MAX && |
| 656 | (tf->feature == ATA_SET_MAX_LOCK || |
| 657 | tf->feature == ATA_SET_MAX_FREEZE_LOCK)) |
| 658 | return 1; |
| 659 | } |
| 660 | |
Tejun Heo | fa5b561 | 2009-09-16 04:17:02 +0900 | [diff] [blame] | 661 | if (tf->command == ATA_CMD_SET_FEATURES && |
| 662 | tf->feature == SETFEATURES_SATA_ENABLE) { |
Tejun Heo | b344991 | 2008-07-06 23:15:03 +0900 | [diff] [blame] | 663 | /* inhibit enabling DIPM */ |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 664 | if (dev->gtf_filter & ATA_ACPI_FILTER_DIPM && |
Tejun Heo | b344991 | 2008-07-06 23:15:03 +0900 | [diff] [blame] | 665 | tf->nsect == SATA_DIPM) |
| 666 | return 1; |
Tejun Heo | fa5b561 | 2009-09-16 04:17:02 +0900 | [diff] [blame] | 667 | |
| 668 | /* inhibit FPDMA non-zero offset */ |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 669 | if (dev->gtf_filter & ATA_ACPI_FILTER_FPDMA_OFFSET && |
Tejun Heo | fa5b561 | 2009-09-16 04:17:02 +0900 | [diff] [blame] | 670 | (tf->nsect == SATA_FPDMA_OFFSET || |
| 671 | tf->nsect == SATA_FPDMA_IN_ORDER)) |
| 672 | return 1; |
| 673 | |
| 674 | /* inhibit FPDMA auto activation */ |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 675 | if (dev->gtf_filter & ATA_ACPI_FILTER_FPDMA_AA && |
Tejun Heo | fa5b561 | 2009-09-16 04:17:02 +0900 | [diff] [blame] | 676 | tf->nsect == SATA_FPDMA_AA) |
| 677 | return 1; |
Tejun Heo | b344991 | 2008-07-06 23:15:03 +0900 | [diff] [blame] | 678 | } |
| 679 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 680 | return 0; |
| 681 | } |
| 682 | |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 683 | /** |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 684 | * ata_acpi_run_tf - send taskfile registers to host controller |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 685 | * @dev: target ATA device |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 686 | * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7) |
| 687 | * |
Sergei Shtylyov | 3696df3 | 2011-02-04 22:04:17 +0300 | [diff] [blame] | 688 | * Outputs ATA taskfile to standard ATA host controller. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 689 | * Writes the control, feature, nsect, lbal, lbam, and lbah registers. |
| 690 | * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect, |
| 691 | * hob_lbal, hob_lbam, and hob_lbah. |
| 692 | * |
| 693 | * This function waits for idle (!BUSY and !DRQ) after writing |
| 694 | * registers. If the control register has a new value, this |
| 695 | * function also waits for idle after writing control and before |
| 696 | * writing the remaining registers. |
| 697 | * |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 698 | * LOCKING: |
| 699 | * EH context. |
| 700 | * |
| 701 | * RETURNS: |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 702 | * 1 if command is executed successfully. 0 if ignored, rejected or |
| 703 | * filtered out, -errno on other errors. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 704 | */ |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 705 | static int ata_acpi_run_tf(struct ata_device *dev, |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 706 | const struct ata_acpi_gtf *gtf, |
| 707 | const struct ata_acpi_gtf *prev_gtf) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 708 | { |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 709 | struct ata_taskfile *pptf = NULL; |
| 710 | struct ata_taskfile tf, ptf, rtf; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 711 | unsigned int err_mask; |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 712 | const char *level; |
Robert Hancock | 6521148 | 2009-07-14 20:43:39 -0600 | [diff] [blame] | 713 | const char *descr; |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 714 | char msg[60]; |
| 715 | int rc; |
Jeff Garzik | fc16c25 | 2007-02-24 21:05:01 -0500 | [diff] [blame] | 716 | |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 717 | if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0) |
| 718 | && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0) |
| 719 | && (gtf->tf[6] == 0)) |
| 720 | return 0; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 721 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 722 | ata_acpi_gtf_to_tf(dev, gtf, &tf); |
| 723 | if (prev_gtf) { |
| 724 | ata_acpi_gtf_to_tf(dev, prev_gtf, &ptf); |
| 725 | pptf = &ptf; |
| 726 | } |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 727 | |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 728 | if (!ata_acpi_filter_tf(dev, &tf, pptf)) { |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 729 | rtf = tf; |
| 730 | err_mask = ata_exec_internal(dev, &rtf, NULL, |
| 731 | DMA_NONE, NULL, 0, 0); |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 732 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 733 | switch (err_mask) { |
| 734 | case 0: |
| 735 | level = KERN_DEBUG; |
| 736 | snprintf(msg, sizeof(msg), "succeeded"); |
| 737 | rc = 1; |
| 738 | break; |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 739 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 740 | case AC_ERR_DEV: |
| 741 | level = KERN_INFO; |
| 742 | snprintf(msg, sizeof(msg), |
| 743 | "rejected by device (Stat=0x%02x Err=0x%02x)", |
| 744 | rtf.command, rtf.feature); |
| 745 | rc = 0; |
| 746 | break; |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 747 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 748 | default: |
| 749 | level = KERN_ERR; |
| 750 | snprintf(msg, sizeof(msg), |
| 751 | "failed (Emask=0x%x Stat=0x%02x Err=0x%02x)", |
| 752 | err_mask, rtf.command, rtf.feature); |
| 753 | rc = -EIO; |
| 754 | break; |
| 755 | } |
| 756 | } else { |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 757 | level = KERN_INFO; |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 758 | snprintf(msg, sizeof(msg), "filtered out"); |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 759 | rc = 0; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 760 | } |
Robert Hancock | 6521148 | 2009-07-14 20:43:39 -0600 | [diff] [blame] | 761 | descr = ata_get_cmd_descript(tf.command); |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 762 | |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 763 | ata_dev_printk(dev, level, |
Robert Hancock | 6521148 | 2009-07-14 20:43:39 -0600 | [diff] [blame] | 764 | "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x (%s) %s\n", |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 765 | tf.command, tf.feature, tf.nsect, tf.lbal, |
Robert Hancock | 6521148 | 2009-07-14 20:43:39 -0600 | [diff] [blame] | 766 | tf.lbam, tf.lbah, tf.device, |
| 767 | (descr ? descr : "unknown"), msg); |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 768 | |
| 769 | return rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /** |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 773 | * ata_acpi_exec_tfs - get then write drive taskfile settings |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 774 | * @dev: target ATA device |
Martin Olsson | 98a1708 | 2009-04-22 18:21:29 +0200 | [diff] [blame] | 775 | * @nr_executed: out parameter for the number of executed commands |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 776 | * |
Martin Olsson | 98a1708 | 2009-04-22 18:21:29 +0200 | [diff] [blame] | 777 | * Evaluate _GTF and execute returned taskfiles. |
Tejun Heo | 69b16a5 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 778 | * |
| 779 | * LOCKING: |
| 780 | * EH context. |
| 781 | * |
| 782 | * RETURNS: |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 783 | * Number of executed taskfiles on success, 0 if _GTF doesn't exist. |
| 784 | * -errno on other errors. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 785 | */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 786 | static int ata_acpi_exec_tfs(struct ata_device *dev, int *nr_executed) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 787 | { |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 788 | struct ata_acpi_gtf *gtf = NULL, *pgtf = NULL; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 789 | int gtf_count, i, rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 790 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 791 | /* get taskfiles */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 792 | rc = ata_dev_get_GTF(dev, >f); |
| 793 | if (rc < 0) |
| 794 | return rc; |
| 795 | gtf_count = rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 796 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 797 | /* execute them */ |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 798 | for (i = 0; i < gtf_count; i++, gtf++) { |
| 799 | rc = ata_acpi_run_tf(dev, gtf, pgtf); |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 800 | if (rc < 0) |
| 801 | break; |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 802 | if (rc) { |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 803 | (*nr_executed)++; |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 804 | pgtf = gtf; |
| 805 | } |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 808 | ata_acpi_clear_gtf(dev); |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 809 | |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 810 | if (rc < 0) |
| 811 | return rc; |
| 812 | return 0; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 815 | /** |
| 816 | * ata_acpi_push_id - send Identify data to drive |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 817 | * @dev: target ATA device |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 818 | * |
| 819 | * _SDD ACPI object: for SATA mode only |
| 820 | * Must be after Identify (Packet) Device -- uses its data |
| 821 | * ATM this function never returns a failure. It is an optional |
| 822 | * method and if it fails for whatever reason, we should still |
| 823 | * just keep going. |
Tejun Heo | 69b16a5 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 824 | * |
| 825 | * LOCKING: |
| 826 | * EH context. |
| 827 | * |
| 828 | * RETURNS: |
Tejun Heo | f240677 | 2009-11-18 22:24:21 +0900 | [diff] [blame] | 829 | * 0 on success, -ENOENT if _SDD doesn't exist, -errno on failure. |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 830 | */ |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 831 | static int ata_acpi_push_id(struct ata_device *dev) |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 832 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 833 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 834 | acpi_status status; |
| 835 | struct acpi_object_list input; |
| 836 | union acpi_object in_params[1]; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 837 | |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 838 | if (ata_msg_probe(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 839 | ata_dev_dbg(dev, "%s: ix = %d, port#: %d\n", |
| 840 | __func__, dev->devno, ap->port_no); |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 841 | |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 842 | /* Give the drive Identify data to the drive via the _SDD method */ |
| 843 | /* _SDD: set up input parameters */ |
| 844 | input.count = 1; |
| 845 | input.pointer = in_params; |
| 846 | in_params[0].type = ACPI_TYPE_BUFFER; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 847 | in_params[0].buffer.length = sizeof(dev->id[0]) * ATA_ID_WORDS; |
| 848 | in_params[0].buffer.pointer = (u8 *)dev->id; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 849 | /* Output buffer: _SDD has no output */ |
| 850 | |
| 851 | /* It's OK for _SDD to be missing too. */ |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 852 | swap_buf_le16(dev->id, ATA_ID_WORDS); |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 853 | status = acpi_evaluate_object(dev->acpi_handle, "_SDD", &input, NULL); |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 854 | swap_buf_le16(dev->id, ATA_ID_WORDS); |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 855 | |
Tejun Heo | f240677 | 2009-11-18 22:24:21 +0900 | [diff] [blame] | 856 | if (status == AE_NOT_FOUND) |
| 857 | return -ENOENT; |
| 858 | |
| 859 | if (ACPI_FAILURE(status)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 860 | ata_dev_warn(dev, "ACPI _SDD failed (AE 0x%x)\n", status); |
Tejun Heo | f240677 | 2009-11-18 22:24:21 +0900 | [diff] [blame] | 861 | return -EIO; |
| 862 | } |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 863 | |
Tejun Heo | f240677 | 2009-11-18 22:24:21 +0900 | [diff] [blame] | 864 | return 0; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 867 | /** |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 868 | * ata_acpi_on_suspend - ATA ACPI hook called on suspend |
| 869 | * @ap: target ATA port |
| 870 | * |
| 871 | * This function is called when @ap is about to be suspended. All |
| 872 | * devices are already put to sleep but the port_suspend() callback |
| 873 | * hasn't been executed yet. Error return from this function aborts |
| 874 | * suspend. |
| 875 | * |
| 876 | * LOCKING: |
| 877 | * EH context. |
| 878 | * |
| 879 | * RETURNS: |
| 880 | * 0 on success, -errno on failure. |
| 881 | */ |
| 882 | int ata_acpi_on_suspend(struct ata_port *ap) |
| 883 | { |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 884 | /* nada */ |
| 885 | return 0; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | /** |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 889 | * ata_acpi_on_resume - ATA ACPI hook called on resume |
| 890 | * @ap: target ATA port |
| 891 | * |
| 892 | * This function is called when @ap is resumed - right after port |
| 893 | * itself is resumed but before any EH action is taken. |
| 894 | * |
| 895 | * LOCKING: |
| 896 | * EH context. |
| 897 | */ |
| 898 | void ata_acpi_on_resume(struct ata_port *ap) |
| 899 | { |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 900 | const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 901 | struct ata_device *dev; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 902 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 903 | if (ap->acpi_handle && gtm) { |
| 904 | /* _GTM valid */ |
| 905 | |
| 906 | /* restore timing parameters */ |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 907 | ata_acpi_stm(ap, gtm); |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 908 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 909 | /* _GTF should immediately follow _STM so that it can |
| 910 | * use values set by _STM. Cache _GTF result and |
| 911 | * schedule _GTF. |
| 912 | */ |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 913 | ata_for_each_dev(dev, &ap->link, ALL) { |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 914 | ata_acpi_clear_gtf(dev); |
Shaohua Li | 48feb3c | 2008-03-25 16:50:45 +0800 | [diff] [blame] | 915 | if (ata_dev_enabled(dev) && |
| 916 | ata_dev_get_GTF(dev, NULL) >= 0) |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 917 | dev->flags |= ATA_DFLAG_ACPI_PENDING; |
| 918 | } |
| 919 | } else { |
| 920 | /* SATA _GTF needs to be evaulated after _SDD and |
| 921 | * there's no reason to evaluate IDE _GTF early |
| 922 | * without _STM. Clear cache and schedule _GTF. |
| 923 | */ |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 924 | ata_for_each_dev(dev, &ap->link, ALL) { |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 925 | ata_acpi_clear_gtf(dev); |
Shaohua Li | 48feb3c | 2008-03-25 16:50:45 +0800 | [diff] [blame] | 926 | if (ata_dev_enabled(dev)) |
| 927 | dev->flags |= ATA_DFLAG_ACPI_PENDING; |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 928 | } |
| 929 | } |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | /** |
Shaohua Li | bd3adca | 2007-11-02 09:32:38 +0800 | [diff] [blame] | 933 | * ata_acpi_set_state - set the port power state |
| 934 | * @ap: target ATA port |
| 935 | * @state: state, on/off |
| 936 | * |
| 937 | * This function executes the _PS0/_PS3 ACPI method to set the power state. |
| 938 | * ACPI spec requires _PS0 when IDE power on and _PS3 when power off |
| 939 | */ |
| 940 | void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) |
| 941 | { |
| 942 | struct ata_device *dev; |
| 943 | |
| 944 | if (!ap->acpi_handle || (ap->flags & ATA_FLAG_ACPI_SATA)) |
| 945 | return; |
| 946 | |
| 947 | /* channel first and then drives for power on and vica versa |
| 948 | for power off */ |
| 949 | if (state.event == PM_EVENT_ON) |
| 950 | acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0); |
| 951 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 952 | ata_for_each_dev(dev, &ap->link, ENABLED) { |
| 953 | if (dev->acpi_handle) |
Shaohua Li | bd3adca | 2007-11-02 09:32:38 +0800 | [diff] [blame] | 954 | acpi_bus_set_power(dev->acpi_handle, |
| 955 | state.event == PM_EVENT_ON ? |
| 956 | ACPI_STATE_D0 : ACPI_STATE_D3); |
| 957 | } |
| 958 | if (state.event != PM_EVENT_ON) |
| 959 | acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D3); |
| 960 | } |
| 961 | |
| 962 | /** |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 963 | * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration |
| 964 | * @dev: target ATA device |
| 965 | * |
| 966 | * This function is called when @dev is about to be configured. |
| 967 | * IDENTIFY data might have been modified after this hook is run. |
| 968 | * |
| 969 | * LOCKING: |
| 970 | * EH context. |
| 971 | * |
| 972 | * RETURNS: |
| 973 | * Positive number if IDENTIFY data needs to be refreshed, 0 if not, |
| 974 | * -errno on failure. |
| 975 | */ |
| 976 | int ata_acpi_on_devcfg(struct ata_device *dev) |
| 977 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 978 | struct ata_port *ap = dev->link->ap; |
| 979 | struct ata_eh_context *ehc = &ap->link.eh_context; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 980 | int acpi_sata = ap->flags & ATA_FLAG_ACPI_SATA; |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 981 | int nr_executed = 0; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 982 | int rc; |
| 983 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 984 | if (!dev->acpi_handle) |
| 985 | return 0; |
| 986 | |
| 987 | /* do we need to do _GTF? */ |
| 988 | if (!(dev->flags & ATA_DFLAG_ACPI_PENDING) && |
| 989 | !(acpi_sata && (ehc->i.flags & ATA_EHI_DID_HARDRESET))) |
| 990 | return 0; |
| 991 | |
| 992 | /* do _SDD if SATA */ |
| 993 | if (acpi_sata) { |
| 994 | rc = ata_acpi_push_id(dev); |
Tejun Heo | f240677 | 2009-11-18 22:24:21 +0900 | [diff] [blame] | 995 | if (rc && rc != -ENOENT) |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 996 | goto acpi_err; |
| 997 | } |
| 998 | |
| 999 | /* do _GTF */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1000 | rc = ata_acpi_exec_tfs(dev, &nr_executed); |
| 1001 | if (rc) |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1002 | goto acpi_err; |
| 1003 | |
| 1004 | dev->flags &= ~ATA_DFLAG_ACPI_PENDING; |
| 1005 | |
| 1006 | /* refresh IDENTIFY page if any _GTF command has been executed */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1007 | if (nr_executed) { |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1008 | rc = ata_dev_reread_id(dev, 0); |
| 1009 | if (rc < 0) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1010 | ata_dev_err(dev, |
| 1011 | "failed to IDENTIFY after ACPI commands\n"); |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1012 | return rc; |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | return 0; |
| 1017 | |
| 1018 | acpi_err: |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1019 | /* ignore evaluation failure if we can continue safely */ |
| 1020 | if (rc == -EINVAL && !nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN)) |
| 1021 | return 0; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1022 | |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1023 | /* fail and let EH retry once more for unknown IO errors */ |
| 1024 | if (!(dev->flags & ATA_DFLAG_ACPI_FAILED)) { |
| 1025 | dev->flags |= ATA_DFLAG_ACPI_FAILED; |
| 1026 | return rc; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1027 | } |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1028 | |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1029 | ata_dev_warn(dev, "ACPI: failed the second time, disabled\n"); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1030 | dev->acpi_handle = NULL; |
| 1031 | |
| 1032 | /* We can safely continue if no _GTF command has been executed |
| 1033 | * and port is not frozen. |
| 1034 | */ |
| 1035 | if (!nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN)) |
| 1036 | return 0; |
| 1037 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1038 | return rc; |
| 1039 | } |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 1040 | |
| 1041 | /** |
| 1042 | * ata_acpi_on_disable - ATA ACPI hook called when a device is disabled |
| 1043 | * @dev: target ATA device |
| 1044 | * |
| 1045 | * This function is called when @dev is about to be disabled. |
| 1046 | * |
| 1047 | * LOCKING: |
| 1048 | * EH context. |
| 1049 | */ |
| 1050 | void ata_acpi_on_disable(struct ata_device *dev) |
| 1051 | { |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 1052 | ata_acpi_clear_gtf(dev); |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 1053 | } |
Matthew Garrett | 6b66d95 | 2012-06-25 16:13:03 +0800 | [diff] [blame^] | 1054 | |
| 1055 | static int compat_pci_ata(struct ata_port *ap) |
| 1056 | { |
| 1057 | struct device *dev = ap->tdev.parent; |
| 1058 | struct pci_dev *pdev; |
| 1059 | |
| 1060 | if (!is_pci_dev(dev)) |
| 1061 | return 0; |
| 1062 | |
| 1063 | pdev = to_pci_dev(dev); |
| 1064 | |
| 1065 | if ((pdev->class >> 8) != PCI_CLASS_STORAGE_SATA && |
| 1066 | (pdev->class >> 8) != PCI_CLASS_STORAGE_IDE) |
| 1067 | return 0; |
| 1068 | |
| 1069 | return 1; |
| 1070 | } |
| 1071 | |
| 1072 | static int ata_acpi_bind_host(struct ata_port *ap, acpi_handle *handle) |
| 1073 | { |
| 1074 | if (ap->flags & ATA_FLAG_ACPI_SATA) |
| 1075 | return -ENODEV; |
| 1076 | |
| 1077 | *handle = acpi_get_child(DEVICE_ACPI_HANDLE(ap->tdev.parent), |
| 1078 | ap->port_no); |
| 1079 | |
| 1080 | if (!*handle) |
| 1081 | return -ENODEV; |
| 1082 | |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
| 1086 | static int ata_acpi_bind_device(struct ata_port *ap, struct scsi_device *sdev, |
| 1087 | acpi_handle *handle) |
| 1088 | { |
| 1089 | struct ata_device *ata_dev; |
| 1090 | |
| 1091 | if (ap->flags & ATA_FLAG_ACPI_SATA) |
| 1092 | ata_dev = &ap->link.device[sdev->channel]; |
| 1093 | else |
| 1094 | ata_dev = &ap->link.device[sdev->id]; |
| 1095 | |
| 1096 | *handle = dev_acpi_handle(ata_dev); |
| 1097 | |
| 1098 | if (!*handle) |
| 1099 | return -ENODEV; |
| 1100 | |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
| 1104 | static int is_ata_port(const struct device *dev) |
| 1105 | { |
| 1106 | return dev->type == &ata_port_type; |
| 1107 | } |
| 1108 | |
| 1109 | static struct ata_port *dev_to_ata_port(struct device *dev) |
| 1110 | { |
| 1111 | while (!is_ata_port(dev)) { |
| 1112 | if (!dev->parent) |
| 1113 | return NULL; |
| 1114 | dev = dev->parent; |
| 1115 | } |
| 1116 | return to_ata_port(dev); |
| 1117 | } |
| 1118 | |
| 1119 | static int ata_acpi_find_device(struct device *dev, acpi_handle *handle) |
| 1120 | { |
| 1121 | struct ata_port *ap = dev_to_ata_port(dev); |
| 1122 | |
| 1123 | if (!ap) |
| 1124 | return -ENODEV; |
| 1125 | |
| 1126 | if (!compat_pci_ata(ap)) |
| 1127 | return -ENODEV; |
| 1128 | |
| 1129 | if (scsi_is_host_device(dev)) |
| 1130 | return ata_acpi_bind_host(ap, handle); |
| 1131 | else if (scsi_is_sdev_device(dev)) { |
| 1132 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1133 | |
| 1134 | return ata_acpi_bind_device(ap, sdev, handle); |
| 1135 | } else |
| 1136 | return -ENODEV; |
| 1137 | } |
| 1138 | |
| 1139 | static int ata_acpi_find_dummy(struct device *dev, acpi_handle *handle) |
| 1140 | { |
| 1141 | return -ENODEV; |
| 1142 | } |
| 1143 | |
| 1144 | static struct acpi_bus_type ata_acpi_bus = { |
| 1145 | .find_bridge = ata_acpi_find_dummy, |
| 1146 | .find_device = ata_acpi_find_device, |
| 1147 | }; |
| 1148 | |
| 1149 | int ata_acpi_register(void) |
| 1150 | { |
| 1151 | return scsi_register_acpi_bus_type(&ata_acpi_bus); |
| 1152 | } |
| 1153 | |
| 1154 | void ata_acpi_unregister(void) |
| 1155 | { |
| 1156 | scsi_unregister_acpi_bus_type(&ata_acpi_bus); |
| 1157 | } |