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