diff options
Diffstat (limited to 'drivers/pnp')
| -rw-r--r-- | drivers/pnp/Makefile | 6 | ||||
| -rw-r--r-- | drivers/pnp/base.h | 6 | ||||
| -rw-r--r-- | drivers/pnp/card.c | 5 | ||||
| -rw-r--r-- | drivers/pnp/core.c | 7 | ||||
| -rw-r--r-- | drivers/pnp/driver.c | 53 | ||||
| -rw-r--r-- | drivers/pnp/interface.c | 148 | ||||
| -rw-r--r-- | drivers/pnp/isapnp/Makefile | 6 | ||||
| -rw-r--r-- | drivers/pnp/isapnp/core.c | 11 | ||||
| -rw-r--r-- | drivers/pnp/isapnp/proc.c | 29 | ||||
| -rw-r--r-- | drivers/pnp/manager.c | 46 | ||||
| -rw-r--r-- | drivers/pnp/pnpacpi/Makefile | 3 | ||||
| -rw-r--r-- | drivers/pnp/pnpacpi/core.c | 234 | ||||
| -rw-r--r-- | drivers/pnp/pnpacpi/pnpacpi.h | 1 | ||||
| -rw-r--r-- | drivers/pnp/pnpacpi/rsparser.c | 346 | ||||
| -rw-r--r-- | drivers/pnp/pnpbios/Kconfig | 4 | ||||
| -rw-r--r-- | drivers/pnp/pnpbios/Makefile | 5 | ||||
| -rw-r--r-- | drivers/pnp/pnpbios/bioscalls.c | 14 | ||||
| -rw-r--r-- | drivers/pnp/pnpbios/core.c | 42 | ||||
| -rw-r--r-- | drivers/pnp/pnpbios/proc.c | 9 | ||||
| -rw-r--r-- | drivers/pnp/pnpbios/rsparser.c | 12 | ||||
| -rw-r--r-- | drivers/pnp/quirks.c | 121 | ||||
| -rw-r--r-- | drivers/pnp/resource.c | 32 | 
22 files changed, 564 insertions, 576 deletions
diff --git a/drivers/pnp/Makefile b/drivers/pnp/Makefile index 8de3775ec24..bfba893cb32 100644 --- a/drivers/pnp/Makefile +++ b/drivers/pnp/Makefile @@ -2,11 +2,13 @@  # Makefile for the Linux Plug-and-Play Support.  # -obj-y		:= core.o card.o driver.o resource.o manager.o support.o interface.o quirks.o +obj-y		:= pnp.o + +pnp-y		:= core.o card.o driver.o resource.o manager.o support.o interface.o quirks.o  obj-$(CONFIG_PNPACPI)		+= pnpacpi/  obj-$(CONFIG_PNPBIOS)		+= pnpbios/  obj-$(CONFIG_ISAPNP)		+= isapnp/  # pnp_system_init goes after pnpacpi/pnpbios init -obj-y				+= system.o +pnp-y				+= system.o diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h index 19bc7369547..c8873b0ca55 100644 --- a/drivers/pnp/base.h +++ b/drivers/pnp/base.h @@ -4,7 +4,7 @@   */  extern spinlock_t pnp_lock; -extern struct device_attribute pnp_interface_attrs[]; +extern const struct attribute_group *pnp_dev_groups[];  void *pnp_alloc(long size);  int pnp_register_protocol(struct pnp_protocol *protocol); @@ -142,7 +142,9 @@ void __pnp_remove_device(struct pnp_dev *dev);  int pnp_check_port(struct pnp_dev *dev, struct resource *res);  int pnp_check_mem(struct pnp_dev *dev, struct resource *res);  int pnp_check_irq(struct pnp_dev *dev, struct resource *res); +#ifdef CONFIG_ISA_DMA_API  int pnp_check_dma(struct pnp_dev *dev, struct resource *res); +#endif  char *pnp_resource_type_name(struct resource *res);  void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc); @@ -157,6 +159,8 @@ struct pnp_resource {  void pnp_free_resource(struct pnp_resource *pnp_res); +struct pnp_resource *pnp_add_resource(struct pnp_dev *dev, +				      struct resource *res);  struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,  					  int flags);  struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma, diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c index 4a651f69e17..874c236ac1a 100644 --- a/drivers/pnp/card.c +++ b/drivers/pnp/card.c @@ -239,6 +239,7 @@ int pnp_add_card(struct pnp_card *card)  	error = device_register(&card->dev);  	if (error) {  		dev_err(&card->dev, "could not register (err=%d)\n", error); +		put_device(&card->dev);  		return error;  	} @@ -320,7 +321,7 @@ void pnp_remove_card_device(struct pnp_dev *dev)   * pnp_request_card_device - Searches for a PnP device under the specified card   * @clink: pointer to the card link, cannot be NULL   * @id: pointer to a PnP ID structure that explains the rules for finding the device - * @from: Starting place to search from. If NULL it will start from the begining. + * @from: Starting place to search from. If NULL it will start from the beginning.   */  struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,  					const char *id, struct pnp_dev *from) @@ -369,7 +370,7 @@ err_out:  /**   * pnp_release_card_device - call this when the driver no longer needs the device - * @dev: pointer to the PnP device stucture + * @dev: pointer to the PnP device structure   */  void pnp_release_card_device(struct pnp_dev *dev)  { diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c index 0f34d962fd3..cb6ce42f8e7 100644 --- a/drivers/pnp/core.c +++ b/drivers/pnp/core.c @@ -220,10 +220,5 @@ subsys_initcall(pnp_init);  int pnp_debug;  #if defined(CONFIG_PNP_DEBUG_MESSAGES) -static int __init pnp_debug_setup(char *__unused) -{ -	pnp_debug = 1; -	return 1; -} -__setup("pnp.debug", pnp_debug_setup); +module_param_named(debug, pnp_debug, int, 0644);  #endif diff --git a/drivers/pnp/driver.c b/drivers/pnp/driver.c index d1dbb9df53f..f748cc8cbb0 100644 --- a/drivers/pnp/driver.c +++ b/drivers/pnp/driver.c @@ -154,7 +154,7 @@ static int pnp_bus_match(struct device *dev, struct device_driver *drv)  	return 1;  } -static int pnp_bus_suspend(struct device *dev, pm_message_t state) +static int __pnp_bus_suspend(struct device *dev, pm_message_t state)  {  	struct pnp_dev *pnp_dev = to_pnp_dev(dev);  	struct pnp_driver *pnp_drv = pnp_dev->driver; @@ -163,6 +163,13 @@ static int pnp_bus_suspend(struct device *dev, pm_message_t state)  	if (!pnp_drv)  		return 0; +	if (pnp_drv->driver.pm && pnp_drv->driver.pm->suspend) { +		error = pnp_drv->driver.pm->suspend(dev); +		suspend_report_result(pnp_drv->driver.pm->suspend, error); +		if (error) +			return error; +	} +  	if (pnp_drv->suspend) {  		error = pnp_drv->suspend(pnp_dev, state);  		if (error) @@ -180,6 +187,21 @@ static int pnp_bus_suspend(struct device *dev, pm_message_t state)  	return 0;  } +static int pnp_bus_suspend(struct device *dev) +{ +	return __pnp_bus_suspend(dev, PMSG_SUSPEND); +} + +static int pnp_bus_freeze(struct device *dev) +{ +	return __pnp_bus_suspend(dev, PMSG_FREEZE); +} + +static int pnp_bus_poweroff(struct device *dev) +{ +	return __pnp_bus_suspend(dev, PMSG_HIBERNATE); +} +  static int pnp_bus_resume(struct device *dev)  {  	struct pnp_dev *pnp_dev = to_pnp_dev(dev); @@ -189,8 +211,11 @@ static int pnp_bus_resume(struct device *dev)  	if (!pnp_drv)  		return 0; -	if (pnp_dev->protocol->resume) -		pnp_dev->protocol->resume(pnp_dev); +	if (pnp_dev->protocol->resume) { +		error = pnp_dev->protocol->resume(pnp_dev); +		if (error) +			return error; +	}  	if (pnp_can_write(pnp_dev)) {  		error = pnp_start_dev(pnp_dev); @@ -198,6 +223,12 @@ static int pnp_bus_resume(struct device *dev)  			return error;  	} +	if (pnp_drv->driver.pm && pnp_drv->driver.pm->resume) { +		error = pnp_drv->driver.pm->resume(dev); +		if (error) +			return error; +	} +  	if (pnp_drv->resume) {  		error = pnp_drv->resume(pnp_dev);  		if (error) @@ -207,15 +238,25 @@ static int pnp_bus_resume(struct device *dev)  	return 0;  } +static const struct dev_pm_ops pnp_bus_dev_pm_ops = { +	/* Suspend callbacks */ +	.suspend = pnp_bus_suspend, +	.resume = pnp_bus_resume, +	/* Hibernate callbacks */ +	.freeze = pnp_bus_freeze, +	.thaw = pnp_bus_resume, +	.poweroff = pnp_bus_poweroff, +	.restore = pnp_bus_resume, +}; +  struct bus_type pnp_bus_type = {  	.name    = "pnp",  	.match   = pnp_bus_match,  	.probe   = pnp_device_probe,  	.remove  = pnp_device_remove,  	.shutdown = pnp_device_shutdown, -	.suspend = pnp_bus_suspend, -	.resume  = pnp_bus_resume, -	.dev_attrs = pnp_interface_attrs, +	.pm	 = &pnp_bus_dev_pm_ops, +	.dev_groups = pnp_dev_groups,  };  int pnp_register_driver(struct pnp_driver *drv) diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c index cfaf5b73540..e6c403be09a 100644 --- a/drivers/pnp/interface.c +++ b/drivers/pnp/interface.c @@ -203,8 +203,8 @@ static void pnp_print_option(pnp_info_buffer_t * buffer, char *space,  	}  } -static ssize_t pnp_show_options(struct device *dmdev, -				struct device_attribute *attr, char *buf) +static ssize_t options_show(struct device *dmdev, struct device_attribute *attr, +			    char *buf)  {  	struct pnp_dev *dev = to_pnp_dev(dmdev);  	pnp_info_buffer_t *buffer; @@ -241,10 +241,10 @@ static ssize_t pnp_show_options(struct device *dmdev,  	kfree(buffer);  	return ret;  } +static DEVICE_ATTR_RO(options); -static ssize_t pnp_show_current_resources(struct device *dmdev, -					  struct device_attribute *attr, -					  char *buf) +static ssize_t resources_show(struct device *dmdev, +			      struct device_attribute *attr, char *buf)  {  	struct pnp_dev *dev = to_pnp_dev(dmdev);  	pnp_info_buffer_t *buffer; @@ -298,14 +298,46 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,  	return ret;  } -static ssize_t pnp_set_current_resources(struct device *dmdev, -					 struct device_attribute *attr, -					 const char *ubuf, size_t count) +static char *pnp_get_resource_value(char *buf, +				    unsigned long type, +				    resource_size_t *start, +				    resource_size_t *end, +				    unsigned long *flags) +{ +	if (start) +		*start = 0; +	if (end) +		*end = 0; +	if (flags) +		*flags = 0; + +	/* TBD: allow for disabled resources */ + +	buf = skip_spaces(buf); +	if (start) { +		*start = simple_strtoull(buf, &buf, 0); +		if (end) { +			buf = skip_spaces(buf); +			if (*buf == '-') { +				buf = skip_spaces(buf + 1); +				*end = simple_strtoull(buf, &buf, 0); +			} else +				*end = *start; +		} +	} + +	/* TBD: allow for additional flags, e.g., IORESOURCE_WINDOW */ + +	return buf; +} + +static ssize_t resources_store(struct device *dmdev, +			       struct device_attribute *attr, const char *ubuf, +			       size_t count)  {  	struct pnp_dev *dev = to_pnp_dev(dmdev);  	char *buf = (void *)ubuf;  	int retval = 0; -	resource_size_t start, end;  	if (dev->status & PNP_ATTACHED) {  		retval = -EBUSY; @@ -349,6 +381,10 @@ static ssize_t pnp_set_current_resources(struct device *dmdev,  		goto done;  	}  	if (!strnicmp(buf, "set", 3)) { +		resource_size_t start; +		resource_size_t end; +		unsigned long flags; +  		if (dev->active)  			goto done;  		buf += 3; @@ -357,42 +393,37 @@ static ssize_t pnp_set_current_resources(struct device *dmdev,  		while (1) {  			buf = skip_spaces(buf);  			if (!strnicmp(buf, "io", 2)) { -				buf = skip_spaces(buf + 2); -				start = simple_strtoul(buf, &buf, 0); -				buf = skip_spaces(buf); -				if (*buf == '-') { -					buf = skip_spaces(buf + 1); -					end = simple_strtoul(buf, &buf, 0); -				} else -					end = start; -				pnp_add_io_resource(dev, start, end, 0); -				continue; -			} -			if (!strnicmp(buf, "mem", 3)) { -				buf = skip_spaces(buf + 3); -				start = simple_strtoul(buf, &buf, 0); -				buf = skip_spaces(buf); -				if (*buf == '-') { -					buf = skip_spaces(buf + 1); -					end = simple_strtoul(buf, &buf, 0); -				} else -					end = start; -				pnp_add_mem_resource(dev, start, end, 0); -				continue; -			} -			if (!strnicmp(buf, "irq", 3)) { -				buf = skip_spaces(buf + 3); -				start = simple_strtoul(buf, &buf, 0); -				pnp_add_irq_resource(dev, start, 0); -				continue; -			} -			if (!strnicmp(buf, "dma", 3)) { -				buf = skip_spaces(buf + 3); -				start = simple_strtoul(buf, &buf, 0); -				pnp_add_dma_resource(dev, start, 0); -				continue; -			} -			break; +				buf = pnp_get_resource_value(buf + 2, +							     IORESOURCE_IO, +							     &start, &end, +							     &flags); +				pnp_add_io_resource(dev, start, end, flags); +			} else if (!strnicmp(buf, "mem", 3)) { +				buf = pnp_get_resource_value(buf + 3, +							     IORESOURCE_MEM, +							     &start, &end, +							     &flags); +				pnp_add_mem_resource(dev, start, end, flags); +			} else if (!strnicmp(buf, "irq", 3)) { +				buf = pnp_get_resource_value(buf + 3, +							     IORESOURCE_IRQ, +							     &start, NULL, +							     &flags); +				pnp_add_irq_resource(dev, start, flags); +			} else if (!strnicmp(buf, "dma", 3)) { +				buf = pnp_get_resource_value(buf + 3, +							     IORESOURCE_DMA, +							     &start, NULL, +							     &flags); +				pnp_add_dma_resource(dev, start, flags); +			} else if (!strnicmp(buf, "bus", 3)) { +				buf = pnp_get_resource_value(buf + 3, +							     IORESOURCE_BUS, +							     &start, &end, +							     NULL); +				pnp_add_bus_resource(dev, start, end); +			} else +				break;  		}  		mutex_unlock(&pnp_res_mutex);  		goto done; @@ -403,9 +434,10 @@ done:  		return retval;  	return count;  } +static DEVICE_ATTR_RW(resources); -static ssize_t pnp_show_current_ids(struct device *dmdev, -				    struct device_attribute *attr, char *buf) +static ssize_t id_show(struct device *dmdev, struct device_attribute *attr, +		       char *buf)  {  	char *str = buf;  	struct pnp_dev *dev = to_pnp_dev(dmdev); @@ -417,12 +449,20 @@ static ssize_t pnp_show_current_ids(struct device *dmdev,  	}  	return (str - buf);  } +static DEVICE_ATTR_RO(id); + +static struct attribute *pnp_dev_attrs[] = { +	&dev_attr_resources.attr, +	&dev_attr_options.attr, +	&dev_attr_id.attr, +	NULL, +}; + +static const struct attribute_group pnp_dev_group = { +	.attrs = pnp_dev_attrs, +}; -struct device_attribute pnp_interface_attrs[] = { -	__ATTR(resources, S_IRUGO | S_IWUSR, -		   pnp_show_current_resources, -		   pnp_set_current_resources), -	__ATTR(options, S_IRUGO, pnp_show_options, NULL), -	__ATTR(id, S_IRUGO, pnp_show_current_ids, NULL), -	__ATTR_NULL, +const struct attribute_group *pnp_dev_groups[] = { +	&pnp_dev_group, +	NULL,  }; diff --git a/drivers/pnp/isapnp/Makefile b/drivers/pnp/isapnp/Makefile index cac18bbfb81..6e607aa33aa 100644 --- a/drivers/pnp/isapnp/Makefile +++ b/drivers/pnp/isapnp/Makefile @@ -1,7 +1,7 @@  #  # Makefile for the kernel ISAPNP driver.  # +obj-y			+= pnp.o +pnp-y			:= core.o compat.o -isapnp-proc-$(CONFIG_PROC_FS) = proc.o - -obj-y := core.o compat.o $(isapnp-proc-y) +pnp-$(CONFIG_PROC_FS)	+= proc.o diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c index 918d5f04486..cf88f9b6244 100644 --- a/drivers/pnp/isapnp/core.c +++ b/drivers/pnp/isapnp/core.c @@ -379,10 +379,6 @@ static int __init isapnp_read_tag(unsigned char *type, unsigned short *size)  		*type = (tag >> 3) & 0x0f;  		*size = tag & 0x07;  	} -#if 0 -	printk(KERN_DEBUG "tag = 0x%x, type = 0x%x, size = %i\n", tag, *type, -	       *size); -#endif  	if (*type == 0xff && *size == 0xffff)	/* probably invalid data */  		return -1;  	return 0; @@ -813,13 +809,6 @@ static int __init isapnp_build_device_list(void)  		if (!card)  			continue; -#if 0 -		dev_info(&card->dev, -		       "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", -		       header[0], header[1], header[2], header[3], header[4], -		       header[5], header[6], header[7], header[8]); -		dev_info(&card->dev, "checksum = %#x\n", checksum); -#endif  		INIT_LIST_HEAD(&card->devices);  		card->serial =  		    (header[7] << 24) | (header[6] << 16) | (header[5] << 8) | diff --git a/drivers/pnp/isapnp/proc.c b/drivers/pnp/isapnp/proc.c index e73ebefdf3e..5edee645d89 100644 --- a/drivers/pnp/isapnp/proc.c +++ b/drivers/pnp/isapnp/proc.c @@ -21,7 +21,6 @@  #include <linux/isapnp.h>  #include <linux/proc_fs.h>  #include <linux/init.h> -#include <linux/smp_lock.h>  #include <asm/uaccess.h>  extern struct pnp_protocol isapnp_protocol; @@ -30,35 +29,13 @@ static struct proc_dir_entry *isapnp_proc_bus_dir = NULL;  static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)  { -	loff_t new = -1; -	struct inode *inode = file->f_path.dentry->d_inode; - -	mutex_lock(&inode->i_mutex); -	switch (whence) { -	case 0: -		new = off; -		break; -	case 1: -		new = file->f_pos + off; -		break; -	case 2: -		new = 256 + off; -		break; -	} -	if (new < 0 || new > 256) -		new = -EINVAL; -	else -		file->f_pos = new; -	mutex_unlock(&inode->i_mutex); -	return new; +	return fixed_size_llseek(file, off, whence, 256);  }  static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf,  				    size_t nbytes, loff_t * ppos)  { -	struct inode *ino = file->f_path.dentry->d_inode; -	struct proc_dir_entry *dp = PDE(ino); -	struct pnp_dev *dev = dp->data; +	struct pnp_dev *dev = PDE_DATA(file_inode(file));  	int pos = *ppos;  	int cnt, size = 256; @@ -108,7 +85,7 @@ static int isapnp_proc_attach_device(struct pnp_dev *dev)  			&isapnp_proc_bus_file_operations, dev);  	if (!e)  		return -ENOMEM; -	e->size = 256; +	proc_set_size(e, 256);  	return 0;  } diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c index 0a15664eef1..9357aa77904 100644 --- a/drivers/pnp/manager.c +++ b/drivers/pnp/manager.c @@ -18,11 +18,27 @@  DEFINE_MUTEX(pnp_res_mutex); +static struct resource *pnp_find_resource(struct pnp_dev *dev, +					  unsigned char rule, +					  unsigned long type, +					  unsigned int bar) +{ +	struct resource *res = pnp_get_resource(dev, type, bar); + +	/* when the resource already exists, set its resource bits from rule */ +	if (res) { +		res->flags &= ~IORESOURCE_BITS; +		res->flags |= rule & IORESOURCE_BITS; +	} + +	return res; +} +  static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)  {  	struct resource *res, local_res; -	res = pnp_get_resource(dev, IORESOURCE_IO, idx); +	res = pnp_find_resource(dev, rule->flags, IORESOURCE_IO, idx);  	if (res) {  		pnp_dbg(&dev->dev, "  io %d already set to %#llx-%#llx "  			"flags %#lx\n", idx, (unsigned long long) res->start, @@ -65,7 +81,7 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)  {  	struct resource *res, local_res; -	res = pnp_get_resource(dev, IORESOURCE_MEM, idx); +	res = pnp_find_resource(dev, rule->flags, IORESOURCE_MEM, idx);  	if (res) {  		pnp_dbg(&dev->dev, "  mem %d already set to %#llx-%#llx "  			"flags %#lx\n", idx, (unsigned long long) res->start, @@ -78,6 +94,7 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)  	res->start = 0;  	res->end = 0; +	/* ??? rule->flags restricted to 8 bits, all tests bogus ??? */  	if (!(rule->flags & IORESOURCE_MEM_WRITEABLE))  		res->flags |= IORESOURCE_READONLY;  	if (rule->flags & IORESOURCE_MEM_CACHEABLE) @@ -123,7 +140,7 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)  		5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2  	}; -	res = pnp_get_resource(dev, IORESOURCE_IRQ, idx); +	res = pnp_find_resource(dev, rule->flags, IORESOURCE_IRQ, idx);  	if (res) {  		pnp_dbg(&dev->dev, "  irq %d already set to %d flags %#lx\n",  			idx, (int) res->start, res->flags); @@ -171,6 +188,7 @@ __add:  	return 0;  } +#ifdef CONFIG_ISA_DMA_API  static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)  {  	struct resource *res, local_res; @@ -181,7 +199,7 @@ static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)  		1, 3, 5, 6, 7, 0, 2, 4  	}; -	res = pnp_get_resource(dev, IORESOURCE_DMA, idx); +	res = pnp_find_resource(dev, rule->flags, IORESOURCE_DMA, idx);  	if (res) {  		pnp_dbg(&dev->dev, "  dma %d already set to %d flags %#lx\n",  			idx, (int) res->start, res->flags); @@ -193,6 +211,12 @@ static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)  	res->start = -1;  	res->end = -1; +	if (!rule->map) { +		res->flags |= IORESOURCE_DISABLED; +		pnp_dbg(&dev->dev, "  dma %d disabled\n", idx); +		goto __add; +	} +  	for (i = 0; i < 8; i++) {  		if (rule->map & (1 << xtab[i])) {  			res->start = res->end = xtab[i]; @@ -200,16 +224,15 @@ static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)  				goto __add;  		}  	} -#ifdef MAX_DMA_CHANNELS -	res->start = res->end = MAX_DMA_CHANNELS; -#endif -	res->flags |= IORESOURCE_DISABLED; -	pnp_dbg(&dev->dev, "  disable dma %d\n", idx); + +	pnp_dbg(&dev->dev, "  couldn't assign dma %d\n", idx); +	return -EBUSY;  __add:  	pnp_add_dma_resource(dev, res->start, res->flags);  	return 0;  } +#endif /* CONFIG_ISA_DMA_API */  void pnp_init_resources(struct pnp_dev *dev)  { @@ -234,7 +257,8 @@ static void pnp_clean_resource_table(struct pnp_dev *dev)  static int pnp_assign_resources(struct pnp_dev *dev, int set)  {  	struct pnp_option *option; -	int nport = 0, nmem = 0, nirq = 0, ndma = 0; +	int nport = 0, nmem = 0, nirq = 0; +	int ndma __maybe_unused = 0;  	int ret = 0;  	pnp_dbg(&dev->dev, "pnp_assign_resources, try dependent set %d\n", set); @@ -256,9 +280,11 @@ static int pnp_assign_resources(struct pnp_dev *dev, int set)  		case IORESOURCE_IRQ:  			ret = pnp_assign_irq(dev, &option->u.irq, nirq++);  			break; +#ifdef CONFIG_ISA_DMA_API  		case IORESOURCE_DMA:  			ret = pnp_assign_dma(dev, &option->u.dma, ndma++);  			break; +#endif  		default:  			ret = -EINVAL;  			break; diff --git a/drivers/pnp/pnpacpi/Makefile b/drivers/pnp/pnpacpi/Makefile index 905326fcca8..40c93da1825 100644 --- a/drivers/pnp/pnpacpi/Makefile +++ b/drivers/pnp/pnpacpi/Makefile @@ -1,5 +1,6 @@  #  # Makefile for the kernel PNPACPI driver.  # +obj-y += pnp.o -obj-y := core.o rsparser.o +pnp-y := core.o rsparser.o diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c index 2d73dfcecdb..a5c6cb773e5 100644 --- a/drivers/pnp/pnpacpi/core.c +++ b/drivers/pnp/pnpacpi/core.c @@ -19,37 +19,17 @@   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   */ +#include <linux/export.h>  #include <linux/acpi.h>  #include <linux/pnp.h>  #include <linux/slab.h>  #include <linux/mod_devicetable.h> -#include <acpi/acpi_bus.h>  #include "../base.h"  #include "pnpacpi.h"  static int num; -/* We need only to blacklist devices that have already an acpi driver that - * can't use pnp layer. We don't need to blacklist device that are directly - * used by the kernel (PCI root, ...), as it is harmless and there were - * already present in pnpbios. But there is an exception for devices that - * have irqs (PIC, Timer) because we call acpi_register_gsi. - * Finally, only devices that have a CRS method need to be in this list. - */ -static struct acpi_device_id excluded_id_list[] __initdata = { -	{"PNP0C09", 0},		/* EC */ -	{"PNP0C0F", 0},		/* Link device */ -	{"PNP0000", 0},		/* PIC */ -	{"PNP0100", 0},		/* Timer */ -	{"", 0}, -}; - -static inline int __init is_exclusive_device(struct acpi_device *dev) -{ -	return (!acpi_match_device_ids(dev, excluded_id_list)); -} -  /*   * Compatible Device IDs   */ @@ -57,7 +37,7 @@ static inline int __init is_exclusive_device(struct acpi_device *dev)  	if (!(('0' <= (c) && (c) <= '9') || ('A' <= (c) && (c) <= 'F'))) \  		return 0  #define TEST_ALPHA(c) \ -	if (!('@' <= (c) || (c) <= 'Z')) \ +	if (!('A' <= (c) && (c) <= 'Z')) \  		return 0  static int __init ispnpidacpi(const char *id)  { @@ -81,89 +61,141 @@ static int pnpacpi_get_resources(struct pnp_dev *dev)  static int pnpacpi_set_resources(struct pnp_dev *dev)  { -	struct acpi_device *acpi_dev = dev->data; -	acpi_handle handle = acpi_dev->handle; -	struct acpi_buffer buffer; -	int ret; +	struct acpi_device *acpi_dev; +	acpi_handle handle; +	int ret = 0;  	pnp_dbg(&dev->dev, "set resources\n"); -	ret = pnpacpi_build_resource_template(dev, &buffer); -	if (ret) -		return ret; -	ret = pnpacpi_encode_resources(dev, &buffer); -	if (ret) { + +	handle = ACPI_HANDLE(&dev->dev); +	if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { +		dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); +		return -ENODEV; +	} + +	if (WARN_ON_ONCE(acpi_dev != dev->data)) +		dev->data = acpi_dev; + +	if (acpi_has_method(handle, METHOD_NAME__SRS)) { +		struct acpi_buffer buffer; + +		ret = pnpacpi_build_resource_template(dev, &buffer); +		if (ret) +			return ret; + +		ret = pnpacpi_encode_resources(dev, &buffer); +		if (!ret) { +			acpi_status status; + +			status = acpi_set_current_resources(handle, &buffer); +			if (ACPI_FAILURE(status)) +				ret = -EIO; +		}  		kfree(buffer.pointer); -		return ret;  	} -	if (ACPI_FAILURE(acpi_set_current_resources(handle, &buffer))) -		ret = -EINVAL; -	else if (acpi_bus_power_manageable(handle)) +	if (!ret && acpi_bus_power_manageable(handle))  		ret = acpi_bus_set_power(handle, ACPI_STATE_D0); -	kfree(buffer.pointer); +  	return ret;  }  static int pnpacpi_disable_resources(struct pnp_dev *dev)  { -	struct acpi_device *acpi_dev = dev->data; -	acpi_handle handle = acpi_dev->handle; -	int ret; +	struct acpi_device *acpi_dev; +	acpi_handle handle; +	acpi_status status;  	dev_dbg(&dev->dev, "disable resources\n"); +	handle = ACPI_HANDLE(&dev->dev); +	if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { +		dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); +		return 0; +	} +  	/* acpi_unregister_gsi(pnp_irq(dev, 0)); */ -	ret = 0;  	if (acpi_bus_power_manageable(handle)) -		acpi_bus_set_power(handle, ACPI_STATE_D3); -		/* continue even if acpi_bus_set_power() fails */ -	if (ACPI_FAILURE(acpi_evaluate_object(handle, "_DIS", NULL, NULL))) -		ret = -ENODEV; -	return ret; +		acpi_bus_set_power(handle, ACPI_STATE_D3_COLD); + +	/* continue even if acpi_bus_set_power() fails */ +	status = acpi_evaluate_object(handle, "_DIS", NULL, NULL); +	if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) +		return -ENODEV; + +	return 0;  }  #ifdef CONFIG_ACPI_SLEEP  static bool pnpacpi_can_wakeup(struct pnp_dev *dev)  { -	struct acpi_device *acpi_dev = dev->data; -	acpi_handle handle = acpi_dev->handle; +	struct acpi_device *acpi_dev; +	acpi_handle handle; + +	handle = ACPI_HANDLE(&dev->dev); +	if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { +		dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); +		return false; +	}  	return acpi_bus_can_wakeup(handle);  }  static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state)  { -	struct acpi_device *acpi_dev = dev->data; -	acpi_handle handle = acpi_dev->handle; -	int power_state; +	struct acpi_device *acpi_dev; +	acpi_handle handle; +	int error = 0; + +	handle = ACPI_HANDLE(&dev->dev); +	if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { +		dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); +		return 0; +	}  	if (device_can_wakeup(&dev->dev)) { -		int rc = acpi_pm_device_sleep_wake(&dev->dev, +		error = acpi_pm_device_sleep_wake(&dev->dev,  				device_may_wakeup(&dev->dev)); +		if (error) +			return error; +	} -		if (rc) -			return rc; +	if (acpi_bus_power_manageable(handle)) { +		int power_state = acpi_pm_device_sleep_state(&dev->dev, NULL, +							ACPI_STATE_D3_COLD); +		if (power_state < 0) +			power_state = (state.event == PM_EVENT_ON) ? +					ACPI_STATE_D0 : ACPI_STATE_D3_COLD; + +		/* +		 * acpi_bus_set_power() often fails (keyboard port can't be +		 * powered-down?), and in any case, our return value is ignored +		 * by pnp_bus_suspend().  Hence we don't revert the wakeup +		 * setting if the set_power fails. +		 */ +		error = acpi_bus_set_power(handle, power_state);  	} -	power_state = acpi_pm_device_sleep_state(&dev->dev, NULL); -	if (power_state < 0) -		power_state = (state.event == PM_EVENT_ON) ? -				ACPI_STATE_D0 : ACPI_STATE_D3; - -	/* acpi_bus_set_power() often fails (keyboard port can't be -	 * powered-down?), and in any case, our return value is ignored -	 * by pnp_bus_suspend().  Hence we don't revert the wakeup -	 * setting if the set_power fails. -	 */ -	return acpi_bus_set_power(handle, power_state); + +	return error;  }  static int pnpacpi_resume(struct pnp_dev *dev)  { -	struct acpi_device *acpi_dev = dev->data; -	acpi_handle handle = acpi_dev->handle; +	struct acpi_device *acpi_dev; +	acpi_handle handle = ACPI_HANDLE(&dev->dev); +	int error = 0; + +	if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { +		dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); +		return -ENODEV; +	}  	if (device_may_wakeup(&dev->dev))  		acpi_pm_device_sleep_wake(&dev->dev, false); -	return acpi_bus_set_power(handle, ACPI_STATE_D0); + +	if (acpi_bus_power_manageable(handle)) +		error = acpi_bus_set_power(handle, ACPI_STATE_D0); + +	return error;  }  #endif @@ -180,7 +212,7 @@ struct pnp_protocol pnpacpi_protocol = {  };  EXPORT_SYMBOL(pnpacpi_protocol); -static char *pnpacpi_get_id(struct acpi_device *device) +static char *__init pnpacpi_get_id(struct acpi_device *device)  {  	struct acpi_hardware_id *id; @@ -194,25 +226,27 @@ static char *pnpacpi_get_id(struct acpi_device *device)  static int __init pnpacpi_add_device(struct acpi_device *device)  { -	acpi_handle temp = NULL; -	acpi_status status;  	struct pnp_dev *dev;  	char *pnpid;  	struct acpi_hardware_id *id; +	int error; + +	/* Skip devices that are already bound */ +	if (device->physical_node_count) +		return 0;  	/*  	 * If a PnPacpi device is not present , the device  	 * driver should not be loaded.  	 */ -	status = acpi_get_handle(device->handle, "_CRS", &temp); -	if (ACPI_FAILURE(status)) +	if (!acpi_has_method(device->handle, "_CRS"))  		return 0;  	pnpid = pnpacpi_get_id(device);  	if (!pnpid)  		return 0; -	if (is_exclusive_device(device) || !device->status.present) +	if (!device->status.present)  		return 0;  	dev = pnp_alloc_dev(&pnpacpi_protocol, num, pnpid); @@ -222,16 +256,14 @@ static int __init pnpacpi_add_device(struct acpi_device *device)  	dev->data = device;  	/* .enabled means the device can decode the resources */  	dev->active = device->status.enabled; -	status = acpi_get_handle(device->handle, "_SRS", &temp); -	if (ACPI_SUCCESS(status)) +	if (acpi_has_method(device->handle, "_SRS"))  		dev->capabilities |= PNP_CONFIGURABLE;  	dev->capabilities |= PNP_READ;  	if (device->flags.dynamic_status && (dev->capabilities & PNP_CONFIGURABLE))  		dev->capabilities |= PNP_WRITE;  	if (device->flags.removable)  		dev->capabilities |= PNP_REMOVABLE; -	status = acpi_get_handle(device->handle, "_DIS", &temp); -	if (ACPI_SUCCESS(status)) +	if (acpi_has_method(device->handle, "_DIS"))  		dev->capabilities |= PNP_DISABLE;  	if (strlen(acpi_device_name(device))) @@ -256,10 +288,16 @@ static int __init pnpacpi_add_device(struct acpi_device *device)  	/* clear out the damaged flags */  	if (!dev->active)  		pnp_init_resources(dev); -	pnp_add_device(dev); + +	error = pnp_add_device(dev); +	if (error) { +		put_device(&dev->dev); +		return error; +	} +  	num++; -	return AE_OK; +	return 0;  }  static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle, @@ -268,10 +306,10 @@ static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,  {  	struct acpi_device *device; -	if (!acpi_bus_get_device(handle, &device)) -		pnpacpi_add_device(device); -	else +	if (acpi_bus_get_device(handle, &device))  		return AE_CTRL_DEPTH; +	if (acpi_is_pnp_device(device)) +		pnpacpi_add_device(device);  	return AE_OK;  } @@ -281,32 +319,32 @@ static int __init acpi_pnp_match(struct device *dev, void *_pnp)  	struct pnp_dev *pnp = _pnp;  	/* true means it matched */ -	return !acpi_get_physical_device(acpi->handle) -	    && compare_pnp_id(pnp->id, acpi_device_hid(acpi)); +	return pnp->data == acpi;  } -static int __init acpi_pnp_find_device(struct device *dev, acpi_handle * handle) +static struct acpi_device * __init acpi_pnp_find_companion(struct device *dev)  { -	struct device *adev; -	struct acpi_device *acpi; - -	adev = bus_find_device(&acpi_bus_type, NULL, -			       to_pnp_dev(dev), acpi_pnp_match); -	if (!adev) -		return -ENODEV; +	dev = bus_find_device(&acpi_bus_type, NULL, to_pnp_dev(dev), +			      acpi_pnp_match); +	if (!dev) +		return NULL; -	acpi = to_acpi_device(adev); -	*handle = acpi->handle; -	put_device(adev); -	return 0; +	put_device(dev); +	return to_acpi_device(dev);  }  /* complete initialization of a PNPACPI device includes having   * pnpdev->dev.archdata.acpi_handle point to its ACPI sibling.   */ +static bool acpi_pnp_bus_match(struct device *dev) +{ +	return dev->bus == &pnp_bus_type; +} +  static struct acpi_bus_type __initdata acpi_pnp_bus = { -	.bus	     = &pnp_bus_type, -	.find_device = acpi_pnp_find_device, +	.name	     = "PNP", +	.match	     = acpi_pnp_bus_match, +	.find_companion = acpi_pnp_find_companion,  };  int pnpacpi_disabled __initdata; diff --git a/drivers/pnp/pnpacpi/pnpacpi.h b/drivers/pnp/pnpacpi/pnpacpi.h index 3e60225b022..051ef969977 100644 --- a/drivers/pnp/pnpacpi/pnpacpi.h +++ b/drivers/pnp/pnpacpi/pnpacpi.h @@ -1,7 +1,6 @@  #ifndef ACPI_PNP_H  #define ACPI_PNP_H -#include <acpi/acpi_bus.h>  #include <linux/acpi.h>  #include <linux/pnp.h> diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c index 100e4d9372f..66977ebf13b 100644 --- a/drivers/pnp/pnpacpi/rsparser.c +++ b/drivers/pnp/pnpacpi/rsparser.c @@ -28,37 +28,6 @@  #include "../base.h"  #include "pnpacpi.h" -#ifdef CONFIG_IA64 -#define valid_IRQ(i) (1) -#else -#define valid_IRQ(i) (((i) != 0) && ((i) != 2)) -#endif - -/* - * Allocated Resources - */ -static int irq_flags(int triggering, int polarity, int shareable) -{ -	int flags; - -	if (triggering == ACPI_LEVEL_SENSITIVE) { -		if (polarity == ACPI_ACTIVE_LOW) -			flags = IORESOURCE_IRQ_LOWLEVEL; -		else -			flags = IORESOURCE_IRQ_HIGHLEVEL; -	} else { -		if (polarity == ACPI_ACTIVE_LOW) -			flags = IORESOURCE_IRQ_LOWEDGE; -		else -			flags = IORESOURCE_IRQ_HIGHEDGE; -	} - -	if (shareable == ACPI_SHARED) -		flags |= IORESOURCE_IRQ_SHAREABLE; - -	return flags; -} -  static void decode_irq_flags(struct pnp_dev *dev, int flags, int *triggering,  			     int *polarity, int *shareable)  { @@ -94,45 +63,6 @@ static void decode_irq_flags(struct pnp_dev *dev, int flags, int *triggering,  		*shareable = ACPI_EXCLUSIVE;  } -static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev, -						u32 gsi, int triggering, -						int polarity, int shareable) -{ -	int irq, flags; -	int p, t; - -	if (!valid_IRQ(gsi)) { -		pnp_add_irq_resource(dev, gsi, IORESOURCE_DISABLED); -		return; -	} - -	/* -	 * in IO-APIC mode, use overrided attribute. Two reasons: -	 * 1. BIOS bug in DSDT -	 * 2. BIOS uses IO-APIC mode Interrupt Source Override -	 */ -	if (!acpi_get_override_irq(gsi, &t, &p)) { -		t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE; -		p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH; - -		if (triggering != t || polarity != p) { -			dev_warn(&dev->dev, "IRQ %d override to %s, %s\n", -				gsi, t ? "edge":"level", p ? "low":"high"); -			triggering = t; -			polarity = p; -		} -	} - -	flags = irq_flags(triggering, polarity, shareable); -	irq = acpi_register_gsi(&dev->dev, gsi, triggering, polarity); -	if (irq >= 0) -		pcibios_penalize_isa_irq(irq, 1); -	else -		flags |= IORESOURCE_DISABLED; - -	pnp_add_irq_resource(dev, irq, flags); -} -  static int dma_flags(struct pnp_dev *dev, int type, int bus_master,  		     int transfer)  { @@ -177,21 +107,16 @@ static int dma_flags(struct pnp_dev *dev, int type, int bus_master,  	return flags;  } -static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start, -					       u64 len, int io_decode, -					       int window) -{ -	int flags = 0; -	u64 end = start + len - 1; +/* + * Allocated Resources + */ -	if (io_decode == ACPI_DECODE_16) -		flags |= IORESOURCE_IO_16BIT_ADDR; -	if (len == 0 || end >= 0x10003) -		flags |= IORESOURCE_DISABLED; -	if (window) -		flags |= IORESOURCE_WINDOW; +static void pnpacpi_add_irqresource(struct pnp_dev *dev, struct resource *r) +{ +	if (!(r->flags & IORESOURCE_DISABLED)) +		pcibios_penalize_isa_irq(r->start, 1); -	pnp_add_io_resource(dev, start, end, flags); +	pnp_add_resource(dev, r);  }  /* @@ -249,130 +174,58 @@ static void pnpacpi_parse_allocated_vendor(struct pnp_dev *dev,  	}  } -static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev, -						u64 start, u64 len, -						int write_protect, int window) -{ -	int flags = 0; -	u64 end = start + len - 1; - -	if (len == 0) -		flags |= IORESOURCE_DISABLED; -	if (write_protect == ACPI_READ_WRITE_MEMORY) -		flags |= IORESOURCE_MEM_WRITEABLE; -	if (window) -		flags |= IORESOURCE_WINDOW; - -	pnp_add_mem_resource(dev, start, end, flags); -} - -static void pnpacpi_parse_allocated_busresource(struct pnp_dev *dev, -						u64 start, u64 len) -{ -	u64 end = start + len - 1; - -	pnp_add_bus_resource(dev, start, end); -} - -static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev, -						  struct acpi_resource *res) -{ -	struct acpi_resource_address64 addr, *p = &addr; -	acpi_status status; -	int window; -	u64 len; - -	status = acpi_resource_to_address64(res, p); -	if (!ACPI_SUCCESS(status)) { -		dev_warn(&dev->dev, "failed to convert resource type %d\n", -			 res->type); -		return; -	} - -	/* Windows apparently computes length rather than using _LEN */ -	len = p->maximum - p->minimum + 1; -	window = (p->producer_consumer == ACPI_PRODUCER) ? 1 : 0; - -	if (p->resource_type == ACPI_MEMORY_RANGE) -		pnpacpi_parse_allocated_memresource(dev, p->minimum, len, -			p->info.mem.write_protect, window); -	else if (p->resource_type == ACPI_IO_RANGE) -		pnpacpi_parse_allocated_ioresource(dev, p->minimum, len, -			p->granularity == 0xfff ? ACPI_DECODE_10 : -				ACPI_DECODE_16, window); -	else if (p->resource_type == ACPI_BUS_NUMBER_RANGE) -		pnpacpi_parse_allocated_busresource(dev, p->minimum, len); -} - -static void pnpacpi_parse_allocated_ext_address_space(struct pnp_dev *dev, -						      struct acpi_resource *res) -{ -	struct acpi_resource_extended_address64 *p = &res->data.ext_address64; -	int window; -	u64 len; - -	/* Windows apparently computes length rather than using _LEN */ -	len = p->maximum - p->minimum + 1; -	window = (p->producer_consumer == ACPI_PRODUCER) ? 1 : 0; - -	if (p->resource_type == ACPI_MEMORY_RANGE) -		pnpacpi_parse_allocated_memresource(dev, p->minimum, len, -			p->info.mem.write_protect, window); -	else if (p->resource_type == ACPI_IO_RANGE) -		pnpacpi_parse_allocated_ioresource(dev, p->minimum, len, -			p->granularity == 0xfff ? ACPI_DECODE_10 : -				ACPI_DECODE_16, window); -	else if (p->resource_type == ACPI_BUS_NUMBER_RANGE) -		pnpacpi_parse_allocated_busresource(dev, p->minimum, len); -} -  static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,  					      void *data)  {  	struct pnp_dev *dev = data; -	struct acpi_resource_irq *irq;  	struct acpi_resource_dma *dma; -	struct acpi_resource_io *io; -	struct acpi_resource_fixed_io *fixed_io;  	struct acpi_resource_vendor_typed *vendor_typed; -	struct acpi_resource_memory24 *memory24; -	struct acpi_resource_memory32 *memory32; -	struct acpi_resource_fixed_memory32 *fixed_memory32; -	struct acpi_resource_extended_irq *extended_irq; +	struct resource r = {0};  	int i, flags; -	switch (res->type) { -	case ACPI_RESOURCE_TYPE_IRQ: -		/* -		 * Per spec, only one interrupt per descriptor is allowed in -		 * _CRS, but some firmware violates this, so parse them all. -		 */ -		irq = &res->data.irq; -		if (irq->interrupt_count == 0) -			pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED); -		else { -			for (i = 0; i < irq->interrupt_count; i++) { -				pnpacpi_parse_allocated_irqresource(dev, -					irq->interrupts[i], -					irq->triggering, -					irq->polarity, -				    irq->sharable); -			} +	if (acpi_dev_resource_address_space(res, &r) +	    || acpi_dev_resource_ext_address_space(res, &r)) { +		pnp_add_resource(dev, &r); +		return AE_OK; +	} +	r.flags = 0; +	if (acpi_dev_resource_interrupt(res, 0, &r)) { +		pnpacpi_add_irqresource(dev, &r); +		for (i = 1; acpi_dev_resource_interrupt(res, i, &r); i++) +			pnpacpi_add_irqresource(dev, &r); + +		if (i > 1) {  			/*  			 * The IRQ encoder puts a single interrupt in each  			 * descriptor, so if a _CRS descriptor has more than  			 * one interrupt, we won't be able to re-encode it.  			 */ -			if (pnp_can_write(dev) && irq->interrupt_count > 1) { +			if (pnp_can_write(dev)) {  				dev_warn(&dev->dev, "multiple interrupts in "  					 "_CRS descriptor; configuration can't "  					 "be changed\n");  				dev->capabilities &= ~PNP_WRITE;  			}  		} -		break; +		return AE_OK; +	} else if (r.flags & IORESOURCE_DISABLED) { +		pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED); +		return AE_OK; +	} +	switch (res->type) { +	case ACPI_RESOURCE_TYPE_MEMORY24: +	case ACPI_RESOURCE_TYPE_MEMORY32: +	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: +		if (acpi_dev_resource_memory(res, &r)) +			pnp_add_resource(dev, &r); +		break; +	case ACPI_RESOURCE_TYPE_IO: +	case ACPI_RESOURCE_TYPE_FIXED_IO: +		if (acpi_dev_resource_io(res, &r)) +			pnp_add_resource(dev, &r); +		break;  	case ACPI_RESOURCE_TYPE_DMA:  		dma = &res->data.dma;  		if (dma->channel_count > 0 && dma->channels[0] != (u8) -1) @@ -383,26 +236,10 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,  		pnp_add_dma_resource(dev, dma->channels[0], flags);  		break; -	case ACPI_RESOURCE_TYPE_IO: -		io = &res->data.io; -		pnpacpi_parse_allocated_ioresource(dev, -			io->minimum, -			io->address_length, -			io->io_decode, 0); -		break; -  	case ACPI_RESOURCE_TYPE_START_DEPENDENT:  	case ACPI_RESOURCE_TYPE_END_DEPENDENT:  		break; -	case ACPI_RESOURCE_TYPE_FIXED_IO: -		fixed_io = &res->data.fixed_io; -		pnpacpi_parse_allocated_ioresource(dev, -			fixed_io->address, -			fixed_io->address_length, -			ACPI_DECODE_10, 0); -		break; -  	case ACPI_RESOURCE_TYPE_VENDOR:  		vendor_typed = &res->data.vendor_typed;  		pnpacpi_parse_allocated_vendor(dev, vendor_typed); @@ -411,66 +248,6 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,  	case ACPI_RESOURCE_TYPE_END_TAG:  		break; -	case ACPI_RESOURCE_TYPE_MEMORY24: -		memory24 = &res->data.memory24; -		pnpacpi_parse_allocated_memresource(dev, -			memory24->minimum, -			memory24->address_length, -			memory24->write_protect, 0); -		break; -	case ACPI_RESOURCE_TYPE_MEMORY32: -		memory32 = &res->data.memory32; -		pnpacpi_parse_allocated_memresource(dev, -			memory32->minimum, -			memory32->address_length, -			memory32->write_protect, 0); -		break; -	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: -		fixed_memory32 = &res->data.fixed_memory32; -		pnpacpi_parse_allocated_memresource(dev, -			fixed_memory32->address, -			fixed_memory32->address_length, -			fixed_memory32->write_protect, 0); -		break; -	case ACPI_RESOURCE_TYPE_ADDRESS16: -	case ACPI_RESOURCE_TYPE_ADDRESS32: -	case ACPI_RESOURCE_TYPE_ADDRESS64: -		pnpacpi_parse_allocated_address_space(dev, res); -		break; - -	case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: -		pnpacpi_parse_allocated_ext_address_space(dev, res); -		break; - -	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: -		extended_irq = &res->data.extended_irq; - -		if (extended_irq->interrupt_count == 0) -			pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED); -		else { -			for (i = 0; i < extended_irq->interrupt_count; i++) { -				pnpacpi_parse_allocated_irqresource(dev, -					extended_irq->interrupts[i], -					extended_irq->triggering, -					extended_irq->polarity, -					extended_irq->sharable); -			} - -			/* -			 * The IRQ encoder puts a single interrupt in each -			 * descriptor, so if a _CRS descriptor has more than -			 * one interrupt, we won't be able to re-encode it. -			 */ -			if (pnp_can_write(dev) && -			    extended_irq->interrupt_count > 1) { -				dev_warn(&dev->dev, "multiple interrupts in " -					 "_CRS descriptor; configuration can't " -					 "be changed\n"); -				dev->capabilities &= ~PNP_WRITE; -			} -		} -		break; -  	case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:  		break; @@ -511,9 +288,6 @@ static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev,  	int i;  	unsigned char map = 0, flags; -	if (p->channel_count == 0) -		return; -  	for (i = 0; i < p->channel_count; i++)  		map |= 1 << p->channels[i]; @@ -529,15 +303,12 @@ static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev,  	pnp_irq_mask_t map;  	unsigned char flags; -	if (p->interrupt_count == 0) -		return; -  	bitmap_zero(map.bits, PNP_IRQ_NR);  	for (i = 0; i < p->interrupt_count; i++)  		if (p->interrupts[i])  			__set_bit(p->interrupts[i], map.bits); -	flags = irq_flags(p->triggering, p->polarity, p->sharable); +	flags = acpi_dev_irq_flags(p->triggering, p->polarity, p->sharable);  	pnp_register_irq_resource(dev, option_flags, &map, flags);  } @@ -549,9 +320,6 @@ static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev,  	pnp_irq_mask_t map;  	unsigned char flags; -	if (p->interrupt_count == 0) -		return; -  	bitmap_zero(map.bits, PNP_IRQ_NR);  	for (i = 0; i < p->interrupt_count; i++) {  		if (p->interrupts[i]) { @@ -564,7 +332,7 @@ static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev,  		}  	} -	flags = irq_flags(p->triggering, p->polarity, p->sharable); +	flags = acpi_dev_irq_flags(p->triggering, p->polarity, p->sharable);  	pnp_register_irq_resource(dev, option_flags, &map, flags);  } @@ -574,9 +342,6 @@ static __init void pnpacpi_parse_port_option(struct pnp_dev *dev,  {  	unsigned char flags = 0; -	if (io->address_length == 0) -		return; -  	if (io->io_decode == ACPI_DECODE_16)  		flags = IORESOURCE_IO_16BIT_ADDR;  	pnp_register_port_resource(dev, option_flags, io->minimum, io->maximum, @@ -587,9 +352,6 @@ static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev,  					unsigned int option_flags,  					struct acpi_resource_fixed_io *io)  { -	if (io->address_length == 0) -		return; -  	pnp_register_port_resource(dev, option_flags, io->address, io->address,  				   0, io->address_length, IORESOURCE_IO_FIXED);  } @@ -600,9 +362,6 @@ static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev,  {  	unsigned char flags = 0; -	if (p->address_length == 0) -		return; -  	if (p->write_protect == ACPI_READ_WRITE_MEMORY)  		flags = IORESOURCE_MEM_WRITEABLE;  	pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum, @@ -615,9 +374,6 @@ static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev,  {  	unsigned char flags = 0; -	if (p->address_length == 0) -		return; -  	if (p->write_protect == ACPI_READ_WRITE_MEMORY)  		flags = IORESOURCE_MEM_WRITEABLE;  	pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum, @@ -630,9 +386,6 @@ static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev,  {  	unsigned char flags = 0; -	if (p->address_length == 0) -		return; -  	if (p->write_protect == ACPI_READ_WRITE_MEMORY)  		flags = IORESOURCE_MEM_WRITEABLE;  	pnp_register_mem_resource(dev, option_flags, p->address, p->address, @@ -654,9 +407,6 @@ static __init void pnpacpi_parse_address_option(struct pnp_dev *dev,  		return;  	} -	if (p->address_length == 0) -		return; -  	if (p->resource_type == ACPI_MEMORY_RANGE) {  		if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY)  			flags = IORESOURCE_MEM_WRITEABLE; @@ -676,9 +426,6 @@ static __init void pnpacpi_parse_ext_address_option(struct pnp_dev *dev,  	struct acpi_resource_extended_address64 *p = &r->data.ext_address64;  	unsigned char flags = 0; -	if (p->address_length == 0) -		return; -  	if (p->resource_type == ACPI_MEMORY_RANGE) {  		if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY)  			flags = IORESOURCE_MEM_WRITEABLE; @@ -896,6 +643,7 @@ int pnpacpi_build_resource_template(struct pnp_dev *dev,  	}  	/* resource will pointer the end resource now */  	resource->type = ACPI_RESOURCE_TYPE_END_TAG; +	resource->length = sizeof(struct acpi_resource);  	return 0;  } @@ -1018,7 +766,7 @@ static void pnpacpi_encode_io(struct pnp_dev *dev,  		io->minimum = p->start;  		io->maximum = p->end;  		io->alignment = 0;	/* Correct? */ -		io->address_length = p->end - p->start + 1; +		io->address_length = resource_size(p);  	} else {  		io->minimum = 0;  		io->address_length = 0; @@ -1036,7 +784,7 @@ static void pnpacpi_encode_fixed_io(struct pnp_dev *dev,  	if (pnp_resource_enabled(p)) {  		fixed_io->address = p->start; -		fixed_io->address_length = p->end - p->start + 1; +		fixed_io->address_length = resource_size(p);  	} else {  		fixed_io->address = 0;  		fixed_io->address_length = 0; @@ -1059,7 +807,7 @@ static void pnpacpi_encode_mem24(struct pnp_dev *dev,  		memory24->minimum = p->start;  		memory24->maximum = p->end;  		memory24->alignment = 0; -		memory24->address_length = p->end - p->start + 1; +		memory24->address_length = resource_size(p);  	} else {  		memory24->minimum = 0;  		memory24->address_length = 0; @@ -1083,7 +831,7 @@ static void pnpacpi_encode_mem32(struct pnp_dev *dev,  		memory32->minimum = p->start;  		memory32->maximum = p->end;  		memory32->alignment = 0; -		memory32->address_length = p->end - p->start + 1; +		memory32->address_length = resource_size(p);  	} else {  		memory32->minimum = 0;  		memory32->alignment = 0; @@ -1106,7 +854,7 @@ static void pnpacpi_encode_fixed_mem32(struct pnp_dev *dev,  		    p->flags & IORESOURCE_MEM_WRITEABLE ?  		    ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;  		fixed_memory32->address = p->start; -		fixed_memory32->address_length = p->end - p->start + 1; +		fixed_memory32->address_length = resource_size(p);  	} else {  		fixed_memory32->address = 0;  		fixed_memory32->address_length = 0; diff --git a/drivers/pnp/pnpbios/Kconfig b/drivers/pnp/pnpbios/Kconfig index b986d9fa3b9..50c3dd065e0 100644 --- a/drivers/pnp/pnpbios/Kconfig +++ b/drivers/pnp/pnpbios/Kconfig @@ -2,8 +2,8 @@  # Plug and Play BIOS configuration  #  config PNPBIOS -	bool "Plug and Play BIOS support (EXPERIMENTAL)" -	depends on ISA && X86 && EXPERIMENTAL +	bool "Plug and Play BIOS support" +	depends on ISA && X86  	default n  	---help---  	  Linux uses the PNPBIOS as defined in "Plug and Play BIOS diff --git a/drivers/pnp/pnpbios/Makefile b/drivers/pnp/pnpbios/Makefile index 3cd3ed76060..240b0ffb83c 100644 --- a/drivers/pnp/pnpbios/Makefile +++ b/drivers/pnp/pnpbios/Makefile @@ -1,7 +1,8 @@  #  # Makefile for the kernel PNPBIOS driver.  # +obj-y := pnp.o -pnpbios-proc-$(CONFIG_PNPBIOS_PROC_FS) = proc.o +pnp-y := core.o bioscalls.o rsparser.o -obj-y := core.o bioscalls.o rsparser.o $(pnpbios-proc-y) +pnp-$(CONFIG_PNPBIOS_PROC_FS) += proc.o diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c index 8591f6ab1b3..438d4c72c7b 100644 --- a/drivers/pnp/pnpbios/bioscalls.c +++ b/drivers/pnp/pnpbios/bioscalls.c @@ -17,12 +17,11 @@  #include <asm/page.h>  #include <asm/desc.h> -#include <asm/system.h>  #include <asm/byteorder.h>  #include "pnpbios.h" -static struct { +__visible struct {  	u16 offset;  	u16 segment;  } pnp_bios_callpoint; @@ -38,10 +37,11 @@ static struct {   * kernel begins at offset 3GB...   */ -asmlinkage void pnp_bios_callfunc(void); +asmlinkage __visible void pnp_bios_callfunc(void);  __asm__(".text			\n"  	__ALIGN_STR "\n" +	".globl pnp_bios_callfunc\n"  	"pnp_bios_callfunc:\n"  	"	pushl %edx	\n"  	"	pushl %ecx	\n" @@ -67,9 +67,9 @@ static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,   * after PnP BIOS oopses.   */ -u32 pnp_bios_fault_esp; -u32 pnp_bios_fault_eip; -u32 pnp_bios_is_utter_crap = 0; +__visible u32 pnp_bios_fault_esp; +__visible u32 pnp_bios_fault_eip; +__visible u32 pnp_bios_is_utter_crap = 0;  static spinlock_t pnp_bios_lock; @@ -219,7 +219,7 @@ void pnpbios_print_status(const char *module, u16 status)  		       module);  		break;  	case PNP_HARDWARE_ERROR: -		printk(KERN_ERR "PnPBIOS: %s: a hardware failure has occured\n", +		printk(KERN_ERR "PnPBIOS: %s: a hardware failure has occurred\n",  		       module);  		break;  	default: diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c index cfe86853feb..074569e77d2 100644 --- a/drivers/pnp/pnpbios/core.c +++ b/drivers/pnp/pnpbios/core.c @@ -65,7 +65,6 @@  #include <asm/page.h>  #include <asm/desc.h> -#include <asm/system.h>  #include <asm/byteorder.h>  #include "../base.h" @@ -92,8 +91,6 @@ struct pnp_dev_node_info node_info;   *   */ -#ifdef CONFIG_HOTPLUG -  static struct completion unload_sem;  /* @@ -200,8 +197,6 @@ static int pnp_dock_thread(void *unused)  	complete_and_exit(&unload_sem, 0);  } -#endif				/* CONFIG_HOTPLUG */ -  static int pnpbios_get_resources(struct pnp_dev *dev)  {  	u8 nodenum = dev->number; @@ -317,18 +312,19 @@ static int __init insert_device(struct pnp_bios_node *node)  	struct list_head *pos;  	struct pnp_dev *dev;  	char id[8]; +	int error;  	/* check if the device is already added */  	list_for_each(pos, &pnpbios_protocol.devices) {  		dev = list_entry(pos, struct pnp_dev, protocol_list);  		if (dev->number == node->handle) -			return -1; +			return -EEXIST;  	}  	pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);  	dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id);  	if (!dev) -		return -1; +		return -ENOMEM;  	pnpbios_parse_data_stream(dev, node);  	dev->active = pnp_is_active(dev); @@ -347,7 +343,12 @@ static int __init insert_device(struct pnp_bios_node *node)  	if (!dev->active)  		pnp_init_resources(dev); -	pnp_add_device(dev); +	error = pnp_add_device(dev); +	if (error) { +		put_device(&dev->dev); +		return error; +	} +  	pnpbios_interface_attach_device(node);  	return 0; @@ -518,10 +519,6 @@ static int __init pnpbios_init(void)  {  	int ret; -#if defined(CONFIG_PPC) -	if (check_legacy_ioport(PNPBIOS_BASE)) -		return -ENODEV; -#endif  	if (pnpbios_disabled || dmi_check_system(pnpbios_dmi_table) ||  	    paravirt_enabled()) {  		printk(KERN_INFO "PnPBIOS: Disabled\n"); @@ -574,21 +571,16 @@ fs_initcall(pnpbios_init);  static int __init pnpbios_thread_init(void)  { -#if defined(CONFIG_PPC) -	if (check_legacy_ioport(PNPBIOS_BASE)) -		return 0; -#endif +	struct task_struct *task; +  	if (pnpbios_disabled)  		return 0; -#ifdef CONFIG_HOTPLUG -	{ -		struct task_struct *task; -		init_completion(&unload_sem); -		task = kthread_run(pnp_dock_thread, NULL, "kpnpbiosd"); -		if (IS_ERR(task)) -			return PTR_ERR(task); -	} -#endif + +	init_completion(&unload_sem); +	task = kthread_run(pnp_dock_thread, NULL, "kpnpbiosd"); +	if (IS_ERR(task)) +		return PTR_ERR(task); +  	return 0;  } diff --git a/drivers/pnp/pnpbios/proc.c b/drivers/pnp/pnpbios/proc.c index bc89f392a62..c212db0fc65 100644 --- a/drivers/pnp/pnpbios/proc.c +++ b/drivers/pnp/pnpbios/proc.c @@ -185,10 +185,9 @@ static int pnp_devices_proc_show(struct seq_file *m, void *v)  		if (pnp_bios_get_dev_node(&nodenum, PNPMODE_DYNAMIC, node))  			break; -		seq_printf(m, "%02x\t%08x\t%02x:%02x:%02x\t%04x\n", +		seq_printf(m, "%02x\t%08x\t%3phC\t%04x\n",  			     node->handle, node->eisa_id, -			     node->type_code[0], node->type_code[1], -			     node->type_code[2], node->flags); +			     node->type_code, node->flags);  		if (nodenum <= thisnodenum) {  			printk(KERN_ERR  			       "%s Node number 0x%x is out of sequence following node 0x%x. Aborting.\n", @@ -238,13 +237,13 @@ static int pnpbios_proc_show(struct seq_file *m, void *v)  static int pnpbios_proc_open(struct inode *inode, struct file *file)  { -	return single_open(file, pnpbios_proc_show, PDE(inode)->data); +	return single_open(file, pnpbios_proc_show, PDE_DATA(inode));  }  static ssize_t pnpbios_proc_write(struct file *file, const char __user *buf,  				  size_t count, loff_t *pos)  { -	void *data = PDE(file->f_path.dentry->d_inode)->data; +	void *data = PDE_DATA(file_inode(file));  	struct pnp_bios_node *node;  	int boot = (long)data >> 8;  	u8 nodenum = (long)data; diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c index cb1f47bfee9..cca2f9f9f3e 100644 --- a/drivers/pnp/pnpbios/rsparser.c +++ b/drivers/pnp/pnpbios/rsparser.c @@ -505,7 +505,7 @@ static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p,  	if (pnp_resource_enabled(res)) {  		base = res->start; -		len = res->end - res->start + 1; +		len = resource_size(res);  	} else {  		base = 0;  		len = 0; @@ -529,7 +529,7 @@ static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p,  	if (pnp_resource_enabled(res)) {  		base = res->start; -		len = res->end - res->start + 1; +		len = resource_size(res);  	} else {  		base = 0;  		len = 0; @@ -559,7 +559,7 @@ static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p,  	if (pnp_resource_enabled(res)) {  		base = res->start; -		len = res->end - res->start + 1; +		len = resource_size(res);  	} else {  		base = 0;  		len = 0; @@ -617,7 +617,7 @@ static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p,  	if (pnp_resource_enabled(res)) {  		base = res->start; -		len = res->end - res->start + 1; +		len = resource_size(res);  	} else {  		base = 0;  		len = 0; @@ -636,11 +636,11 @@ static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p,  				      struct resource *res)  {  	unsigned long base = res->start; -	unsigned long len = res->end - res->start + 1; +	unsigned long len = resource_size(res);  	if (pnp_resource_enabled(res)) {  		base = res->start; -		len = res->end - res->start + 1; +		len = resource_size(res);  	} else {  		base = 0;  		len = 0; diff --git a/drivers/pnp/quirks.c b/drivers/pnp/quirks.c index dfbd5a6cc58..ebf0d6710b5 100644 --- a/drivers/pnp/quirks.c +++ b/drivers/pnp/quirks.c @@ -15,6 +15,7 @@  #include <linux/types.h>  #include <linux/kernel.h> +#include <linux/pci.h>  #include <linux/string.h>  #include <linux/slab.h>  #include <linux/pnp.h> @@ -295,6 +296,120 @@ static void quirk_system_pci_resources(struct pnp_dev *dev)  	}  } +#ifdef CONFIG_AMD_NB + +#include <asm/amd_nb.h> + +static void quirk_amd_mmconfig_area(struct pnp_dev *dev) +{ +	resource_size_t start, end; +	struct pnp_resource *pnp_res; +	struct resource *res; +	struct resource mmconfig_res, *mmconfig; + +	mmconfig = amd_get_mmconfig_range(&mmconfig_res); +	if (!mmconfig) +		return; + +	list_for_each_entry(pnp_res, &dev->resources, list) { +		res = &pnp_res->res; +		if (res->end < mmconfig->start || res->start > mmconfig->end || +		    (res->start == mmconfig->start && res->end == mmconfig->end)) +			continue; + +		dev_info(&dev->dev, FW_BUG +			 "%pR covers only part of AMD MMCONFIG area %pR; adding more reservations\n", +			 res, mmconfig); +		if (mmconfig->start < res->start) { +			start = mmconfig->start; +			end = res->start - 1; +			pnp_add_mem_resource(dev, start, end, 0); +		} +		if (mmconfig->end > res->end) { +			start = res->end + 1; +			end = mmconfig->end; +			pnp_add_mem_resource(dev, start, end, 0); +		} +		break; +	} +} +#endif + +#ifdef CONFIG_PCI +/* Device IDs of parts that have 32KB MCH space */ +static const unsigned int mch_quirk_devices[] = { +	0x0154,	/* Ivy Bridge */ +	0x0c00,	/* Haswell */ +}; + +static struct pci_dev *get_intel_host(void) +{ +	int i; +	struct pci_dev *host; + +	for (i = 0; i < ARRAY_SIZE(mch_quirk_devices); i++) { +		host = pci_get_device(PCI_VENDOR_ID_INTEL, mch_quirk_devices[i], +				      NULL); +		if (host) +			return host; +	} +	return NULL; +} + +static void quirk_intel_mch(struct pnp_dev *dev) +{ +	struct pci_dev *host; +	u32 addr_lo, addr_hi; +	struct pci_bus_region region; +	struct resource mch; +	struct pnp_resource *pnp_res; +	struct resource *res; + +	host = get_intel_host(); +	if (!host) +		return; + +	/* +	 * MCHBAR is not an architected PCI BAR, so MCH space is usually +	 * reported as a PNP0C02 resource.  The MCH space was originally +	 * 16KB, but is 32KB in newer parts.  Some BIOSes still report a +	 * PNP0C02 resource that is only 16KB, which means the rest of the +	 * MCH space is consumed but unreported. +	 */ + +	/* +	 * Read MCHBAR for Host Member Mapped Register Range Base +	 * https://www-ssl.intel.com/content/www/us/en/processors/core/4th-gen-core-family-desktop-vol-2-datasheet +	 * Sec 3.1.12. +	 */ +	pci_read_config_dword(host, 0x48, &addr_lo); +	region.start = addr_lo & ~0x7fff; +	pci_read_config_dword(host, 0x4c, &addr_hi); +	region.start |= (u64) addr_hi << 32; +	region.end = region.start + 32*1024 - 1; + +	memset(&mch, 0, sizeof(mch)); +	mch.flags = IORESOURCE_MEM; +	pcibios_bus_to_resource(host->bus, &mch, ®ion); + +	list_for_each_entry(pnp_res, &dev->resources, list) { +		res = &pnp_res->res; +		if (res->end < mch.start || res->start > mch.end) +			continue;	/* no overlap */ +		if (res->start == mch.start && res->end == mch.end) +			continue;	/* exact match */ + +		dev_info(&dev->dev, FW_BUG "PNP resource %pR covers only part of %s Intel MCH; extending to %pR\n", +			 res, pci_name(host), &mch); +		res->start = mch.start; +		res->end = mch.end; +		break; +	} + +	pci_dev_put(host); +} +#endif +  /*   *  PnP Quirks   *  Cards or devices that need some tweaking due to incomplete resource info @@ -322,6 +437,12 @@ static struct pnp_fixup pnp_fixups[] = {  	/* PnP resources that might overlap PCI BARs */  	{"PNP0c01", quirk_system_pci_resources},  	{"PNP0c02", quirk_system_pci_resources}, +#ifdef CONFIG_AMD_NB +	{"PNP0c01", quirk_amd_mmconfig_area}, +#endif +#ifdef CONFIG_PCI +	{"PNP0c02", quirk_intel_mch}, +#endif  	{""}  }; diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index a925e6b63d7..782e8228957 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -31,7 +31,7 @@ static int pnp_reserve_mem[16] = {[0 ... 15] = -1 };	/* reserve (don't use) some   * option registration   */ -struct pnp_option *pnp_build_option(struct pnp_dev *dev, unsigned long type, +static struct pnp_option *pnp_build_option(struct pnp_dev *dev, unsigned long type,  				    unsigned int option_flags)  {  	struct pnp_option *option; @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)  		return 1;  	/* check if the resource is valid */ -	if (*irq < 0 || *irq > 15) +	if (*irq > 15)  		return 0;  	/* check if the resource is reserved */ @@ -385,7 +385,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)  	 * device is active because it itself may be in use */  	if (!dev->active) {  		if (request_irq(*irq, pnp_test_handler, -				IRQF_DISABLED | IRQF_PROBE_SHARED, "pnp", NULL)) +				IRQF_PROBE_SHARED, "pnp", NULL))  			return 0;  		free_irq(*irq, NULL);  	} @@ -409,9 +409,9 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)  	return 1;  } +#ifdef CONFIG_ISA_DMA_API  int pnp_check_dma(struct pnp_dev *dev, struct resource *res)  { -#ifndef CONFIG_IA64  	int i;  	struct pnp_dev *tdev;  	struct resource *tres; @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)  		return 1;  	/* check if the resource is valid */ -	if (*dma < 0 || *dma == 4 || *dma > 7) +	if (*dma == 4 || *dma > 7)  		return 0;  	/* check if the resource is reserved */ @@ -466,11 +466,8 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)  	}  	return 1; -#else -	/* IA64 does not have legacy DMA */ -	return 0; -#endif  } +#endif /* CONFIG_ISA_DMA_API */  unsigned long pnp_resource_type(struct resource *res)  { @@ -506,6 +503,23 @@ static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev)  	return pnp_res;  } +struct pnp_resource *pnp_add_resource(struct pnp_dev *dev, +				      struct resource *res) +{ +	struct pnp_resource *pnp_res; + +	pnp_res = pnp_new_resource(dev); +	if (!pnp_res) { +		dev_err(&dev->dev, "can't add resource %pR\n", res); +		return NULL; +	} + +	pnp_res->res = *res; +	pnp_res->res.name = dev->name; +	dev_dbg(&dev->dev, "%pR\n", res); +	return pnp_res; +} +  struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,  					  int flags)  {  | 
