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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Copyright (C) 1994-1998	    Linus Torvalds & authors (see below)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright (C) 2003-2005, 2007   Bartlomiej Zolnierkiewicz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Mostly written by Mark Lord  <mlord@pobox.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *                and Gadi Oxman <gadio@netvision.net.il>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *                and Andre Hedrick <andre@linux-ide.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  See linux/MAINTAINERS for address of current maintainer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * This is the multiple IDE interface driver, as evolved from hd.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *   (usually 14 & 15).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * There can be up to two drives per interface, as per the ATA-2 spec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *  From hd.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *  | It traverses the request-list, using interrupts to jump between functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *  | As nearly all functions can be called within interrupts, we may not sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *  | Special care is recommended.  Have Fun!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *  | modified by Drew Eckhardt to check nr of hd's from the CMOS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *  | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *  | in the early extended-partition checks and added DM partitions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *  | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *  | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *  | and general streamlining by Mark Lord (mlord@pobox.com).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *  October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *	Mark Lord	(mlord@pobox.com)		(IDE Perf.Pkg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *	Delman Lee	(delman@ieee.org)		("Mr. atdisk2")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *	Scott Snyder	(snyder@fnald0.fnal.gov)	(ATAPI IDE cd-rom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *  This was a rewrite of just about everything from hd.c, though some original
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *  code is still sprinkled about.  Think of it as a major evolution, with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *  inspiration from lots of linux users, esp.  hamish@zot.apana.org.au
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #include <linux/genhd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #include <linux/ide.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #include <linux/hdreg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) struct class *ide_port_class;
^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)  * ide_device_get	-	get an additional reference to a ide_drive_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * @drive:	device to get a reference to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * Gets a reference to the ide_drive_t and increments the use count of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * underlying LLDD module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) int ide_device_get(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct device *host_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct module *module;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (!get_device(&drive->gendev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	host_dev = drive->hwif->host->dev[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	module = host_dev ? host_dev->driver->owner : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (module && !try_module_get(module)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		put_device(&drive->gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) EXPORT_SYMBOL_GPL(ide_device_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * ide_device_put	-	release a reference to a ide_drive_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * @drive:	device to release a reference on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * Release a reference to the ide_drive_t and decrements the use count of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * the underlying LLDD module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) void ide_device_put(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #ifdef CONFIG_MODULE_UNLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct device *host_dev = drive->hwif->host->dev[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct module *module = host_dev ? host_dev->driver->owner : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	module_put(module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	put_device(&drive->gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) EXPORT_SYMBOL_GPL(ide_device_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int ide_bus_match(struct device *dev, struct device_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	ide_drive_t *drive = to_ide_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	add_uevent_var(env, "MEDIA=%s", ide_media_string(drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	add_uevent_var(env, "DRIVENAME=%s", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	add_uevent_var(env, "MODALIAS=ide:m-%s", ide_media_string(drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static int generic_ide_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	ide_drive_t *drive = to_ide_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct ide_driver *drv = to_ide_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return drv->probe ? drv->probe(drive) : -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int generic_ide_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	ide_drive_t *drive = to_ide_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct ide_driver *drv = to_ide_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (drv->remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		drv->remove(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static void generic_ide_shutdown(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	ide_drive_t *drive = to_ide_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct ide_driver *drv = to_ide_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (dev->driver && drv->shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		drv->shutdown(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct bus_type ide_bus_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	.name		= "ide",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	.match		= ide_bus_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	.uevent		= ide_uevent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	.probe		= generic_ide_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	.remove		= generic_ide_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	.shutdown	= generic_ide_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	.dev_groups	= ide_dev_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	.suspend	= generic_ide_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	.resume		= generic_ide_resume,
^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) EXPORT_SYMBOL_GPL(ide_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int ide_vlb_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) EXPORT_SYMBOL_GPL(ide_vlb_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) module_param_named(vlb_clock, ide_vlb_clk, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) MODULE_PARM_DESC(vlb_clock, "VLB clock frequency (in MHz)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int ide_pci_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) EXPORT_SYMBOL_GPL(ide_pci_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) module_param_named(pci_clock, ide_pci_clk, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static int ide_set_dev_param_mask(const char *s, const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	unsigned int a, b, i, j = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	unsigned int *dev_param_mask = (unsigned int *)kp->arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/* controller . device (0 or 1) [ : 1 (set) | 0 (clear) ] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (sscanf(s, "%u.%u:%u", &a, &b, &j) != 3 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	    sscanf(s, "%u.%u", &a, &b) != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	i = a * MAX_DRIVES + b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (i >= MAX_HWIFS * MAX_DRIVES || j > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		*dev_param_mask |= (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		*dev_param_mask &= ~(1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static const struct kernel_param_ops param_ops_ide_dev_mask = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	.set = ide_set_dev_param_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #define param_check_ide_dev_mask(name, p) param_check_uint(name, p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static unsigned int ide_nodma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) module_param_named(nodma, ide_nodma, ide_dev_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) MODULE_PARM_DESC(nodma, "disallow DMA for a device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static unsigned int ide_noflush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) module_param_named(noflush, ide_noflush, ide_dev_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) MODULE_PARM_DESC(noflush, "disable flush requests for a device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static unsigned int ide_nohpa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) module_param_named(nohpa, ide_nohpa, ide_dev_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) MODULE_PARM_DESC(nohpa, "disable Host Protected Area for a device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static unsigned int ide_noprobe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) module_param_named(noprobe, ide_noprobe, ide_dev_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) MODULE_PARM_DESC(noprobe, "skip probing for a device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static unsigned int ide_nowerr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) module_param_named(nowerr, ide_nowerr, ide_dev_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static unsigned int ide_cdroms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) module_param_named(cdrom, ide_cdroms, ide_dev_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) MODULE_PARM_DESC(cdrom, "force device as a CD-ROM");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct chs_geom {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	unsigned int	cyl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	u8		head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	u8		sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static unsigned int ide_disks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static struct chs_geom ide_disks_chs[MAX_HWIFS * MAX_DRIVES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static int ide_set_disk_chs(const char *str, const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	unsigned int a, b, c = 0, h = 0, s = 0, i, j = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	/* controller . device (0 or 1) : Cylinders , Heads , Sectors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	/* controller . device (0 or 1) : 1 (use CHS) | 0 (ignore CHS) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (sscanf(str, "%u.%u:%u,%u,%u", &a, &b, &c, &h, &s) != 5 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	    sscanf(str, "%u.%u:%u", &a, &b, &j) != 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	i = a * MAX_DRIVES + b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (i >= MAX_HWIFS * MAX_DRIVES || j > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (c > INT_MAX || h > 255 || s > 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		ide_disks |= (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		ide_disks &= ~(1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	ide_disks_chs[i].cyl  = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	ide_disks_chs[i].head = h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	ide_disks_chs[i].sect = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) MODULE_PARM_DESC(chs, "force device as a disk (using CHS)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static void ide_dev_apply_params(ide_drive_t *drive, u8 unit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	int i = drive->hwif->index * MAX_DRIVES + unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (ide_nodma & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		drive->dev_flags |= IDE_DFLAG_NODMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (ide_noflush & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		printk(KERN_INFO "ide: disabling flush requests for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 				 drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		drive->dev_flags |= IDE_DFLAG_NOFLUSH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (ide_nohpa & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		printk(KERN_INFO "ide: disabling Host Protected Area for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 				 drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		drive->dev_flags |= IDE_DFLAG_NOHPA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	if (ide_noprobe & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		drive->dev_flags |= IDE_DFLAG_NOPROBE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (ide_nowerr & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 				 drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		drive->bad_wstat = BAD_R_STAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (ide_cdroms & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		drive->dev_flags |= IDE_DFLAG_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		drive->media = ide_cdrom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		/* an ATAPI device ignores DRDY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		drive->ready_stat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	if (ide_disks & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		drive->cyl  = drive->bios_cyl  = ide_disks_chs[i].cyl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		drive->head = drive->bios_head = ide_disks_chs[i].head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 				 drive->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 				 drive->cyl, drive->head, drive->sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		drive->dev_flags |= IDE_DFLAG_FORCED_GEOM | IDE_DFLAG_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		drive->media = ide_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		drive->ready_stat = ATA_DRDY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static unsigned int ide_ignore_cable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static int ide_set_ignore_cable(const char *s, const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	int i, j = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	/* controller (ignore) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	/* controller : 1 (ignore) | 0 (use) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (sscanf(s, "%d:%d", &i, &j) != 2 && sscanf(s, "%d", &i) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (i >= MAX_HWIFS || j < 0 || j > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	if (j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		ide_ignore_cable |= (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		ide_ignore_cable &= ~(1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) module_param_call(ignore_cable, ide_set_ignore_cable, NULL, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) MODULE_PARM_DESC(ignore_cable, "ignore cable detection");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) void ide_port_apply_params(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (ide_ignore_cable & (1 << hwif->index)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		printk(KERN_INFO "ide: ignoring cable detection for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 				 hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		hwif->cbl = ATA_CBL_PATA40_SHORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	ide_port_for_each_dev(i, drive, hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		ide_dev_apply_params(drive, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  * This is gets invoked once during initialization, to set *everything* up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static int __init ide_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	ret = bus_register(&ide_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		return 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) 	ide_port_class = class_create(THIS_MODULE, "ide_port");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (IS_ERR(ide_port_class)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		ret = PTR_ERR(ide_port_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		goto out_port_class;
^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_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	proc_ide_create();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) out_port_class:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	bus_unregister(&ide_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static void __exit ide_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	proc_ide_destroy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	class_destroy(ide_port_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	bus_unregister(&ide_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) module_init(ide_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) module_exit(ide_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) MODULE_LICENSE("GPL");