Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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