Release 4.12 drivers/pnp/manager.c
  
  
  
/*
 * manager.c - Resource Management, Conflict Resolution, Activation and Disabling of Devices
 *
 * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz>
 * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
 *      Bjorn Helgaas <bjorn.helgaas@hp.com>
 */
#include <linux/errno.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/pnp.h>
#include <linux/bitmap.h>
#include <linux/mutex.h>
#include "base.h"
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;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Witold Szczeponik | 64 | 100.00% | 1 | 100.00% | 
| Total | 64 | 100.00% | 1 | 100.00% | 
static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
{
	struct resource *res, local_res;
	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,
			(unsigned long long) res->end, res->flags);
		return 0;
	}
	res = &local_res;
	res->flags = rule->flags | IORESOURCE_AUTO;
	res->start = 0;
	res->end = 0;
	if (!rule->size) {
		res->flags |= IORESOURCE_DISABLED;
		pnp_dbg(&dev->dev, "  io %d disabled\n", idx);
		goto __add;
	}
	res->start = rule->min;
	res->end = res->start + rule->size - 1;
	while (!pnp_check_port(dev, res)) {
		res->start += rule->align;
		res->end = res->start + rule->size - 1;
		if (res->start > rule->max || !rule->align) {
			pnp_dbg(&dev->dev, "  couldn't assign io %d "
				"(min %#llx max %#llx)\n", idx,
				(unsigned long long) rule->min,
				(unsigned long long) rule->max);
			return -EBUSY;
		}
	}
__add:
	pnp_add_io_resource(dev, res->start, res->end, res->flags);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Björn Helgaas | 162 | 59.56% | 8 | 57.14% | 
| Adam Belay | 105 | 38.60% | 5 | 35.71% | 
| Witold Szczeponik | 5 | 1.84% | 1 | 7.14% | 
| Total | 272 | 100.00% | 14 | 100.00% | 
static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
{
	struct resource *res, local_res;
	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,
			(unsigned long long) res->end, res->flags);
		return 0;
	}
	res = &local_res;
	res->flags = rule->flags | IORESOURCE_AUTO;
	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_RANGELENGTH)
		res->flags |= IORESOURCE_RANGELENGTH;
	if (rule->flags & IORESOURCE_MEM_SHADOWABLE)
		res->flags |= IORESOURCE_SHADOWABLE;
	if (!rule->size) {
		res->flags |= IORESOURCE_DISABLED;
		pnp_dbg(&dev->dev, "  mem %d disabled\n", idx);
		goto __add;
	}
	res->start = rule->min;
	res->end = res->start + rule->size - 1;
	while (!pnp_check_mem(dev, res)) {
		res->start += rule->align;
		res->end = res->start + rule->size - 1;
		if (res->start > rule->max || !rule->align) {
			pnp_dbg(&dev->dev, "  couldn't assign mem %d "
				"(min %#llx max %#llx)\n", idx,
				(unsigned long long) rule->min,
				(unsigned long long) rule->max);
			return -EBUSY;
		}
	}
__add:
	pnp_add_mem_resource(dev, res->start, res->end, res->flags);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Björn Helgaas | 168 | 52.83% | 8 | 57.14% | 
| Adam Belay | 144 | 45.28% | 5 | 35.71% | 
| Witold Szczeponik | 6 | 1.89% | 1 | 7.14% | 
| Total | 318 | 100.00% | 14 | 100.00% | 
static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
{
	struct resource *res, local_res;
	int i;
	/* IRQ priority: this table is good for i386 */
	static unsigned short xtab[16] = {
		5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2
	};
	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);
		return 0;
	}
	res = &local_res;
	res->flags = rule->flags | IORESOURCE_AUTO;
	res->start = -1;
	res->end = -1;
	if (bitmap_empty(rule->map.bits, PNP_IRQ_NR)) {
		res->flags |= IORESOURCE_DISABLED;
		pnp_dbg(&dev->dev, "  irq %d disabled\n", idx);
		goto __add;
	}
	/* TBD: need check for >16 IRQ */
	res->start = find_next_bit(rule->map.bits, PNP_IRQ_NR, 16);
	if (res->start < PNP_IRQ_NR) {
		res->end = res->start;
		goto __add;
	}
	for (i = 0; i < 16; i++) {
		if (test_bit(xtab[i], rule->map.bits)) {
			res->start = res->end = xtab[i];
			if (pnp_check_irq(dev, res))
				goto __add;
		}
	}
	if (rule->flags & IORESOURCE_IRQ_OPTIONAL) {
		res->start = -1;
		res->end = -1;
		res->flags |= IORESOURCE_DISABLED;
		pnp_dbg(&dev->dev, "  irq %d disabled (optional)\n", idx);
		goto __add;
	}
	pnp_dbg(&dev->dev, "  couldn't assign irq %d\n", idx);
	return -EBUSY;
__add:
	pnp_add_irq_resource(dev, res->start, res->flags);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Björn Helgaas | 184 | 51.11% | 9 | 56.25% | 
| Adam Belay | 133 | 36.94% | 5 | 31.25% | 
| Len Brown | 38 | 10.56% | 1 | 6.25% | 
| Witold Szczeponik | 5 | 1.39% | 1 | 6.25% | 
| Total | 360 | 100.00% | 16 | 100.00% | 
#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;
	int i;
	/* DMA priority: this table is good for i386 */
	static unsigned short xtab[8] = {
		1, 3, 5, 6, 7, 0, 2, 4
	};
	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);
		return 0;
	}
	res = &local_res;
	res->flags = rule->flags | IORESOURCE_AUTO;
	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];
			if (pnp_check_dma(dev, res))
				goto __add;
		}
	}
	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;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Adam Belay | 109 | 43.08% | 4 | 30.77% | 
| Björn Helgaas | 104 | 41.11% | 7 | 53.85% | 
| David Flater | 35 | 13.83% | 1 | 7.69% | 
| Witold Szczeponik | 5 | 1.98% | 1 | 7.69% | 
| Total | 253 | 100.00% | 13 | 100.00% | 
#endif /* CONFIG_ISA_DMA_API */
void pnp_init_resources(struct pnp_dev *dev)
{
	pnp_free_resources(dev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Björn Helgaas | 15 | 100.00% | 2 | 100.00% | 
| Total | 15 | 100.00% | 2 | 100.00% | 
static void pnp_clean_resource_table(struct pnp_dev *dev)
{
	struct pnp_resource *pnp_res, *tmp;
	list_for_each_entry_safe(pnp_res, tmp, &dev->resources, list) {
		if (pnp_res->res.flags & IORESOURCE_AUTO)
			pnp_free_resource(pnp_res);
	}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Björn Helgaas | 33 | 71.74% | 4 | 57.14% | 
| Adam Belay | 13 | 28.26% | 3 | 42.86% | 
| Total | 46 | 100.00% | 7 | 100.00% | 
/**
 * pnp_assign_resources - assigns resources to the device based on the specified dependent number
 * @dev: pointer to the desired device
 * @set: the dependent function number
 */
static int pnp_assign_resources(struct pnp_dev *dev, int set)
{
	struct pnp_option *option;
	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);
	mutex_lock(&pnp_res_mutex);
	pnp_clean_resource_table(dev);
	list_for_each_entry(option, &dev->options, list) {
		if (pnp_option_is_dependent(option) &&
		    pnp_option_set(option) != set)
				continue;
		switch (option->type) {
		case IORESOURCE_IO:
			ret = pnp_assign_port(dev, &option->u.port, nport++);
			break;
		case IORESOURCE_MEM:
			ret = pnp_assign_mem(dev, &option->u.mem, nmem++);
			break;
		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;
		}
		if (ret < 0)
			break;
	}
	mutex_unlock(&pnp_res_mutex);
	if (ret < 0) {
		pnp_dbg(&dev->dev, "pnp_assign_resources failed (%d)\n", ret);
		pnp_clean_resource_table(dev);
	} else
		dbg_pnp_show_resources(dev, "pnp_assign_resources succeeded");
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Björn Helgaas | 121 | 49.59% | 4 | 36.36% | 
| Adam Belay | 112 | 45.90% | 4 | 36.36% | 
| David Rientjes | 8 | 3.28% | 1 | 9.09% | 
| Daniel Walker | 2 | 0.82% | 1 | 9.09% | 
| Adrian Bunk | 1 | 0.41% | 1 | 9.09% | 
| Total | 244 | 100.00% | 11 | 100.00% | 
/**
 * pnp_auto_config_dev - automatically assigns resources to a device
 * @dev: pointer to the desired device
 */
int pnp_auto_config_dev(struct pnp_dev *dev)
{
	int i, ret;
	if (!pnp_can_configure(dev)) {
		pnp_dbg(&dev->dev, "configuration not supported\n");
		return -ENODEV;
	}
	ret = pnp_assign_resources(dev, 0);
	if (ret == 0)
		return 0;
	for (i = 1; i < dev->num_dependent_sets; i++) {
		ret = pnp_assign_resources(dev, i);
		if (ret == 0)
			return 0;
	}
	dev_err(&dev->dev, "unable to assign resources\n");
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Adam Belay | 66 | 62.86% | 3 | 50.00% | 
| Björn Helgaas | 39 | 37.14% | 3 | 50.00% | 
| Total | 105 | 100.00% | 6 | 100.00% | 
/**
 * pnp_start_dev - low-level start of the PnP device
 * @dev: pointer to the desired device
 *
 * assumes that resources have already been allocated
 */
int pnp_start_dev(struct pnp_dev *dev)
{
	if (!pnp_can_write(dev)) {
		pnp_dbg(&dev->dev, "activation not supported\n");
		return -EINVAL;
	}
	dbg_pnp_show_resources(dev, "pnp_start_dev");
	if (dev->protocol->set(dev) < 0) {
		dev_err(&dev->dev, "activation failed\n");
		return -EIO;
	}
	dev_info(&dev->dev, "activated\n");
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Adam Belay | 62 | 74.70% | 3 | 42.86% | 
| Björn Helgaas | 19 | 22.89% | 3 | 42.86% | 
| Pierre Ossman | 2 | 2.41% | 1 | 14.29% | 
| Total | 83 | 100.00% | 7 | 100.00% | 
/**
 * pnp_stop_dev - low-level disable of the PnP device
 * @dev: pointer to the desired device
 *
 * does not free resources
 */
int pnp_stop_dev(struct pnp_dev *dev)
{
	if (!pnp_can_disable(dev)) {
		pnp_dbg(&dev->dev, "disabling not supported\n");
		return -EINVAL;
	}
	if (dev->protocol->disable(dev) < 0) {
		dev_err(&dev->dev, "disable failed\n");
		return -EIO;
	}
	dev_info(&dev->dev, "disabled\n");
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Adam Belay | 59 | 77.63% | 2 | 40.00% | 
| Björn Helgaas | 12 | 15.79% | 2 | 40.00% | 
| Pierre Ossman | 5 | 6.58% | 1 | 20.00% | 
| Total | 76 | 100.00% | 5 | 100.00% | 
/**
 * pnp_activate_dev - activates a PnP device for use
 * @dev: pointer to the desired device
 *
 * does not validate or set resources so be careful.
 */
int pnp_activate_dev(struct pnp_dev *dev)
{
	int error;
	if (dev->active)
		return 0;
	/* ensure resources are allocated */
	if (pnp_auto_config_dev(dev))
		return -EBUSY;
	error = pnp_start_dev(dev);
	if (error)
		return error;
	dev->active = 1;
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Pierre Ossman | 56 | 98.25% | 1 | 50.00% | 
| Björn Helgaas | 1 | 1.75% | 1 | 50.00% | 
| Total | 57 | 100.00% | 2 | 100.00% | 
/**
 * pnp_disable_dev - disables device
 * @dev: pointer to the desired device
 *
 * inform the correct pnp protocol so that resources can be used by other devices
 */
int pnp_disable_dev(struct pnp_dev *dev)
{
	int error;
	if (!dev->active)
		return 0;
	error = pnp_stop_dev(dev);
	if (error)
		return error;
	dev->active = 0;
	/* release the resources so that other devices can use them */
	mutex_lock(&pnp_res_mutex);
	pnp_clean_resource_table(dev);
	mutex_unlock(&pnp_res_mutex);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Pierre Ossman | 42 | 65.62% | 1 | 16.67% | 
| Adam Belay | 19 | 29.69% | 3 | 50.00% | 
| Daniel Walker | 2 | 3.12% | 1 | 16.67% | 
| Björn Helgaas | 1 | 1.56% | 1 | 16.67% | 
| Total | 64 | 100.00% | 6 | 100.00% | 
EXPORT_SYMBOL(pnp_start_dev);
EXPORT_SYMBOL(pnp_stop_dev);
EXPORT_SYMBOL(pnp_activate_dev);
EXPORT_SYMBOL(pnp_disable_dev);
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Björn Helgaas | 863 | 42.74% | 17 | 50.00% | 
| Adam Belay | 854 | 42.30% | 9 | 26.47% | 
| Pierre Ossman | 118 | 5.84% | 1 | 2.94% | 
| Witold Szczeponik | 85 | 4.21% | 1 | 2.94% | 
| Len Brown | 38 | 1.88% | 1 | 2.94% | 
| David Flater | 35 | 1.73% | 1 | 2.94% | 
| David Rientjes | 14 | 0.69% | 1 | 2.94% | 
| Daniel Walker | 8 | 0.40% | 1 | 2.94% | 
| Tim Schmielau | 3 | 0.15% | 1 | 2.94% | 
| Adrian Bunk | 1 | 0.05% | 1 | 2.94% | 
| Total | 2019 | 100.00% | 34 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.