9 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <linux/errno.h>
14 #include <linux/kernel.h>
17 #include <linux/pci.h>
18 #include <linux/slab.h>
27 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)");
29 #define NO_PORT_MULT 0xffff
30 #define SATA_ADR(root, pmp) (((root) << 16) | (pmp))
32 #define REGS_PER_GTF 7
47 kfree(dev->gtf_cache);
48 dev->gtf_cache =
NULL;
80 if (!sata_pmp_attached(ap))
142 ata_ehi_hotplugged(ehi);
148 ata_acpi_detach_device(ap, dev);
153 spin_unlock_irqrestore(ap->lock, flags);
163 ata_acpi_handle_hotplug(dev->
link->ap, dev, event);
170 ata_acpi_handle_hotplug(ap,
NULL, event);
177 char event_string[20];
178 char *envp[] = { event_string,
NULL };
182 kobj = &dev->
sdev->sdev_gendev.kobj;
184 kobj = &ap->
dev->kobj;
187 snprintf(event_string, 20,
"BAY_EVENT=%d", event);
194 ata_acpi_uevent(data,
NULL, event);
200 ata_acpi_uevent(dev->
link->ap, dev, event);
204 .handler = ata_acpi_dev_notify_dock,
205 .uevent = ata_acpi_dev_uevent,
209 .handler = ata_acpi_ap_notify_dock,
210 .uevent = ata_acpi_ap_uevent,
230 for (i = 0; i < host->
n_ports; i++) {
268 ata_port_err(ap,
"ACPI get timing mode failed (AE 0x%x)\n",
275 ata_port_warn(ap,
"_GTM returned unexpected object type 0x%x\n",
318 in_params[0].
buffer.pointer = (
u8 *)&stm_buf;
321 in_params[1].
buffer.length = 512;
322 in_params[1].
buffer.pointer = (
u8 *)ap->
link.device[0].id;
324 in_params[2].
buffer.length = 512;
325 in_params[2].
buffer.pointer = (
u8 *)ap->
link.device[1].id;
336 ata_port_err(ap,
"ACPI set timing mode failed (status=0x%x)\n",
374 if (dev->gtf_cache) {
375 out_obj = dev->gtf_cache;
390 out_obj = dev->gtf_cache =
output.pointer;
403 ata_dev_dbg(dev,
"%s: Run _GTF: length or ptr is NULL (0x%llx, 0x%p)\n",
405 (
unsigned long long)
output.length,
428 *gtf = (
void *)out_obj->
buffer.pointer;
430 ata_dev_dbg(dev,
"%s: returning gtf=%p, gtf_count=%d\n",
436 ata_acpi_clear_gtf(dev);
456 unsigned long xfer_mask = 0;
463 if (!(gtm->
flags & 0x10))
474 if (!(gtm->
flags & (1 << (2 * unit))))
511 static void ata_acpi_gtf_to_tf(
struct ata_device *dev,
515 ata_tf_init(dev, tf);
528 static int ata_acpi_filter_tf(
struct ata_device *dev,
607 static int ata_acpi_run_tf(
struct ata_device *dev,
613 unsigned int err_mask;
619 if ((gtf->
tf[0] == 0) && (gtf->
tf[1] == 0) && (gtf->
tf[2] == 0)
620 && (gtf->
tf[3] == 0) && (gtf->
tf[4] == 0) && (gtf->
tf[5] == 0)
621 && (gtf->
tf[6] == 0))
624 ata_acpi_gtf_to_tf(dev, gtf, &tf);
626 ata_acpi_gtf_to_tf(dev, prev_gtf, &ptf);
630 if (!ata_acpi_filter_tf(dev, &tf, pptf)) {
638 snprintf(msg,
sizeof(msg),
"succeeded");
645 "rejected by device (Stat=0x%02x Err=0x%02x)",
646 rtf.command, rtf.feature);
653 "failed (Emask=0x%x Stat=0x%02x Err=0x%02x)",
654 err_mask, rtf.command, rtf.feature);
660 snprintf(msg,
sizeof(msg),
"filtered out");
666 "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x (%s) %s\n",
669 (descr ? descr :
"unknown"), msg);
688 static int ata_acpi_exec_tfs(
struct ata_device *dev,
int *nr_executed)
691 int gtf_count,
i,
rc;
694 rc = ata_dev_get_GTF(dev, >f);
700 for (i = 0; i < gtf_count; i++, gtf++) {
701 rc = ata_acpi_run_tf(dev, gtf, pgtf);
710 ata_acpi_clear_gtf(dev);
733 static int ata_acpi_push_id(
struct ata_device *dev)
747 input.pointer = in_params;
750 in_params[0].buffer.pointer = (
u8 *)dev->
id;
763 ata_dev_warn(dev,
"ACPI _SDD failed (AE 0x%x)\n", status);
817 ata_acpi_clear_gtf(dev);
818 if (ata_dev_enabled(dev) &&
819 ata_dev_get_GTF(dev,
NULL) >= 0)
828 ata_acpi_clear_gtf(dev);
829 if (ata_dev_enabled(dev))
861 acpi_state = acpi_pm_device_sleep_state(
866 acpi_pm_device_run_wake(
867 &dev->
sdev->sdev_gendev,
true);
870 acpi_pm_device_run_wake(
871 &dev->
sdev->sdev_gendev,
false);
913 rc = ata_acpi_push_id(dev);
919 rc = ata_acpi_exec_tfs(dev, &nr_executed);
930 "failed to IDENTIFY after ACPI commands\n");
948 ata_dev_warn(dev,
"ACPI: failed the second time, disabled\n");
970 ata_acpi_clear_gtf(dev);
978 pm_runtime_suspended(&ata_dev->
sdev->sdev_gendev))
979 scsi_autopm_get_device(ata_dev->
sdev);
982 static void ata_acpi_add_pm_notifier(
struct ata_device *dev)
984 struct acpi_device *acpi_dev;
996 if (dev->
sdev->can_power_off) {
998 ata_acpi_wake_dev, dev);
999 device_set_run_wake(&dev->
sdev->sdev_gendev,
true);
1003 static void ata_acpi_remove_pm_notifier(
struct ata_device *dev)
1005 struct acpi_device *acpi_dev;
1017 if (dev->
sdev->can_power_off) {
1018 device_set_run_wake(&dev->
sdev->sdev_gendev,
false);
1024 static void ata_acpi_register_power_resource(
struct ata_device *dev)
1034 device = &sdev->sdev_gendev;
1039 static void ata_acpi_unregister_power_resource(
struct ata_device *dev)
1043 struct device *device;
1049 device = &sdev->sdev_gendev;
1056 ata_acpi_add_pm_notifier(dev);
1057 ata_acpi_register_power_resource(dev);
1062 ata_acpi_remove_pm_notifier(dev);
1063 ata_acpi_unregister_power_resource(dev);
1066 static int compat_pci_ata(
struct ata_port *ap)
1068 struct device *dev = ap->
tdev.parent;
1071 if (!is_pci_dev(dev))
1105 struct acpi_device *acpi_dev;
1106 struct acpi_device_power_state *states;
1109 if (!sata_pmp_attached(ap))
1110 ata_dev = &ap->
link.device[sdev->
id];
1115 ata_dev = &ap->
link.device[sdev->
id];
1132 states = acpi_dev->power.states;
1141 static int is_ata_port(
const struct device *dev)
1146 static struct ata_port *dev_to_ata_port(
struct device *dev)
1148 while (!is_ata_port(dev)) {
1156 static int ata_acpi_find_device(
struct device *dev,
acpi_handle *handle)
1158 struct ata_port *ap = dev_to_ata_port(dev);
1163 if (!compat_pci_ata(ap))
1167 return ata_acpi_bind_host(ap, handle);
1171 return ata_acpi_bind_device(ap, sdev, handle);
1176 static int ata_acpi_find_dummy(
struct device *dev,
acpi_handle *handle)
1182 .find_bridge = ata_acpi_find_dummy,
1183 .find_device = ata_acpi_find_device,
1188 return scsi_register_acpi_bus_type(&ata_acpi_bus);
1193 scsi_unregister_acpi_bus_type(&ata_acpi_bus);