mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 11:11:45 -04:00
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
This commit is contained in:
commit
1da177e4c3
17291 changed files with 6718755 additions and 0 deletions
41
drivers/pnp/Kconfig
Normal file
41
drivers/pnp/Kconfig
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#
|
||||
# Plug and Play configuration
|
||||
#
|
||||
|
||||
menu "Plug and Play support"
|
||||
|
||||
config PNP
|
||||
bool "Plug and Play support"
|
||||
depends on ISA || ACPI_BUS
|
||||
---help---
|
||||
Plug and Play (PnP) is a standard for peripherals which allows those
|
||||
peripherals to be configured by software, e.g. assign IRQ's or other
|
||||
parameters. No jumpers on the cards are needed, instead the values
|
||||
are provided to the cards from the BIOS, from the operating system,
|
||||
or using a user-space utility.
|
||||
|
||||
Say Y here if you would like Linux to configure your Plug and Play
|
||||
devices. You should then also say Y to all of the protocols below.
|
||||
Alternatively, you can say N here and configure your PnP devices
|
||||
using user space utilities such as the isapnptools package.
|
||||
|
||||
If unsure, say Y.
|
||||
|
||||
config PNP_DEBUG
|
||||
bool "PnP Debug Messages"
|
||||
depends on PNP
|
||||
help
|
||||
Say Y if you want the Plug and Play Layer to print debug messages.
|
||||
This is useful if you are developing a PnP driver or troubleshooting.
|
||||
|
||||
comment "Protocols"
|
||||
depends on PNP
|
||||
|
||||
source "drivers/pnp/isapnp/Kconfig"
|
||||
|
||||
source "drivers/pnp/pnpbios/Kconfig"
|
||||
|
||||
source "drivers/pnp/pnpacpi/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
9
drivers/pnp/Makefile
Normal file
9
drivers/pnp/Makefile
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#
|
||||
# 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 system.o
|
||||
|
||||
obj-$(CONFIG_PNPACPI) += pnpacpi/
|
||||
obj-$(CONFIG_PNPBIOS) += pnpbios/
|
||||
obj-$(CONFIG_ISAPNP) += isapnp/
|
||||
13
drivers/pnp/base.h
Normal file
13
drivers/pnp/base.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
extern struct bus_type pnp_bus_type;
|
||||
extern spinlock_t pnp_lock;
|
||||
void *pnp_alloc(long size);
|
||||
int pnp_interface_attach_device(struct pnp_dev *dev);
|
||||
void pnp_fixup_device(struct pnp_dev *dev);
|
||||
void pnp_free_option(struct pnp_option *option);
|
||||
int __pnp_add_device(struct pnp_dev *dev);
|
||||
void __pnp_remove_device(struct pnp_dev *dev);
|
||||
|
||||
int pnp_check_port(struct pnp_dev * dev, int idx);
|
||||
int pnp_check_mem(struct pnp_dev * dev, int idx);
|
||||
int pnp_check_irq(struct pnp_dev * dev, int idx);
|
||||
int pnp_check_dma(struct pnp_dev * dev, int idx);
|
||||
391
drivers/pnp/card.c
Normal file
391
drivers/pnp/card.c
Normal file
|
|
@ -0,0 +1,391 @@
|
|||
/*
|
||||
* card.c - contains functions for managing groups of PnP devices
|
||||
*
|
||||
* Copyright 2002 Adam Belay <ambx1@neo.rr.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#ifdef CONFIG_PNP_DEBUG
|
||||
#define DEBUG
|
||||
#else
|
||||
#undef DEBUG
|
||||
#endif
|
||||
|
||||
#include <linux/pnp.h>
|
||||
#include "base.h"
|
||||
|
||||
LIST_HEAD(pnp_cards);
|
||||
LIST_HEAD(pnp_card_drivers);
|
||||
|
||||
|
||||
static const struct pnp_card_device_id * match_card(struct pnp_card_driver * drv, struct pnp_card * card)
|
||||
{
|
||||
const struct pnp_card_device_id * drv_id = drv->id_table;
|
||||
while (*drv_id->id){
|
||||
if (compare_pnp_id(card->id,drv_id->id)) {
|
||||
int i = 0;
|
||||
for (;;) {
|
||||
int found;
|
||||
struct pnp_dev *dev;
|
||||
if (i == PNP_MAX_DEVICES || ! *drv_id->devs[i].id)
|
||||
return drv_id;
|
||||
found = 0;
|
||||
card_for_each_dev(card, dev) {
|
||||
if (compare_pnp_id(dev->id, drv_id->devs[i].id)) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! found)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
drv_id++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void card_remove(struct pnp_dev * dev)
|
||||
{
|
||||
dev->card_link = NULL;
|
||||
}
|
||||
|
||||
static void card_remove_first(struct pnp_dev * dev)
|
||||
{
|
||||
struct pnp_card_driver * drv = to_pnp_card_driver(dev->driver);
|
||||
if (!dev->card || !drv)
|
||||
return;
|
||||
if (drv->remove)
|
||||
drv->remove(dev->card_link);
|
||||
drv->link.remove = &card_remove;
|
||||
kfree(dev->card_link);
|
||||
card_remove(dev);
|
||||
}
|
||||
|
||||
static int card_probe(struct pnp_card * card, struct pnp_card_driver * drv)
|
||||
{
|
||||
const struct pnp_card_device_id *id = match_card(drv,card);
|
||||
if (id) {
|
||||
struct pnp_card_link * clink = pnp_alloc(sizeof(struct pnp_card_link));
|
||||
if (!clink)
|
||||
return 0;
|
||||
clink->card = card;
|
||||
clink->driver = drv;
|
||||
if (drv->probe) {
|
||||
if (drv->probe(clink, id)>=0)
|
||||
return 1;
|
||||
else {
|
||||
struct pnp_dev * dev;
|
||||
card_for_each_dev(card, dev) {
|
||||
if (dev->card_link == clink)
|
||||
pnp_release_card_device(dev);
|
||||
}
|
||||
kfree(clink);
|
||||
}
|
||||
} else
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_add_card_id - adds an EISA id to the specified card
|
||||
* @id: pointer to a pnp_id structure
|
||||
* @card: pointer to the desired card
|
||||
*
|
||||
*/
|
||||
|
||||
int pnp_add_card_id(struct pnp_id *id, struct pnp_card * card)
|
||||
{
|
||||
struct pnp_id * ptr;
|
||||
if (!id)
|
||||
return -EINVAL;
|
||||
if (!card)
|
||||
return -EINVAL;
|
||||
id->next = NULL;
|
||||
ptr = card->id;
|
||||
while (ptr && ptr->next)
|
||||
ptr = ptr->next;
|
||||
if (ptr)
|
||||
ptr->next = id;
|
||||
else
|
||||
card->id = id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pnp_free_card_ids(struct pnp_card * card)
|
||||
{
|
||||
struct pnp_id * id;
|
||||
struct pnp_id *next;
|
||||
if (!card)
|
||||
return;
|
||||
id = card->id;
|
||||
while (id) {
|
||||
next = id->next;
|
||||
kfree(id);
|
||||
id = next;
|
||||
}
|
||||
}
|
||||
|
||||
static void pnp_release_card(struct device *dmdev)
|
||||
{
|
||||
struct pnp_card * card = to_pnp_card(dmdev);
|
||||
pnp_free_card_ids(card);
|
||||
kfree(card);
|
||||
}
|
||||
|
||||
|
||||
static ssize_t pnp_show_card_name(struct device *dmdev, char *buf)
|
||||
{
|
||||
char *str = buf;
|
||||
struct pnp_card *card = to_pnp_card(dmdev);
|
||||
str += sprintf(str,"%s\n", card->name);
|
||||
return (str - buf);
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(name,S_IRUGO,pnp_show_card_name,NULL);
|
||||
|
||||
static ssize_t pnp_show_card_ids(struct device *dmdev, char *buf)
|
||||
{
|
||||
char *str = buf;
|
||||
struct pnp_card *card = to_pnp_card(dmdev);
|
||||
struct pnp_id * pos = card->id;
|
||||
|
||||
while (pos) {
|
||||
str += sprintf(str,"%s\n", pos->id);
|
||||
pos = pos->next;
|
||||
}
|
||||
return (str - buf);
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(card_id,S_IRUGO,pnp_show_card_ids,NULL);
|
||||
|
||||
static int pnp_interface_attach_card(struct pnp_card *card)
|
||||
{
|
||||
device_create_file(&card->dev,&dev_attr_name);
|
||||
device_create_file(&card->dev,&dev_attr_card_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_add_card - adds a PnP card to the PnP Layer
|
||||
* @card: pointer to the card to add
|
||||
*/
|
||||
|
||||
int pnp_add_card(struct pnp_card * card)
|
||||
{
|
||||
int error;
|
||||
struct list_head * pos, * temp;
|
||||
if (!card || !card->protocol)
|
||||
return -EINVAL;
|
||||
|
||||
sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number, card->number);
|
||||
card->dev.parent = &card->protocol->dev;
|
||||
card->dev.bus = NULL;
|
||||
card->dev.release = &pnp_release_card;
|
||||
error = device_register(&card->dev);
|
||||
|
||||
if (error == 0) {
|
||||
pnp_interface_attach_card(card);
|
||||
spin_lock(&pnp_lock);
|
||||
list_add_tail(&card->global_list, &pnp_cards);
|
||||
list_add_tail(&card->protocol_list, &card->protocol->cards);
|
||||
spin_unlock(&pnp_lock);
|
||||
|
||||
/* we wait until now to add devices in order to ensure the drivers
|
||||
* will be able to use all of the related devices on the card
|
||||
* without waiting any unresonable length of time */
|
||||
list_for_each(pos,&card->devices){
|
||||
struct pnp_dev *dev = card_to_pnp_dev(pos);
|
||||
__pnp_add_device(dev);
|
||||
}
|
||||
|
||||
/* match with card drivers */
|
||||
list_for_each_safe(pos,temp,&pnp_card_drivers){
|
||||
struct pnp_card_driver * drv = list_entry(pos, struct pnp_card_driver, global_list);
|
||||
card_probe(card,drv);
|
||||
}
|
||||
} else
|
||||
pnp_err("sysfs failure, card '%s' will be unavailable", card->dev.bus_id);
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_remove_card - removes a PnP card from the PnP Layer
|
||||
* @card: pointer to the card to remove
|
||||
*/
|
||||
|
||||
void pnp_remove_card(struct pnp_card * card)
|
||||
{
|
||||
struct list_head *pos, *temp;
|
||||
if (!card)
|
||||
return;
|
||||
device_unregister(&card->dev);
|
||||
spin_lock(&pnp_lock);
|
||||
list_del(&card->global_list);
|
||||
list_del(&card->protocol_list);
|
||||
spin_unlock(&pnp_lock);
|
||||
list_for_each_safe(pos,temp,&card->devices){
|
||||
struct pnp_dev *dev = card_to_pnp_dev(pos);
|
||||
pnp_remove_card_device(dev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_add_card_device - adds a device to the specified card
|
||||
* @card: pointer to the card to add to
|
||||
* @dev: pointer to the device to add
|
||||
*/
|
||||
|
||||
int pnp_add_card_device(struct pnp_card * card, struct pnp_dev * dev)
|
||||
{
|
||||
if (!card || !dev || !dev->protocol)
|
||||
return -EINVAL;
|
||||
dev->dev.parent = &card->dev;
|
||||
dev->card_link = NULL;
|
||||
snprintf(dev->dev.bus_id, BUS_ID_SIZE, "%02x:%02x.%02x", dev->protocol->number,
|
||||
card->number,dev->number);
|
||||
spin_lock(&pnp_lock);
|
||||
dev->card = card;
|
||||
list_add_tail(&dev->card_list, &card->devices);
|
||||
spin_unlock(&pnp_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_remove_card_device- removes a device from the specified card
|
||||
* @card: pointer to the card to remove from
|
||||
* @dev: pointer to the device to remove
|
||||
*/
|
||||
|
||||
void pnp_remove_card_device(struct pnp_dev * dev)
|
||||
{
|
||||
spin_lock(&pnp_lock);
|
||||
dev->card = NULL;
|
||||
list_del(&dev->card_list);
|
||||
spin_unlock(&pnp_lock);
|
||||
__pnp_remove_device(dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_request_card_device - Searches for a PnP device under the specified card
|
||||
* @lcard: 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.
|
||||
*/
|
||||
|
||||
struct pnp_dev * pnp_request_card_device(struct pnp_card_link *clink, const char * id, struct pnp_dev * from)
|
||||
{
|
||||
struct list_head * pos;
|
||||
struct pnp_dev * dev;
|
||||
struct pnp_card_driver * drv;
|
||||
struct pnp_card * card;
|
||||
if (!clink || !id)
|
||||
goto done;
|
||||
card = clink->card;
|
||||
drv = clink->driver;
|
||||
if (!from) {
|
||||
pos = card->devices.next;
|
||||
} else {
|
||||
if (from->card != card)
|
||||
goto done;
|
||||
pos = from->card_list.next;
|
||||
}
|
||||
while (pos != &card->devices) {
|
||||
dev = card_to_pnp_dev(pos);
|
||||
if ((!dev->card_link) && compare_pnp_id(dev->id,id))
|
||||
goto found;
|
||||
pos = pos->next;
|
||||
}
|
||||
|
||||
done:
|
||||
return NULL;
|
||||
|
||||
found:
|
||||
down_write(&dev->dev.bus->subsys.rwsem);
|
||||
dev->card_link = clink;
|
||||
dev->dev.driver = &drv->link.driver;
|
||||
if (drv->link.driver.probe) {
|
||||
if (drv->link.driver.probe(&dev->dev)) {
|
||||
dev->dev.driver = NULL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
device_bind_driver(&dev->dev);
|
||||
up_write(&dev->dev.bus->subsys.rwsem);
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_release_card_device - call this when the driver no longer needs the device
|
||||
* @dev: pointer to the PnP device stucture
|
||||
*/
|
||||
|
||||
void pnp_release_card_device(struct pnp_dev * dev)
|
||||
{
|
||||
struct pnp_card_driver * drv = dev->card_link->driver;
|
||||
if (!drv)
|
||||
return;
|
||||
down_write(&dev->dev.bus->subsys.rwsem);
|
||||
drv->link.remove = &card_remove;
|
||||
device_release_driver(&dev->dev);
|
||||
drv->link.remove = &card_remove_first;
|
||||
up_write(&dev->dev.bus->subsys.rwsem);
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_register_card_driver - registers a PnP card driver with the PnP Layer
|
||||
* @drv: pointer to the driver to register
|
||||
*/
|
||||
|
||||
int pnp_register_card_driver(struct pnp_card_driver * drv)
|
||||
{
|
||||
int count = 0;
|
||||
struct list_head *pos, *temp;
|
||||
|
||||
drv->link.name = drv->name;
|
||||
drv->link.id_table = NULL; /* this will disable auto matching */
|
||||
drv->link.flags = drv->flags;
|
||||
drv->link.probe = NULL;
|
||||
drv->link.remove = &card_remove_first;
|
||||
|
||||
spin_lock(&pnp_lock);
|
||||
list_add_tail(&drv->global_list, &pnp_card_drivers);
|
||||
spin_unlock(&pnp_lock);
|
||||
pnp_register_driver(&drv->link);
|
||||
|
||||
list_for_each_safe(pos,temp,&pnp_cards){
|
||||
struct pnp_card *card = list_entry(pos, struct pnp_card, global_list);
|
||||
count += card_probe(card,drv);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_unregister_card_driver - unregisters a PnP card driver from the PnP Layer
|
||||
* @drv: pointer to the driver to unregister
|
||||
*/
|
||||
|
||||
void pnp_unregister_card_driver(struct pnp_card_driver * drv)
|
||||
{
|
||||
spin_lock(&pnp_lock);
|
||||
list_del(&drv->global_list);
|
||||
spin_unlock(&pnp_lock);
|
||||
pnp_unregister_driver(&drv->link);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(pnp_add_card);
|
||||
EXPORT_SYMBOL(pnp_remove_card);
|
||||
EXPORT_SYMBOL(pnp_add_card_device);
|
||||
EXPORT_SYMBOL(pnp_remove_card_device);
|
||||
EXPORT_SYMBOL(pnp_add_card_id);
|
||||
EXPORT_SYMBOL(pnp_request_card_device);
|
||||
EXPORT_SYMBOL(pnp_release_card_device);
|
||||
EXPORT_SYMBOL(pnp_register_card_driver);
|
||||
EXPORT_SYMBOL(pnp_unregister_card_driver);
|
||||
180
drivers/pnp/core.c
Normal file
180
drivers/pnp/core.c
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* core.c - contains all core device and protocol registration functions
|
||||
*
|
||||
* Copyright 2002 Adam Belay <ambx1@neo.rr.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/pnp.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/errno.h>
|
||||
|
||||
#include "base.h"
|
||||
|
||||
|
||||
static LIST_HEAD(pnp_protocols);
|
||||
LIST_HEAD(pnp_global);
|
||||
DEFINE_SPINLOCK(pnp_lock);
|
||||
|
||||
void *pnp_alloc(long size)
|
||||
{
|
||||
void *result;
|
||||
|
||||
result = kmalloc(size, GFP_KERNEL);
|
||||
if (!result){
|
||||
printk(KERN_ERR "pnp: Out of Memory\n");
|
||||
return NULL;
|
||||
}
|
||||
memset(result, 0, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_protocol_register - adds a pnp protocol to the pnp layer
|
||||
* @protocol: pointer to the corresponding pnp_protocol structure
|
||||
*
|
||||
* Ex protocols: ISAPNP, PNPBIOS, etc
|
||||
*/
|
||||
|
||||
int pnp_register_protocol(struct pnp_protocol *protocol)
|
||||
{
|
||||
int nodenum;
|
||||
struct list_head * pos;
|
||||
|
||||
if (!protocol)
|
||||
return -EINVAL;
|
||||
|
||||
INIT_LIST_HEAD(&protocol->devices);
|
||||
INIT_LIST_HEAD(&protocol->cards);
|
||||
nodenum = 0;
|
||||
spin_lock(&pnp_lock);
|
||||
|
||||
/* assign the lowest unused number */
|
||||
list_for_each(pos,&pnp_protocols) {
|
||||
struct pnp_protocol * cur = to_pnp_protocol(pos);
|
||||
if (cur->number == nodenum){
|
||||
pos = &pnp_protocols;
|
||||
nodenum++;
|
||||
}
|
||||
}
|
||||
|
||||
list_add_tail(&protocol->protocol_list, &pnp_protocols);
|
||||
spin_unlock(&pnp_lock);
|
||||
|
||||
protocol->number = nodenum;
|
||||
sprintf(protocol->dev.bus_id, "pnp%d", nodenum);
|
||||
return device_register(&protocol->dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_protocol_unregister - removes a pnp protocol from the pnp layer
|
||||
* @protocol: pointer to the corresponding pnp_protocol structure
|
||||
*
|
||||
*/
|
||||
void pnp_unregister_protocol(struct pnp_protocol *protocol)
|
||||
{
|
||||
spin_lock(&pnp_lock);
|
||||
list_del(&protocol->protocol_list);
|
||||
spin_unlock(&pnp_lock);
|
||||
device_unregister(&protocol->dev);
|
||||
}
|
||||
|
||||
|
||||
static void pnp_free_ids(struct pnp_dev *dev)
|
||||
{
|
||||
struct pnp_id * id;
|
||||
struct pnp_id * next;
|
||||
if (!dev)
|
||||
return;
|
||||
id = dev->id;
|
||||
while (id) {
|
||||
next = id->next;
|
||||
kfree(id);
|
||||
id = next;
|
||||
}
|
||||
}
|
||||
|
||||
static void pnp_release_device(struct device *dmdev)
|
||||
{
|
||||
struct pnp_dev * dev = to_pnp_dev(dmdev);
|
||||
pnp_free_option(dev->independent);
|
||||
pnp_free_option(dev->dependent);
|
||||
pnp_free_ids(dev);
|
||||
kfree(dev);
|
||||
}
|
||||
|
||||
int __pnp_add_device(struct pnp_dev *dev)
|
||||
{
|
||||
int ret;
|
||||
pnp_fixup_device(dev);
|
||||
dev->dev.bus = &pnp_bus_type;
|
||||
dev->dev.release = &pnp_release_device;
|
||||
dev->status = PNP_READY;
|
||||
spin_lock(&pnp_lock);
|
||||
list_add_tail(&dev->global_list, &pnp_global);
|
||||
list_add_tail(&dev->protocol_list, &dev->protocol->devices);
|
||||
spin_unlock(&pnp_lock);
|
||||
|
||||
ret = device_register(&dev->dev);
|
||||
if (ret == 0)
|
||||
pnp_interface_attach_device(dev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* pnp_add_device - adds a pnp device to the pnp layer
|
||||
* @dev: pointer to dev to add
|
||||
*
|
||||
* adds to driver model, name database, fixups, interface, etc.
|
||||
*/
|
||||
|
||||
int pnp_add_device(struct pnp_dev *dev)
|
||||
{
|
||||
if (!dev || !dev->protocol || dev->card)
|
||||
return -EINVAL;
|
||||
dev->dev.parent = &dev->protocol->dev;
|
||||
sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number, dev->number);
|
||||
return __pnp_add_device(dev);
|
||||
}
|
||||
|
||||
void __pnp_remove_device(struct pnp_dev *dev)
|
||||
{
|
||||
spin_lock(&pnp_lock);
|
||||
list_del(&dev->global_list);
|
||||
list_del(&dev->protocol_list);
|
||||
spin_unlock(&pnp_lock);
|
||||
device_unregister(&dev->dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_remove_device - removes a pnp device from the pnp layer
|
||||
* @dev: pointer to dev to add
|
||||
*
|
||||
* this function will free all mem used by dev
|
||||
*/
|
||||
|
||||
void pnp_remove_device(struct pnp_dev *dev)
|
||||
{
|
||||
if (!dev || dev->card)
|
||||
return;
|
||||
__pnp_remove_device(dev);
|
||||
}
|
||||
|
||||
static int __init pnp_init(void)
|
||||
{
|
||||
printk(KERN_INFO "Linux Plug and Play Support v0.97 (c) Adam Belay\n");
|
||||
return bus_register(&pnp_bus_type);
|
||||
}
|
||||
|
||||
subsys_initcall(pnp_init);
|
||||
|
||||
EXPORT_SYMBOL(pnp_register_protocol);
|
||||
EXPORT_SYMBOL(pnp_unregister_protocol);
|
||||
EXPORT_SYMBOL(pnp_add_device);
|
||||
EXPORT_SYMBOL(pnp_remove_device);
|
||||
222
drivers/pnp/driver.c
Normal file
222
drivers/pnp/driver.c
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
/*
|
||||
* driver.c - device id matching, driver model, etc.
|
||||
*
|
||||
* Copyright 2002 Adam Belay <ambx1@neo.rr.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#ifdef CONFIG_PNP_DEBUG
|
||||
#define DEBUG
|
||||
#else
|
||||
#undef DEBUG
|
||||
#endif
|
||||
|
||||
#include <linux/pnp.h>
|
||||
#include "base.h"
|
||||
|
||||
static int compare_func(const char *ida, const char *idb)
|
||||
{
|
||||
int i;
|
||||
/* we only need to compare the last 4 chars */
|
||||
for (i=3; i<7; i++)
|
||||
{
|
||||
if (ida[i] != 'X' &&
|
||||
idb[i] != 'X' &&
|
||||
toupper(ida[i]) != toupper(idb[i]))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int compare_pnp_id(struct pnp_id *pos, const char *id)
|
||||
{
|
||||
if (!pos || !id || (strlen(id) != 7))
|
||||
return 0;
|
||||
if (memcmp(id,"ANYDEVS",7)==0)
|
||||
return 1;
|
||||
while (pos){
|
||||
if (memcmp(pos->id,id,3)==0)
|
||||
if (compare_func(pos->id,id)==1)
|
||||
return 1;
|
||||
pos = pos->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pnp_device_id * match_device(struct pnp_driver *drv, struct pnp_dev *dev)
|
||||
{
|
||||
const struct pnp_device_id *drv_id = drv->id_table;
|
||||
if (!drv_id)
|
||||
return NULL;
|
||||
|
||||
while (*drv_id->id) {
|
||||
if (compare_pnp_id(dev->id, drv_id->id))
|
||||
return drv_id;
|
||||
drv_id++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int pnp_device_attach(struct pnp_dev *pnp_dev)
|
||||
{
|
||||
spin_lock(&pnp_lock);
|
||||
if(pnp_dev->status != PNP_READY){
|
||||
spin_unlock(&pnp_lock);
|
||||
return -EBUSY;
|
||||
}
|
||||
pnp_dev->status = PNP_ATTACHED;
|
||||
spin_unlock(&pnp_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pnp_device_detach(struct pnp_dev *pnp_dev)
|
||||
{
|
||||
spin_lock(&pnp_lock);
|
||||
if (pnp_dev->status == PNP_ATTACHED)
|
||||
pnp_dev->status = PNP_READY;
|
||||
spin_unlock(&pnp_lock);
|
||||
pnp_disable_dev(pnp_dev);
|
||||
}
|
||||
|
||||
static int pnp_device_probe(struct device *dev)
|
||||
{
|
||||
int error;
|
||||
struct pnp_driver *pnp_drv;
|
||||
struct pnp_dev *pnp_dev;
|
||||
const struct pnp_device_id *dev_id = NULL;
|
||||
pnp_dev = to_pnp_dev(dev);
|
||||
pnp_drv = to_pnp_driver(dev->driver);
|
||||
|
||||
pnp_dbg("match found with the PnP device '%s' and the driver '%s'", dev->bus_id,pnp_drv->name);
|
||||
|
||||
error = pnp_device_attach(pnp_dev);
|
||||
if (error < 0)
|
||||
return error;
|
||||
|
||||
if (pnp_dev->active == 0) {
|
||||
if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE)) {
|
||||
error = pnp_activate_dev(pnp_dev);
|
||||
if (error < 0)
|
||||
return error;
|
||||
}
|
||||
} else if ((pnp_drv->flags & PNP_DRIVER_RES_DISABLE)
|
||||
== PNP_DRIVER_RES_DISABLE) {
|
||||
error = pnp_disable_dev(pnp_dev);
|
||||
if (error < 0)
|
||||
return error;
|
||||
}
|
||||
error = 0;
|
||||
if (pnp_drv->probe) {
|
||||
dev_id = match_device(pnp_drv, pnp_dev);
|
||||
if (dev_id != NULL)
|
||||
error = pnp_drv->probe(pnp_dev, dev_id);
|
||||
}
|
||||
if (error >= 0){
|
||||
pnp_dev->driver = pnp_drv;
|
||||
error = 0;
|
||||
} else
|
||||
goto fail;
|
||||
return error;
|
||||
|
||||
fail:
|
||||
pnp_device_detach(pnp_dev);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int pnp_device_remove(struct device *dev)
|
||||
{
|
||||
struct pnp_dev * pnp_dev = to_pnp_dev(dev);
|
||||
struct pnp_driver * drv = pnp_dev->driver;
|
||||
|
||||
if (drv) {
|
||||
if (drv->remove)
|
||||
drv->remove(pnp_dev);
|
||||
pnp_dev->driver = NULL;
|
||||
}
|
||||
pnp_device_detach(pnp_dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pnp_bus_match(struct device *dev, struct device_driver *drv)
|
||||
{
|
||||
struct pnp_dev * pnp_dev = to_pnp_dev(dev);
|
||||
struct pnp_driver * pnp_drv = to_pnp_driver(drv);
|
||||
if (match_device(pnp_drv, pnp_dev) == NULL)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
struct bus_type pnp_bus_type = {
|
||||
.name = "pnp",
|
||||
.match = pnp_bus_match,
|
||||
};
|
||||
|
||||
|
||||
int pnp_register_driver(struct pnp_driver *drv)
|
||||
{
|
||||
int count;
|
||||
struct list_head *pos;
|
||||
|
||||
pnp_dbg("the driver '%s' has been registered", drv->name);
|
||||
|
||||
drv->driver.name = drv->name;
|
||||
drv->driver.bus = &pnp_bus_type;
|
||||
drv->driver.probe = pnp_device_probe;
|
||||
drv->driver.remove = pnp_device_remove;
|
||||
|
||||
count = driver_register(&drv->driver);
|
||||
|
||||
/* get the number of initial matches */
|
||||
if (count >= 0){
|
||||
count = 0;
|
||||
list_for_each(pos,&drv->driver.devices){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void pnp_unregister_driver(struct pnp_driver *drv)
|
||||
{
|
||||
driver_unregister(&drv->driver);
|
||||
pnp_dbg("the driver '%s' has been unregistered", drv->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_add_id - adds an EISA id to the specified device
|
||||
* @id: pointer to a pnp_id structure
|
||||
* @dev: pointer to the desired device
|
||||
*
|
||||
*/
|
||||
|
||||
int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev)
|
||||
{
|
||||
struct pnp_id *ptr;
|
||||
if (!id)
|
||||
return -EINVAL;
|
||||
if (!dev)
|
||||
return -EINVAL;
|
||||
id->next = NULL;
|
||||
ptr = dev->id;
|
||||
while (ptr && ptr->next)
|
||||
ptr = ptr->next;
|
||||
if (ptr)
|
||||
ptr->next = id;
|
||||
else
|
||||
dev->id = id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(pnp_register_driver);
|
||||
EXPORT_SYMBOL(pnp_unregister_driver);
|
||||
EXPORT_SYMBOL(pnp_add_id);
|
||||
EXPORT_SYMBOL(pnp_device_attach);
|
||||
EXPORT_SYMBOL(pnp_device_detach);
|
||||
468
drivers/pnp/interface.c
Normal file
468
drivers/pnp/interface.c
Normal file
|
|
@ -0,0 +1,468 @@
|
|||
/*
|
||||
* interface.c - contains everything related to the user interface
|
||||
*
|
||||
* Some code, especially possible resource dumping is based on isapnp_proc.c (c) Jaroslav Kysela <perex@suse.cz>
|
||||
* Copyright 2002 Adam Belay <ambx1@neo.rr.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/pnp.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <linux/slab.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include "base.h"
|
||||
|
||||
struct pnp_info_buffer {
|
||||
char *buffer; /* pointer to begin of buffer */
|
||||
char *curr; /* current position in buffer */
|
||||
unsigned long size; /* current size */
|
||||
unsigned long len; /* total length of buffer */
|
||||
int stop; /* stop flag */
|
||||
int error; /* error code */
|
||||
};
|
||||
|
||||
typedef struct pnp_info_buffer pnp_info_buffer_t;
|
||||
|
||||
static int pnp_printf(pnp_info_buffer_t * buffer, char *fmt,...)
|
||||
{
|
||||
va_list args;
|
||||
int res;
|
||||
|
||||
if (buffer->stop || buffer->error)
|
||||
return 0;
|
||||
va_start(args, fmt);
|
||||
res = vsnprintf(buffer->curr, buffer->len - buffer->size, fmt, args);
|
||||
va_end(args);
|
||||
if (buffer->size + res >= buffer->len) {
|
||||
buffer->stop = 1;
|
||||
return 0;
|
||||
}
|
||||
buffer->curr += res;
|
||||
buffer->size += res;
|
||||
return res;
|
||||
}
|
||||
|
||||
static void pnp_print_port(pnp_info_buffer_t *buffer, char *space, struct pnp_port *port)
|
||||
{
|
||||
pnp_printf(buffer, "%sport 0x%x-0x%x, align 0x%x, size 0x%x, %i-bit address decoding\n",
|
||||
space, port->min, port->max, port->align ? (port->align-1) : 0, port->size,
|
||||
port->flags & PNP_PORT_FLAG_16BITADDR ? 16 : 10);
|
||||
}
|
||||
|
||||
static void pnp_print_irq(pnp_info_buffer_t *buffer, char *space, struct pnp_irq *irq)
|
||||
{
|
||||
int first = 1, i;
|
||||
|
||||
pnp_printf(buffer, "%sirq ", space);
|
||||
for (i = 0; i < PNP_IRQ_NR; i++)
|
||||
if (test_bit(i, irq->map)) {
|
||||
if (!first) {
|
||||
pnp_printf(buffer, ",");
|
||||
} else {
|
||||
first = 0;
|
||||
}
|
||||
if (i == 2 || i == 9)
|
||||
pnp_printf(buffer, "2/9");
|
||||
else
|
||||
pnp_printf(buffer, "%i", i);
|
||||
}
|
||||
if (bitmap_empty(irq->map, PNP_IRQ_NR))
|
||||
pnp_printf(buffer, "<none>");
|
||||
if (irq->flags & IORESOURCE_IRQ_HIGHEDGE)
|
||||
pnp_printf(buffer, " High-Edge");
|
||||
if (irq->flags & IORESOURCE_IRQ_LOWEDGE)
|
||||
pnp_printf(buffer, " Low-Edge");
|
||||
if (irq->flags & IORESOURCE_IRQ_HIGHLEVEL)
|
||||
pnp_printf(buffer, " High-Level");
|
||||
if (irq->flags & IORESOURCE_IRQ_LOWLEVEL)
|
||||
pnp_printf(buffer, " Low-Level");
|
||||
pnp_printf(buffer, "\n");
|
||||
}
|
||||
|
||||
static void pnp_print_dma(pnp_info_buffer_t *buffer, char *space, struct pnp_dma *dma)
|
||||
{
|
||||
int first = 1, i;
|
||||
char *s;
|
||||
|
||||
pnp_printf(buffer, "%sdma ", space);
|
||||
for (i = 0; i < 8; i++)
|
||||
if (dma->map & (1<<i)) {
|
||||
if (!first) {
|
||||
pnp_printf(buffer, ",");
|
||||
} else {
|
||||
first = 0;
|
||||
}
|
||||
pnp_printf(buffer, "%i", i);
|
||||
}
|
||||
if (!dma->map)
|
||||
pnp_printf(buffer, "<none>");
|
||||
switch (dma->flags & IORESOURCE_DMA_TYPE_MASK) {
|
||||
case IORESOURCE_DMA_8BIT:
|
||||
s = "8-bit";
|
||||
break;
|
||||
case IORESOURCE_DMA_8AND16BIT:
|
||||
s = "8-bit&16-bit";
|
||||
break;
|
||||
default:
|
||||
s = "16-bit";
|
||||
}
|
||||
pnp_printf(buffer, " %s", s);
|
||||
if (dma->flags & IORESOURCE_DMA_MASTER)
|
||||
pnp_printf(buffer, " master");
|
||||
if (dma->flags & IORESOURCE_DMA_BYTE)
|
||||
pnp_printf(buffer, " byte-count");
|
||||
if (dma->flags & IORESOURCE_DMA_WORD)
|
||||
pnp_printf(buffer, " word-count");
|
||||
switch (dma->flags & IORESOURCE_DMA_SPEED_MASK) {
|
||||
case IORESOURCE_DMA_TYPEA:
|
||||
s = "type-A";
|
||||
break;
|
||||
case IORESOURCE_DMA_TYPEB:
|
||||
s = "type-B";
|
||||
break;
|
||||
case IORESOURCE_DMA_TYPEF:
|
||||
s = "type-F";
|
||||
break;
|
||||
default:
|
||||
s = "compatible";
|
||||
break;
|
||||
}
|
||||
pnp_printf(buffer, " %s\n", s);
|
||||
}
|
||||
|
||||
static void pnp_print_mem(pnp_info_buffer_t *buffer, char *space, struct pnp_mem *mem)
|
||||
{
|
||||
char *s;
|
||||
|
||||
pnp_printf(buffer, "%sMemory 0x%x-0x%x, align 0x%x, size 0x%x",
|
||||
space, mem->min, mem->max, mem->align, mem->size);
|
||||
if (mem->flags & IORESOURCE_MEM_WRITEABLE)
|
||||
pnp_printf(buffer, ", writeable");
|
||||
if (mem->flags & IORESOURCE_MEM_CACHEABLE)
|
||||
pnp_printf(buffer, ", cacheable");
|
||||
if (mem->flags & IORESOURCE_MEM_RANGELENGTH)
|
||||
pnp_printf(buffer, ", range-length");
|
||||
if (mem->flags & IORESOURCE_MEM_SHADOWABLE)
|
||||
pnp_printf(buffer, ", shadowable");
|
||||
if (mem->flags & IORESOURCE_MEM_EXPANSIONROM)
|
||||
pnp_printf(buffer, ", expansion ROM");
|
||||
switch (mem->flags & IORESOURCE_MEM_TYPE_MASK) {
|
||||
case IORESOURCE_MEM_8BIT:
|
||||
s = "8-bit";
|
||||
break;
|
||||
case IORESOURCE_MEM_8AND16BIT:
|
||||
s = "8-bit&16-bit";
|
||||
break;
|
||||
case IORESOURCE_MEM_32BIT:
|
||||
s = "32-bit";
|
||||
break;
|
||||
default:
|
||||
s = "16-bit";
|
||||
}
|
||||
pnp_printf(buffer, ", %s\n", s);
|
||||
}
|
||||
|
||||
static void pnp_print_option(pnp_info_buffer_t *buffer, char *space,
|
||||
struct pnp_option *option, int dep)
|
||||
{
|
||||
char *s;
|
||||
struct pnp_port *port;
|
||||
struct pnp_irq *irq;
|
||||
struct pnp_dma *dma;
|
||||
struct pnp_mem *mem;
|
||||
|
||||
if (dep) {
|
||||
switch (option->priority) {
|
||||
case PNP_RES_PRIORITY_PREFERRED:
|
||||
s = "preferred";
|
||||
break;
|
||||
case PNP_RES_PRIORITY_ACCEPTABLE:
|
||||
s = "acceptable";
|
||||
break;
|
||||
case PNP_RES_PRIORITY_FUNCTIONAL:
|
||||
s = "functional";
|
||||
break;
|
||||
default:
|
||||
s = "invalid";
|
||||
}
|
||||
pnp_printf(buffer, "Dependent: %02i - Priority %s\n",dep, s);
|
||||
}
|
||||
|
||||
for (port = option->port; port; port = port->next)
|
||||
pnp_print_port(buffer, space, port);
|
||||
for (irq = option->irq; irq; irq = irq->next)
|
||||
pnp_print_irq(buffer, space, irq);
|
||||
for (dma = option->dma; dma; dma = dma->next)
|
||||
pnp_print_dma(buffer, space, dma);
|
||||
for (mem = option->mem; mem; mem = mem->next)
|
||||
pnp_print_mem(buffer, space, mem);
|
||||
}
|
||||
|
||||
|
||||
static ssize_t pnp_show_options(struct device *dmdev, char *buf)
|
||||
{
|
||||
struct pnp_dev *dev = to_pnp_dev(dmdev);
|
||||
struct pnp_option * independent = dev->independent;
|
||||
struct pnp_option * dependent = dev->dependent;
|
||||
int ret, dep = 1;
|
||||
|
||||
pnp_info_buffer_t *buffer = (pnp_info_buffer_t *)
|
||||
pnp_alloc(sizeof(pnp_info_buffer_t));
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
|
||||
buffer->len = PAGE_SIZE;
|
||||
buffer->buffer = buf;
|
||||
buffer->curr = buffer->buffer;
|
||||
if (independent)
|
||||
pnp_print_option(buffer, "", independent, 0);
|
||||
|
||||
while (dependent){
|
||||
pnp_print_option(buffer, " ", dependent, dep);
|
||||
dependent = dependent->next;
|
||||
dep++;
|
||||
}
|
||||
ret = (buffer->curr - buf);
|
||||
kfree(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(options,S_IRUGO,pnp_show_options,NULL);
|
||||
|
||||
|
||||
static ssize_t pnp_show_current_resources(struct device *dmdev, char *buf)
|
||||
{
|
||||
struct pnp_dev *dev = to_pnp_dev(dmdev);
|
||||
int i, ret;
|
||||
pnp_info_buffer_t *buffer;
|
||||
|
||||
if (!dev)
|
||||
return -EINVAL;
|
||||
|
||||
buffer = (pnp_info_buffer_t *) pnp_alloc(sizeof(pnp_info_buffer_t));
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
buffer->len = PAGE_SIZE;
|
||||
buffer->buffer = buf;
|
||||
buffer->curr = buffer->buffer;
|
||||
|
||||
pnp_printf(buffer,"state = ");
|
||||
if (dev->active)
|
||||
pnp_printf(buffer,"active\n");
|
||||
else
|
||||
pnp_printf(buffer,"disabled\n");
|
||||
|
||||
for (i = 0; i < PNP_MAX_PORT; i++) {
|
||||
if (pnp_port_valid(dev, i)) {
|
||||
pnp_printf(buffer,"io");
|
||||
if (pnp_port_flags(dev, i) & IORESOURCE_DISABLED)
|
||||
pnp_printf(buffer," disabled\n");
|
||||
else
|
||||
pnp_printf(buffer," 0x%lx-0x%lx\n",
|
||||
pnp_port_start(dev, i),
|
||||
pnp_port_end(dev, i));
|
||||
}
|
||||
}
|
||||
for (i = 0; i < PNP_MAX_MEM; i++) {
|
||||
if (pnp_mem_valid(dev, i)) {
|
||||
pnp_printf(buffer,"mem");
|
||||
if (pnp_mem_flags(dev, i) & IORESOURCE_DISABLED)
|
||||
pnp_printf(buffer," disabled\n");
|
||||
else
|
||||
pnp_printf(buffer," 0x%lx-0x%lx\n",
|
||||
pnp_mem_start(dev, i),
|
||||
pnp_mem_end(dev, i));
|
||||
}
|
||||
}
|
||||
for (i = 0; i < PNP_MAX_IRQ; i++) {
|
||||
if (pnp_irq_valid(dev, i)) {
|
||||
pnp_printf(buffer,"irq");
|
||||
if (pnp_irq_flags(dev, i) & IORESOURCE_DISABLED)
|
||||
pnp_printf(buffer," disabled\n");
|
||||
else
|
||||
pnp_printf(buffer," %ld\n",
|
||||
pnp_irq(dev, i));
|
||||
}
|
||||
}
|
||||
for (i = 0; i < PNP_MAX_DMA; i++) {
|
||||
if (pnp_dma_valid(dev, i)) {
|
||||
pnp_printf(buffer,"dma");
|
||||
if (pnp_dma_flags(dev, i) & IORESOURCE_DISABLED)
|
||||
pnp_printf(buffer," disabled\n");
|
||||
else
|
||||
pnp_printf(buffer," %ld\n",
|
||||
pnp_dma(dev, i));
|
||||
}
|
||||
}
|
||||
ret = (buffer->curr - buf);
|
||||
kfree(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern struct semaphore pnp_res_mutex;
|
||||
|
||||
static ssize_t
|
||||
pnp_set_current_resources(struct device * dmdev, const char * ubuf, size_t count)
|
||||
{
|
||||
struct pnp_dev *dev = to_pnp_dev(dmdev);
|
||||
char *buf = (void *)ubuf;
|
||||
int retval = 0;
|
||||
|
||||
if (dev->status & PNP_ATTACHED) {
|
||||
retval = -EBUSY;
|
||||
pnp_info("Device %s cannot be configured because it is in use.", dev->dev.bus_id);
|
||||
goto done;
|
||||
}
|
||||
|
||||
while (isspace(*buf))
|
||||
++buf;
|
||||
if (!strnicmp(buf,"disable",7)) {
|
||||
retval = pnp_disable_dev(dev);
|
||||
goto done;
|
||||
}
|
||||
if (!strnicmp(buf,"activate",8)) {
|
||||
retval = pnp_activate_dev(dev);
|
||||
goto done;
|
||||
}
|
||||
if (!strnicmp(buf,"fill",4)) {
|
||||
if (dev->active)
|
||||
goto done;
|
||||
retval = pnp_auto_config_dev(dev);
|
||||
goto done;
|
||||
}
|
||||
if (!strnicmp(buf,"auto",4)) {
|
||||
if (dev->active)
|
||||
goto done;
|
||||
pnp_init_resource_table(&dev->res);
|
||||
retval = pnp_auto_config_dev(dev);
|
||||
goto done;
|
||||
}
|
||||
if (!strnicmp(buf,"clear",5)) {
|
||||
if (dev->active)
|
||||
goto done;
|
||||
pnp_init_resource_table(&dev->res);
|
||||
goto done;
|
||||
}
|
||||
if (!strnicmp(buf,"get",3)) {
|
||||
down(&pnp_res_mutex);
|
||||
if (pnp_can_read(dev))
|
||||
dev->protocol->get(dev, &dev->res);
|
||||
up(&pnp_res_mutex);
|
||||
goto done;
|
||||
}
|
||||
if (!strnicmp(buf,"set",3)) {
|
||||
int nport = 0, nmem = 0, nirq = 0, ndma = 0;
|
||||
if (dev->active)
|
||||
goto done;
|
||||
buf += 3;
|
||||
pnp_init_resource_table(&dev->res);
|
||||
down(&pnp_res_mutex);
|
||||
while (1) {
|
||||
while (isspace(*buf))
|
||||
++buf;
|
||||
if (!strnicmp(buf,"io",2)) {
|
||||
buf += 2;
|
||||
while (isspace(*buf))
|
||||
++buf;
|
||||
dev->res.port_resource[nport].start = simple_strtoul(buf,&buf,0);
|
||||
while (isspace(*buf))
|
||||
++buf;
|
||||
if(*buf == '-') {
|
||||
buf += 1;
|
||||
while (isspace(*buf))
|
||||
++buf;
|
||||
dev->res.port_resource[nport].end = simple_strtoul(buf,&buf,0);
|
||||
} else
|
||||
dev->res.port_resource[nport].end = dev->res.port_resource[nport].start;
|
||||
dev->res.port_resource[nport].flags = IORESOURCE_IO;
|
||||
nport++;
|
||||
if (nport >= PNP_MAX_PORT)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
if (!strnicmp(buf,"mem",3)) {
|
||||
buf += 3;
|
||||
while (isspace(*buf))
|
||||
++buf;
|
||||
dev->res.mem_resource[nmem].start = simple_strtoul(buf,&buf,0);
|
||||
while (isspace(*buf))
|
||||
++buf;
|
||||
if(*buf == '-') {
|
||||
buf += 1;
|
||||
while (isspace(*buf))
|
||||
++buf;
|
||||
dev->res.mem_resource[nmem].end = simple_strtoul(buf,&buf,0);
|
||||
} else
|
||||
dev->res.mem_resource[nmem].end = dev->res.mem_resource[nmem].start;
|
||||
dev->res.mem_resource[nmem].flags = IORESOURCE_MEM;
|
||||
nmem++;
|
||||
if (nmem >= PNP_MAX_MEM)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
if (!strnicmp(buf,"irq",3)) {
|
||||
buf += 3;
|
||||
while (isspace(*buf))
|
||||
++buf;
|
||||
dev->res.irq_resource[nirq].start =
|
||||
dev->res.irq_resource[nirq].end = simple_strtoul(buf,&buf,0);
|
||||
dev->res.irq_resource[nirq].flags = IORESOURCE_IRQ;
|
||||
nirq++;
|
||||
if (nirq >= PNP_MAX_IRQ)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
if (!strnicmp(buf,"dma",3)) {
|
||||
buf += 3;
|
||||
while (isspace(*buf))
|
||||
++buf;
|
||||
dev->res.dma_resource[ndma].start =
|
||||
dev->res.dma_resource[ndma].end = simple_strtoul(buf,&buf,0);
|
||||
dev->res.dma_resource[ndma].flags = IORESOURCE_DMA;
|
||||
ndma++;
|
||||
if (ndma >= PNP_MAX_DMA)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
up(&pnp_res_mutex);
|
||||
goto done;
|
||||
}
|
||||
done:
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
return count;
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(resources,S_IRUGO | S_IWUSR,
|
||||
pnp_show_current_resources,pnp_set_current_resources);
|
||||
|
||||
static ssize_t pnp_show_current_ids(struct device *dmdev, char *buf)
|
||||
{
|
||||
char *str = buf;
|
||||
struct pnp_dev *dev = to_pnp_dev(dmdev);
|
||||
struct pnp_id * pos = dev->id;
|
||||
|
||||
while (pos) {
|
||||
str += sprintf(str,"%s\n", pos->id);
|
||||
pos = pos->next;
|
||||
}
|
||||
return (str - buf);
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(id,S_IRUGO,pnp_show_current_ids,NULL);
|
||||
|
||||
int pnp_interface_attach_device(struct pnp_dev *dev)
|
||||
{
|
||||
device_create_file(&dev->dev,&dev_attr_options);
|
||||
device_create_file(&dev->dev,&dev_attr_resources);
|
||||
device_create_file(&dev->dev,&dev_attr_id);
|
||||
return 0;
|
||||
}
|
||||
11
drivers/pnp/isapnp/Kconfig
Normal file
11
drivers/pnp/isapnp/Kconfig
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#
|
||||
# ISA Plug and Play configuration
|
||||
#
|
||||
config ISAPNP
|
||||
bool "ISA Plug and Play support"
|
||||
depends on PNP && ISA
|
||||
help
|
||||
Say Y here if you would like support for ISA Plug and Play devices.
|
||||
Some information is in <file:Documentation/isapnp.txt>.
|
||||
|
||||
If unsure, say Y.
|
||||
7
drivers/pnp/isapnp/Makefile
Normal file
7
drivers/pnp/isapnp/Makefile
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
# Makefile for the kernel ISAPNP driver.
|
||||
#
|
||||
|
||||
isapnp-proc-$(CONFIG_PROC_FS) = proc.o
|
||||
|
||||
obj-y := core.o compat.o $(isapnp-proc-y)
|
||||
91
drivers/pnp/isapnp/compat.c
Normal file
91
drivers/pnp/isapnp/compat.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* compat.c - A series of functions to make it easier to convert drivers that use
|
||||
* the old isapnp APIs. If possible use the new APIs instead.
|
||||
*
|
||||
* Copyright 2002 Adam Belay <ambx1@neo.rr.com>
|
||||
*
|
||||
*/
|
||||
|
||||
/* TODO: see if more isapnp functions are needed here */
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/isapnp.h>
|
||||
#include <linux/string.h>
|
||||
|
||||
static void pnp_convert_id(char *buf, unsigned short vendor, unsigned short device)
|
||||
{
|
||||
sprintf(buf, "%c%c%c%x%x%x%x",
|
||||
'A' + ((vendor >> 2) & 0x3f) - 1,
|
||||
'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
|
||||
'A' + ((vendor >> 8) & 0x1f) - 1,
|
||||
(device >> 4) & 0x0f,
|
||||
device & 0x0f,
|
||||
(device >> 12) & 0x0f,
|
||||
(device >> 8) & 0x0f);
|
||||
}
|
||||
|
||||
struct pnp_card *pnp_find_card(unsigned short vendor,
|
||||
unsigned short device,
|
||||
struct pnp_card *from)
|
||||
{
|
||||
char id[8];
|
||||
char any[8];
|
||||
struct list_head *list;
|
||||
pnp_convert_id(id, vendor, device);
|
||||
pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID);
|
||||
|
||||
list = from ? from->global_list.next : pnp_cards.next;
|
||||
|
||||
while (list != &pnp_cards) {
|
||||
struct pnp_card *card = global_to_pnp_card(list);
|
||||
if (compare_pnp_id(card->id,id) || (memcmp(id,any,7)==0))
|
||||
return card;
|
||||
list = list->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct pnp_dev *pnp_find_dev(struct pnp_card *card,
|
||||
unsigned short vendor,
|
||||
unsigned short function,
|
||||
struct pnp_dev *from)
|
||||
{
|
||||
char id[8];
|
||||
char any[8];
|
||||
pnp_convert_id(id, vendor, function);
|
||||
pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID);
|
||||
if (card == NULL) { /* look for a logical device from all cards */
|
||||
struct list_head *list;
|
||||
|
||||
list = pnp_global.next;
|
||||
if (from)
|
||||
list = from->global_list.next;
|
||||
|
||||
while (list != &pnp_global) {
|
||||
struct pnp_dev *dev = global_to_pnp_dev(list);
|
||||
if (compare_pnp_id(dev->id,id) || (memcmp(id,any,7)==0))
|
||||
return dev;
|
||||
list = list->next;
|
||||
}
|
||||
} else {
|
||||
struct list_head *list;
|
||||
|
||||
list = card->devices.next;
|
||||
if (from) {
|
||||
list = from->card_list.next;
|
||||
if (from->card != card) /* something is wrong */
|
||||
return NULL;
|
||||
}
|
||||
while (list != &card->devices) {
|
||||
struct pnp_dev *dev = card_to_pnp_dev(list);
|
||||
if (compare_pnp_id(dev->id,id))
|
||||
return dev;
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(pnp_find_card);
|
||||
EXPORT_SYMBOL(pnp_find_dev);
|
||||
1156
drivers/pnp/isapnp/core.c
Normal file
1156
drivers/pnp/isapnp/core.c
Normal file
File diff suppressed because it is too large
Load diff
171
drivers/pnp/isapnp/proc.c
Normal file
171
drivers/pnp/isapnp/proc.c
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* ISA Plug & Play support
|
||||
* Copyright (c) by Jaroslav Kysela <perex@suse.cz>
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/module.h>
|
||||
#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;
|
||||
|
||||
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;
|
||||
|
||||
lock_kernel();
|
||||
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) {
|
||||
unlock_kernel();
|
||||
return -EINVAL;
|
||||
}
|
||||
unlock_kernel();
|
||||
return (file->f_pos = new);
|
||||
}
|
||||
|
||||
static ssize_t isapnp_proc_bus_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
|
||||
{
|
||||
struct inode *ino = file->f_dentry->d_inode;
|
||||
struct proc_dir_entry *dp = PDE(ino);
|
||||
struct pnp_dev *dev = dp->data;
|
||||
int pos = *ppos;
|
||||
int cnt, size = 256;
|
||||
|
||||
if (pos >= size)
|
||||
return 0;
|
||||
if (nbytes >= size)
|
||||
nbytes = size;
|
||||
if (pos + nbytes > size)
|
||||
nbytes = size - pos;
|
||||
cnt = nbytes;
|
||||
|
||||
if (!access_ok(VERIFY_WRITE, buf, cnt))
|
||||
return -EINVAL;
|
||||
|
||||
isapnp_cfg_begin(dev->card->number, dev->number);
|
||||
for ( ; pos < 256 && cnt > 0; pos++, buf++, cnt--) {
|
||||
unsigned char val;
|
||||
val = isapnp_read_byte(pos);
|
||||
__put_user(val, buf);
|
||||
}
|
||||
isapnp_cfg_end();
|
||||
|
||||
*ppos = pos;
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
static struct file_operations isapnp_proc_bus_file_operations =
|
||||
{
|
||||
.llseek = isapnp_proc_bus_lseek,
|
||||
.read = isapnp_proc_bus_read,
|
||||
};
|
||||
|
||||
static int isapnp_proc_attach_device(struct pnp_dev *dev)
|
||||
{
|
||||
struct pnp_card *bus = dev->card;
|
||||
struct proc_dir_entry *de, *e;
|
||||
char name[16];
|
||||
|
||||
if (!(de = bus->procdir)) {
|
||||
sprintf(name, "%02x", bus->number);
|
||||
de = bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir);
|
||||
if (!de)
|
||||
return -ENOMEM;
|
||||
}
|
||||
sprintf(name, "%02x", dev->number);
|
||||
e = dev->procent = create_proc_entry(name, S_IFREG | S_IRUGO, de);
|
||||
if (!e)
|
||||
return -ENOMEM;
|
||||
e->proc_fops = &isapnp_proc_bus_file_operations;
|
||||
e->owner = THIS_MODULE;
|
||||
e->data = dev;
|
||||
e->size = 256;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef MODULE
|
||||
static int __exit isapnp_proc_detach_device(struct pnp_dev *dev)
|
||||
{
|
||||
struct pnp_card *bus = dev->card;
|
||||
struct proc_dir_entry *de;
|
||||
char name[16];
|
||||
|
||||
if (!(de = bus->procdir))
|
||||
return -EINVAL;
|
||||
sprintf(name, "%02x", dev->number);
|
||||
remove_proc_entry(name, de);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __exit isapnp_proc_detach_bus(struct pnp_card *bus)
|
||||
{
|
||||
struct proc_dir_entry *de;
|
||||
char name[16];
|
||||
|
||||
if (!(de = bus->procdir))
|
||||
return -EINVAL;
|
||||
sprintf(name, "%02x", bus->number);
|
||||
remove_proc_entry(name, isapnp_proc_bus_dir);
|
||||
return 0;
|
||||
}
|
||||
#endif /* MODULE */
|
||||
|
||||
int __init isapnp_proc_init(void)
|
||||
{
|
||||
struct pnp_dev *dev;
|
||||
isapnp_proc_bus_dir = proc_mkdir("isapnp", proc_bus);
|
||||
protocol_for_each_dev(&isapnp_protocol,dev) {
|
||||
isapnp_proc_attach_device(dev);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef MODULE
|
||||
int __exit isapnp_proc_done(void)
|
||||
{
|
||||
struct pnp_dev *dev;
|
||||
struct pnp_bus *card;
|
||||
|
||||
isapnp_for_each_dev(dev) {
|
||||
isapnp_proc_detach_device(dev);
|
||||
}
|
||||
isapnp_for_each_card(card) {
|
||||
isapnp_proc_detach_bus(card);
|
||||
}
|
||||
if (isapnp_proc_bus_dir)
|
||||
remove_proc_entry("isapnp", proc_bus);
|
||||
return 0;
|
||||
}
|
||||
#endif /* MODULE */
|
||||
566
drivers/pnp/manager.c
Normal file
566
drivers/pnp/manager.c
Normal file
|
|
@ -0,0 +1,566 @@
|
|||
/*
|
||||
* manager.c - Resource Management, Conflict Resolution, Activation and Disabling of Devices
|
||||
*
|
||||
* based on isapnp.c resource management (c) Jaroslav Kysela <perex@suse.cz>
|
||||
* Copyright 2003 Adam Belay <ambx1@neo.rr.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
#ifdef CONFIG_PNP_DEBUG
|
||||
#define DEBUG
|
||||
#else
|
||||
#undef DEBUG
|
||||
#endif
|
||||
|
||||
#include <linux/pnp.h>
|
||||
#include "base.h"
|
||||
|
||||
DECLARE_MUTEX(pnp_res_mutex);
|
||||
|
||||
static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
|
||||
{
|
||||
unsigned long *start, *end, *flags;
|
||||
|
||||
if (!dev || !rule)
|
||||
return -EINVAL;
|
||||
|
||||
if (idx >= PNP_MAX_PORT) {
|
||||
pnp_err("More than 4 ports is incompatible with pnp specifications.");
|
||||
/* pretend we were successful so at least the manager won't try again */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* check if this resource has been manually set, if so skip */
|
||||
if (!(dev->res.port_resource[idx].flags & IORESOURCE_AUTO))
|
||||
return 1;
|
||||
|
||||
start = &dev->res.port_resource[idx].start;
|
||||
end = &dev->res.port_resource[idx].end;
|
||||
flags = &dev->res.port_resource[idx].flags;
|
||||
|
||||
/* set the initial values */
|
||||
*flags |= rule->flags | IORESOURCE_IO;
|
||||
*flags &= ~IORESOURCE_UNSET;
|
||||
|
||||
if (!rule->size) {
|
||||
*flags |= IORESOURCE_DISABLED;
|
||||
return 1; /* skip disabled resource requests */
|
||||
}
|
||||
|
||||
*start = rule->min;
|
||||
*end = *start + rule->size - 1;
|
||||
|
||||
/* run through until pnp_check_port is happy */
|
||||
while (!pnp_check_port(dev, idx)) {
|
||||
*start += rule->align;
|
||||
*end = *start + rule->size - 1;
|
||||
if (*start > rule->max || !rule->align)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
|
||||
{
|
||||
unsigned long *start, *end, *flags;
|
||||
|
||||
if (!dev || !rule)
|
||||
return -EINVAL;
|
||||
|
||||
if (idx >= PNP_MAX_MEM) {
|
||||
pnp_err("More than 8 mems is incompatible with pnp specifications.");
|
||||
/* pretend we were successful so at least the manager won't try again */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* check if this resource has been manually set, if so skip */
|
||||
if (!(dev->res.mem_resource[idx].flags & IORESOURCE_AUTO))
|
||||
return 1;
|
||||
|
||||
start = &dev->res.mem_resource[idx].start;
|
||||
end = &dev->res.mem_resource[idx].end;
|
||||
flags = &dev->res.mem_resource[idx].flags;
|
||||
|
||||
/* set the initial values */
|
||||
*flags |= rule->flags | IORESOURCE_MEM;
|
||||
*flags &= ~IORESOURCE_UNSET;
|
||||
|
||||
/* convert pnp flags to standard Linux flags */
|
||||
if (!(rule->flags & IORESOURCE_MEM_WRITEABLE))
|
||||
*flags |= IORESOURCE_READONLY;
|
||||
if (rule->flags & IORESOURCE_MEM_CACHEABLE)
|
||||
*flags |= IORESOURCE_CACHEABLE;
|
||||
if (rule->flags & IORESOURCE_MEM_RANGELENGTH)
|
||||
*flags |= IORESOURCE_RANGELENGTH;
|
||||
if (rule->flags & IORESOURCE_MEM_SHADOWABLE)
|
||||
*flags |= IORESOURCE_SHADOWABLE;
|
||||
|
||||
if (!rule->size) {
|
||||
*flags |= IORESOURCE_DISABLED;
|
||||
return 1; /* skip disabled resource requests */
|
||||
}
|
||||
|
||||
*start = rule->min;
|
||||
*end = *start + rule->size -1;
|
||||
|
||||
/* run through until pnp_check_mem is happy */
|
||||
while (!pnp_check_mem(dev, idx)) {
|
||||
*start += rule->align;
|
||||
*end = *start + rule->size - 1;
|
||||
if (*start > rule->max || !rule->align)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pnp_assign_irq(struct pnp_dev * dev, struct pnp_irq *rule, int idx)
|
||||
{
|
||||
unsigned long *start, *end, *flags;
|
||||
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
|
||||
};
|
||||
|
||||
if (!dev || !rule)
|
||||
return -EINVAL;
|
||||
|
||||
if (idx >= PNP_MAX_IRQ) {
|
||||
pnp_err("More than 2 irqs is incompatible with pnp specifications.");
|
||||
/* pretend we were successful so at least the manager won't try again */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* check if this resource has been manually set, if so skip */
|
||||
if (!(dev->res.irq_resource[idx].flags & IORESOURCE_AUTO))
|
||||
return 1;
|
||||
|
||||
start = &dev->res.irq_resource[idx].start;
|
||||
end = &dev->res.irq_resource[idx].end;
|
||||
flags = &dev->res.irq_resource[idx].flags;
|
||||
|
||||
/* set the initial values */
|
||||
*flags |= rule->flags | IORESOURCE_IRQ;
|
||||
*flags &= ~IORESOURCE_UNSET;
|
||||
|
||||
if (bitmap_empty(rule->map, PNP_IRQ_NR)) {
|
||||
*flags |= IORESOURCE_DISABLED;
|
||||
return 1; /* skip disabled resource requests */
|
||||
}
|
||||
|
||||
/* TBD: need check for >16 IRQ */
|
||||
*start = find_next_bit(rule->map, PNP_IRQ_NR, 16);
|
||||
if (*start < PNP_IRQ_NR) {
|
||||
*end = *start;
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < 16; i++) {
|
||||
if(test_bit(xtab[i], rule->map)) {
|
||||
*start = *end = xtab[i];
|
||||
if(pnp_check_irq(dev, idx))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
|
||||
{
|
||||
unsigned long *start, *end, *flags;
|
||||
int i;
|
||||
|
||||
/* DMA priority: this table is good for i386 */
|
||||
static unsigned short xtab[8] = {
|
||||
1, 3, 5, 6, 7, 0, 2, 4
|
||||
};
|
||||
|
||||
if (!dev || !rule)
|
||||
return -EINVAL;
|
||||
|
||||
if (idx >= PNP_MAX_DMA) {
|
||||
pnp_err("More than 2 dmas is incompatible with pnp specifications.");
|
||||
/* pretend we were successful so at least the manager won't try again */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* check if this resource has been manually set, if so skip */
|
||||
if (!(dev->res.dma_resource[idx].flags & IORESOURCE_AUTO))
|
||||
return 1;
|
||||
|
||||
start = &dev->res.dma_resource[idx].start;
|
||||
end = &dev->res.dma_resource[idx].end;
|
||||
flags = &dev->res.dma_resource[idx].flags;
|
||||
|
||||
/* set the initial values */
|
||||
*flags |= rule->flags | IORESOURCE_DMA;
|
||||
*flags &= ~IORESOURCE_UNSET;
|
||||
|
||||
if (!rule->map) {
|
||||
*flags |= IORESOURCE_DISABLED;
|
||||
return 1; /* skip disabled resource requests */
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if(rule->map & (1<<xtab[i])) {
|
||||
*start = *end = xtab[i];
|
||||
if(pnp_check_dma(dev, idx))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_init_resources - Resets a resource table to default values.
|
||||
* @table: pointer to the desired resource table
|
||||
*
|
||||
*/
|
||||
void pnp_init_resource_table(struct pnp_resource_table *table)
|
||||
{
|
||||
int idx;
|
||||
for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
|
||||
table->irq_resource[idx].name = NULL;
|
||||
table->irq_resource[idx].start = -1;
|
||||
table->irq_resource[idx].end = -1;
|
||||
table->irq_resource[idx].flags = IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
|
||||
}
|
||||
for (idx = 0; idx < PNP_MAX_DMA; idx++) {
|
||||
table->dma_resource[idx].name = NULL;
|
||||
table->dma_resource[idx].start = -1;
|
||||
table->dma_resource[idx].end = -1;
|
||||
table->dma_resource[idx].flags = IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
|
||||
}
|
||||
for (idx = 0; idx < PNP_MAX_PORT; idx++) {
|
||||
table->port_resource[idx].name = NULL;
|
||||
table->port_resource[idx].start = 0;
|
||||
table->port_resource[idx].end = 0;
|
||||
table->port_resource[idx].flags = IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
|
||||
}
|
||||
for (idx = 0; idx < PNP_MAX_MEM; idx++) {
|
||||
table->mem_resource[idx].name = NULL;
|
||||
table->mem_resource[idx].start = 0;
|
||||
table->mem_resource[idx].end = 0;
|
||||
table->mem_resource[idx].flags = IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_clean_resources - clears resources that were not manually set
|
||||
* @res - the resources to clean
|
||||
*
|
||||
*/
|
||||
static void pnp_clean_resource_table(struct pnp_resource_table * res)
|
||||
{
|
||||
int idx;
|
||||
for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
|
||||
if (!(res->irq_resource[idx].flags & IORESOURCE_AUTO))
|
||||
continue;
|
||||
res->irq_resource[idx].start = -1;
|
||||
res->irq_resource[idx].end = -1;
|
||||
res->irq_resource[idx].flags = IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
|
||||
}
|
||||
for (idx = 0; idx < PNP_MAX_DMA; idx++) {
|
||||
if (!(res->dma_resource[idx].flags & IORESOURCE_AUTO))
|
||||
continue;
|
||||
res->dma_resource[idx].start = -1;
|
||||
res->dma_resource[idx].end = -1;
|
||||
res->dma_resource[idx].flags = IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
|
||||
}
|
||||
for (idx = 0; idx < PNP_MAX_PORT; idx++) {
|
||||
if (!(res->port_resource[idx].flags & IORESOURCE_AUTO))
|
||||
continue;
|
||||
res->port_resource[idx].start = 0;
|
||||
res->port_resource[idx].end = 0;
|
||||
res->port_resource[idx].flags = IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
|
||||
}
|
||||
for (idx = 0; idx < PNP_MAX_MEM; idx++) {
|
||||
if (!(res->mem_resource[idx].flags & IORESOURCE_AUTO))
|
||||
continue;
|
||||
res->mem_resource[idx].start = 0;
|
||||
res->mem_resource[idx].end = 0;
|
||||
res->mem_resource[idx].flags = IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_assign_resources - assigns resources to the device based on the specified dependent number
|
||||
* @dev: pointer to the desired device
|
||||
* @depnum: the dependent function number
|
||||
*
|
||||
* Only set depnum to 0 if the device does not have dependent options.
|
||||
*/
|
||||
static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
|
||||
{
|
||||
struct pnp_port *port;
|
||||
struct pnp_mem *mem;
|
||||
struct pnp_irq *irq;
|
||||
struct pnp_dma *dma;
|
||||
int nport = 0, nmem = 0, nirq = 0, ndma = 0;
|
||||
|
||||
if (!pnp_can_configure(dev))
|
||||
return -ENODEV;
|
||||
|
||||
down(&pnp_res_mutex);
|
||||
pnp_clean_resource_table(&dev->res); /* start with a fresh slate */
|
||||
if (dev->independent) {
|
||||
port = dev->independent->port;
|
||||
mem = dev->independent->mem;
|
||||
irq = dev->independent->irq;
|
||||
dma = dev->independent->dma;
|
||||
while (port) {
|
||||
if (!pnp_assign_port(dev, port, nport))
|
||||
goto fail;
|
||||
nport++;
|
||||
port = port->next;
|
||||
}
|
||||
while (mem) {
|
||||
if (!pnp_assign_mem(dev, mem, nmem))
|
||||
goto fail;
|
||||
nmem++;
|
||||
mem = mem->next;
|
||||
}
|
||||
while (irq) {
|
||||
if (!pnp_assign_irq(dev, irq, nirq))
|
||||
goto fail;
|
||||
nirq++;
|
||||
irq = irq->next;
|
||||
}
|
||||
while (dma) {
|
||||
if (!pnp_assign_dma(dev, dma, ndma))
|
||||
goto fail;
|
||||
ndma++;
|
||||
dma = dma->next;
|
||||
}
|
||||
}
|
||||
|
||||
if (depnum) {
|
||||
struct pnp_option *dep;
|
||||
int i;
|
||||
for (i=1,dep=dev->dependent; i<depnum; i++, dep=dep->next)
|
||||
if(!dep)
|
||||
goto fail;
|
||||
port =dep->port;
|
||||
mem = dep->mem;
|
||||
irq = dep->irq;
|
||||
dma = dep->dma;
|
||||
while (port) {
|
||||
if (!pnp_assign_port(dev, port, nport))
|
||||
goto fail;
|
||||
nport++;
|
||||
port = port->next;
|
||||
}
|
||||
while (mem) {
|
||||
if (!pnp_assign_mem(dev, mem, nmem))
|
||||
goto fail;
|
||||
nmem++;
|
||||
mem = mem->next;
|
||||
}
|
||||
while (irq) {
|
||||
if (!pnp_assign_irq(dev, irq, nirq))
|
||||
goto fail;
|
||||
nirq++;
|
||||
irq = irq->next;
|
||||
}
|
||||
while (dma) {
|
||||
if (!pnp_assign_dma(dev, dma, ndma))
|
||||
goto fail;
|
||||
ndma++;
|
||||
dma = dma->next;
|
||||
}
|
||||
} else if (dev->dependent)
|
||||
goto fail;
|
||||
|
||||
up(&pnp_res_mutex);
|
||||
return 1;
|
||||
|
||||
fail:
|
||||
pnp_clean_resource_table(&dev->res);
|
||||
up(&pnp_res_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_manual_config_dev - Disables Auto Config and Manually sets the resource table
|
||||
* @dev: pointer to the desired device
|
||||
* @res: pointer to the new resource config
|
||||
*
|
||||
* This function can be used by drivers that want to manually set thier resources.
|
||||
*/
|
||||
int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table * res, int mode)
|
||||
{
|
||||
int i;
|
||||
struct pnp_resource_table * bak;
|
||||
if (!dev || !res)
|
||||
return -EINVAL;
|
||||
if (!pnp_can_configure(dev))
|
||||
return -ENODEV;
|
||||
bak = pnp_alloc(sizeof(struct pnp_resource_table));
|
||||
if (!bak)
|
||||
return -ENOMEM;
|
||||
*bak = dev->res;
|
||||
|
||||
down(&pnp_res_mutex);
|
||||
dev->res = *res;
|
||||
if (!(mode & PNP_CONFIG_FORCE)) {
|
||||
for (i = 0; i < PNP_MAX_PORT; i++) {
|
||||
if(!pnp_check_port(dev,i))
|
||||
goto fail;
|
||||
}
|
||||
for (i = 0; i < PNP_MAX_MEM; i++) {
|
||||
if(!pnp_check_mem(dev,i))
|
||||
goto fail;
|
||||
}
|
||||
for (i = 0; i < PNP_MAX_IRQ; i++) {
|
||||
if(!pnp_check_irq(dev,i))
|
||||
goto fail;
|
||||
}
|
||||
for (i = 0; i < PNP_MAX_DMA; i++) {
|
||||
if(!pnp_check_dma(dev,i))
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
up(&pnp_res_mutex);
|
||||
|
||||
kfree(bak);
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
dev->res = *bak;
|
||||
up(&pnp_res_mutex);
|
||||
kfree(bak);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
struct pnp_option *dep;
|
||||
int i = 1;
|
||||
|
||||
if(!dev)
|
||||
return -EINVAL;
|
||||
|
||||
if(!pnp_can_configure(dev)) {
|
||||
pnp_info("Device %s does not support resource configuration.", dev->dev.bus_id);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (!dev->dependent) {
|
||||
if (pnp_assign_resources(dev, 0))
|
||||
return 0;
|
||||
} else {
|
||||
dep = dev->dependent;
|
||||
do {
|
||||
if (pnp_assign_resources(dev, i))
|
||||
return 0;
|
||||
dep = dep->next;
|
||||
i++;
|
||||
} while (dep);
|
||||
}
|
||||
|
||||
pnp_err("Unable to assign resources to device %s.", dev->dev.bus_id);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (!dev)
|
||||
return -EINVAL;
|
||||
if (dev->active) {
|
||||
return 0; /* the device is already active */
|
||||
}
|
||||
|
||||
/* ensure resources are allocated */
|
||||
if (pnp_auto_config_dev(dev))
|
||||
return -EBUSY;
|
||||
|
||||
if (!pnp_can_write(dev)) {
|
||||
pnp_info("Device %s does not supported activation.", dev->dev.bus_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (dev->protocol->set(dev, &dev->res)<0) {
|
||||
pnp_err("Failed to activate device %s.", dev->dev.bus_id);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
dev->active = 1;
|
||||
pnp_info("Device %s activated.", dev->dev.bus_id);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (!dev)
|
||||
return -EINVAL;
|
||||
if (!dev->active) {
|
||||
return 0; /* the device is already disabled */
|
||||
}
|
||||
|
||||
if (!pnp_can_disable(dev)) {
|
||||
pnp_info("Device %s does not supported disabling.", dev->dev.bus_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (dev->protocol->disable(dev)<0) {
|
||||
pnp_err("Failed to disable device %s.", dev->dev.bus_id);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
dev->active = 0;
|
||||
pnp_info("Device %s disabled.", dev->dev.bus_id);
|
||||
|
||||
/* release the resources so that other devices can use them */
|
||||
down(&pnp_res_mutex);
|
||||
pnp_clean_resource_table(&dev->res);
|
||||
up(&pnp_res_mutex);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* pnp_resource_change - change one resource
|
||||
* @resource: pointer to resource to be changed
|
||||
* @start: start of region
|
||||
* @size: size of region
|
||||
*
|
||||
*/
|
||||
void pnp_resource_change(struct resource *resource, unsigned long start, unsigned long size)
|
||||
{
|
||||
if (resource == NULL)
|
||||
return;
|
||||
resource->flags &= ~(IORESOURCE_AUTO | IORESOURCE_UNSET);
|
||||
resource->start = start;
|
||||
resource->end = start + size - 1;
|
||||
}
|
||||
|
||||
|
||||
EXPORT_SYMBOL(pnp_manual_config_dev);
|
||||
EXPORT_SYMBOL(pnp_auto_config_dev);
|
||||
EXPORT_SYMBOL(pnp_activate_dev);
|
||||
EXPORT_SYMBOL(pnp_disable_dev);
|
||||
EXPORT_SYMBOL(pnp_resource_change);
|
||||
EXPORT_SYMBOL(pnp_init_resource_table);
|
||||
18
drivers/pnp/pnpacpi/Kconfig
Normal file
18
drivers/pnp/pnpacpi/Kconfig
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# Plug and Play ACPI configuration
|
||||
#
|
||||
config PNPACPI
|
||||
bool "Plug and Play ACPI support (EXPERIMENTAL)"
|
||||
depends on PNP && ACPI_BUS && EXPERIMENTAL
|
||||
default y
|
||||
---help---
|
||||
Linux uses the PNPACPI to autodetect built-in
|
||||
mainboard resources (e.g. parallel port resources).
|
||||
|
||||
Some features (e.g. real hotplug) are not currently
|
||||
implemented.
|
||||
|
||||
If you would like the kernel to detect and allocate resources to
|
||||
your mainboard devices (on some systems they are disabled by the
|
||||
BIOS) say Y here. Also the PNPACPI can help prevent resource
|
||||
conflicts between mainboard devices and other bus devices.
|
||||
5
drivers/pnp/pnpacpi/Makefile
Normal file
5
drivers/pnp/pnpacpi/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#
|
||||
# Makefile for the kernel PNPACPI driver.
|
||||
#
|
||||
|
||||
obj-y := core.o rsparser.o
|
||||
269
drivers/pnp/pnpacpi/core.c
Normal file
269
drivers/pnp/pnpacpi/core.c
Normal file
|
|
@ -0,0 +1,269 @@
|
|||
/*
|
||||
* pnpacpi -- PnP ACPI driver
|
||||
*
|
||||
* Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr>
|
||||
* Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/pnp.h>
|
||||
#include <acpi/acpi_bus.h>
|
||||
#include "pnpacpi.h"
|
||||
|
||||
static int num = 0;
|
||||
|
||||
static char __initdata excluded_id_list[] =
|
||||
"PNP0C0A," /* Battery */
|
||||
"PNP0C0C,PNP0C0E,PNP0C0D," /* Button */
|
||||
"PNP0C09," /* EC */
|
||||
"PNP0C0B," /* Fan */
|
||||
"PNP0A03," /* PCI root */
|
||||
"PNP0C0F," /* Link device */
|
||||
"PNP0000," /* PIC */
|
||||
"PNP0100," /* Timer */
|
||||
;
|
||||
static inline int is_exclusive_device(struct acpi_device *dev)
|
||||
{
|
||||
return (!acpi_match_ids(dev, excluded_id_list));
|
||||
}
|
||||
|
||||
void *pnpacpi_kmalloc(size_t size, int f)
|
||||
{
|
||||
void *p = kmalloc(size, f);
|
||||
if (p)
|
||||
memset(p, 0, size);
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compatible Device IDs
|
||||
*/
|
||||
#define TEST_HEX(c) \
|
||||
if (!(('0' <= (c) && (c) <= '9') || ('A' <= (c) && (c) <= 'F'))) \
|
||||
return 0
|
||||
#define TEST_ALPHA(c) \
|
||||
if (!('@' <= (c) || (c) <= 'Z')) \
|
||||
return 0
|
||||
static int __init ispnpidacpi(char *id)
|
||||
{
|
||||
TEST_ALPHA(id[0]);
|
||||
TEST_ALPHA(id[1]);
|
||||
TEST_ALPHA(id[2]);
|
||||
TEST_HEX(id[3]);
|
||||
TEST_HEX(id[4]);
|
||||
TEST_HEX(id[5]);
|
||||
TEST_HEX(id[6]);
|
||||
if (id[7] != '\0')
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void __init pnpidacpi_to_pnpid(char *id, char *str)
|
||||
{
|
||||
str[0] = id[0];
|
||||
str[1] = id[1];
|
||||
str[2] = id[2];
|
||||
str[3] = tolower(id[3]);
|
||||
str[4] = tolower(id[4]);
|
||||
str[5] = tolower(id[5]);
|
||||
str[6] = tolower(id[6]);
|
||||
str[7] = '\0';
|
||||
}
|
||||
|
||||
static int pnpacpi_get_resources(struct pnp_dev * dev, struct pnp_resource_table * res)
|
||||
{
|
||||
acpi_status status;
|
||||
status = pnpacpi_parse_allocated_resource((acpi_handle)dev->data,
|
||||
&dev->res);
|
||||
return ACPI_FAILURE(status) ? -ENODEV : 0;
|
||||
}
|
||||
|
||||
static int pnpacpi_set_resources(struct pnp_dev * dev, struct pnp_resource_table * res)
|
||||
{
|
||||
acpi_handle handle = dev->data;
|
||||
struct acpi_buffer buffer;
|
||||
int ret = 0;
|
||||
acpi_status status;
|
||||
|
||||
ret = pnpacpi_build_resource_template(handle, &buffer);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = pnpacpi_encode_resources(res, &buffer);
|
||||
if (ret) {
|
||||
kfree(buffer.pointer);
|
||||
return ret;
|
||||
}
|
||||
status = acpi_set_current_resources(handle, &buffer);
|
||||
if (ACPI_FAILURE(status))
|
||||
ret = -EINVAL;
|
||||
kfree(buffer.pointer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int pnpacpi_disable_resources(struct pnp_dev *dev)
|
||||
{
|
||||
acpi_status status;
|
||||
|
||||
/* acpi_unregister_gsi(pnp_irq(dev, 0)); */
|
||||
status = acpi_evaluate_object((acpi_handle)dev->data,
|
||||
"_DIS", NULL, NULL);
|
||||
return ACPI_FAILURE(status) ? -ENODEV : 0;
|
||||
}
|
||||
|
||||
struct pnp_protocol pnpacpi_protocol = {
|
||||
.name = "Plug and Play ACPI",
|
||||
.get = pnpacpi_get_resources,
|
||||
.set = pnpacpi_set_resources,
|
||||
.disable = pnpacpi_disable_resources,
|
||||
};
|
||||
|
||||
static int __init pnpacpi_add_device(struct acpi_device *device)
|
||||
{
|
||||
acpi_handle temp = NULL;
|
||||
acpi_status status;
|
||||
struct pnp_id *dev_id;
|
||||
struct pnp_dev *dev;
|
||||
|
||||
if (!ispnpidacpi(acpi_device_hid(device)) ||
|
||||
is_exclusive_device(device))
|
||||
return 0;
|
||||
|
||||
pnp_dbg("ACPI device : hid %s", acpi_device_hid(device));
|
||||
dev = pnpacpi_kmalloc(sizeof(struct pnp_dev), GFP_KERNEL);
|
||||
if (!dev) {
|
||||
pnp_err("Out of memory");
|
||||
return -ENOMEM;
|
||||
}
|
||||
dev->data = device->handle;
|
||||
/* .enabled means if the device can decode the resources */
|
||||
dev->active = device->status.enabled;
|
||||
status = acpi_get_handle(device->handle, "_SRS", &temp);
|
||||
if (ACPI_SUCCESS(status))
|
||||
dev->capabilities |= PNP_CONFIGURABLE;
|
||||
dev->capabilities |= PNP_READ;
|
||||
if (device->flags.dynamic_status)
|
||||
dev->capabilities |= PNP_WRITE;
|
||||
if (device->flags.removable)
|
||||
dev->capabilities |= PNP_REMOVABLE;
|
||||
status = acpi_get_handle(device->handle, "_DIS", &temp);
|
||||
if (ACPI_SUCCESS(status))
|
||||
dev->capabilities |= PNP_DISABLE;
|
||||
|
||||
dev->protocol = &pnpacpi_protocol;
|
||||
|
||||
if (strlen(acpi_device_name(device)))
|
||||
strncpy(dev->name, acpi_device_name(device), sizeof(dev->name));
|
||||
else
|
||||
strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
|
||||
|
||||
dev->number = num;
|
||||
|
||||
/* set the initial values for the PnP device */
|
||||
dev_id = pnpacpi_kmalloc(sizeof(struct pnp_id), GFP_KERNEL);
|
||||
if (!dev_id)
|
||||
goto err;
|
||||
pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id);
|
||||
pnp_add_id(dev_id, dev);
|
||||
|
||||
if(dev->active) {
|
||||
/* parse allocated resource */
|
||||
status = pnpacpi_parse_allocated_resource(device->handle, &dev->res);
|
||||
if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
|
||||
pnp_err("PnPACPI: METHOD_NAME__CRS failure for %s", dev_id->id);
|
||||
goto err1;
|
||||
}
|
||||
}
|
||||
|
||||
if(dev->capabilities & PNP_CONFIGURABLE) {
|
||||
status = pnpacpi_parse_resource_option_data(device->handle,
|
||||
dev);
|
||||
if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
|
||||
pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s", dev_id->id);
|
||||
goto err1;
|
||||
}
|
||||
}
|
||||
|
||||
/* parse compatible ids */
|
||||
if (device->flags.compatible_ids) {
|
||||
struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < cid_list->count; i++) {
|
||||
if (!ispnpidacpi(cid_list->id[i].value))
|
||||
continue;
|
||||
dev_id = pnpacpi_kmalloc(sizeof(struct pnp_id),
|
||||
GFP_KERNEL);
|
||||
if (!dev_id)
|
||||
continue;
|
||||
|
||||
pnpidacpi_to_pnpid(cid_list->id[i].value, dev_id->id);
|
||||
pnp_add_id(dev_id, dev);
|
||||
}
|
||||
}
|
||||
|
||||
/* clear out the damaged flags */
|
||||
if (!dev->active)
|
||||
pnp_init_resource_table(&dev->res);
|
||||
pnp_add_device(dev);
|
||||
num ++;
|
||||
|
||||
return AE_OK;
|
||||
err1:
|
||||
kfree(dev_id);
|
||||
err:
|
||||
kfree(dev);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
|
||||
u32 lvl, void *context, void **rv)
|
||||
{
|
||||
struct acpi_device *device;
|
||||
|
||||
if (!acpi_bus_get_device(handle, &device))
|
||||
pnpacpi_add_device(device);
|
||||
else
|
||||
return AE_CTRL_DEPTH;
|
||||
return AE_OK;
|
||||
}
|
||||
|
||||
int pnpacpi_disabled __initdata;
|
||||
int __init pnpacpi_init(void)
|
||||
{
|
||||
if (acpi_disabled || pnpacpi_disabled) {
|
||||
pnp_info("PnP ACPI: disabled");
|
||||
return 0;
|
||||
}
|
||||
pnp_info("PnP ACPI init");
|
||||
pnp_register_protocol(&pnpacpi_protocol);
|
||||
acpi_get_devices(NULL, pnpacpi_add_device_handler, NULL, NULL);
|
||||
pnp_info("PnP ACPI: found %d devices", num);
|
||||
return 0;
|
||||
}
|
||||
subsys_initcall(pnpacpi_init);
|
||||
|
||||
static int __init pnpacpi_setup(char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 1;
|
||||
if (!strncmp(str, "off", 3))
|
||||
pnpacpi_disabled = 1;
|
||||
return 1;
|
||||
}
|
||||
__setup("pnpacpi=", pnpacpi_setup);
|
||||
|
||||
EXPORT_SYMBOL(pnpacpi_protocol);
|
||||
13
drivers/pnp/pnpacpi/pnpacpi.h
Normal file
13
drivers/pnp/pnpacpi/pnpacpi.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef ACPI_PNP_H
|
||||
#define ACPI_PNP_H
|
||||
|
||||
#include <acpi/acpi_bus.h>
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/pnp.h>
|
||||
|
||||
void *pnpacpi_kmalloc(size_t size, int f);
|
||||
acpi_status pnpacpi_parse_allocated_resource(acpi_handle, struct pnp_resource_table*);
|
||||
acpi_status pnpacpi_parse_resource_option_data(acpi_handle, struct pnp_dev*);
|
||||
int pnpacpi_encode_resources(struct pnp_resource_table *, struct acpi_buffer *);
|
||||
int pnpacpi_build_resource_template(acpi_handle, struct acpi_buffer*);
|
||||
#endif
|
||||
821
drivers/pnp/pnpacpi/rsparser.c
Normal file
821
drivers/pnp/pnpacpi/rsparser.c
Normal file
|
|
@ -0,0 +1,821 @@
|
|||
/*
|
||||
* pnpacpi -- PnP ACPI driver
|
||||
*
|
||||
* Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr>
|
||||
* Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/pci.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 edge_level, int active_high_low)
|
||||
{
|
||||
int flag;
|
||||
if (edge_level == ACPI_LEVEL_SENSITIVE) {
|
||||
if(active_high_low == ACPI_ACTIVE_LOW)
|
||||
flag = IORESOURCE_IRQ_LOWLEVEL;
|
||||
else
|
||||
flag = IORESOURCE_IRQ_HIGHLEVEL;
|
||||
}
|
||||
else {
|
||||
if(active_high_low == ACPI_ACTIVE_LOW)
|
||||
flag = IORESOURCE_IRQ_LOWEDGE;
|
||||
else
|
||||
flag = IORESOURCE_IRQ_HIGHEDGE;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
static void decode_irq_flags(int flag, int *edge_level, int *active_high_low)
|
||||
{
|
||||
switch (flag) {
|
||||
case IORESOURCE_IRQ_LOWLEVEL:
|
||||
*edge_level = ACPI_LEVEL_SENSITIVE;
|
||||
*active_high_low = ACPI_ACTIVE_LOW;
|
||||
break;
|
||||
case IORESOURCE_IRQ_HIGHLEVEL:
|
||||
*edge_level = ACPI_LEVEL_SENSITIVE;
|
||||
*active_high_low = ACPI_ACTIVE_HIGH;
|
||||
break;
|
||||
case IORESOURCE_IRQ_LOWEDGE:
|
||||
*edge_level = ACPI_EDGE_SENSITIVE;
|
||||
*active_high_low = ACPI_ACTIVE_LOW;
|
||||
break;
|
||||
case IORESOURCE_IRQ_HIGHEDGE:
|
||||
*edge_level = ACPI_EDGE_SENSITIVE;
|
||||
*active_high_low = ACPI_ACTIVE_HIGH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pnpacpi_parse_allocated_irqresource(struct pnp_resource_table * res, int irq)
|
||||
{
|
||||
int i = 0;
|
||||
while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
|
||||
i < PNP_MAX_IRQ)
|
||||
i++;
|
||||
if (i < PNP_MAX_IRQ) {
|
||||
res->irq_resource[i].flags = IORESOURCE_IRQ; //Also clears _UNSET flag
|
||||
if (irq == -1) {
|
||||
res->irq_resource[i].flags |= IORESOURCE_DISABLED;
|
||||
return;
|
||||
}
|
||||
res->irq_resource[i].start =(unsigned long) irq;
|
||||
res->irq_resource[i].end = (unsigned long) irq;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table * res, int dma)
|
||||
{
|
||||
int i = 0;
|
||||
while (!(res->dma_resource[i].flags & IORESOURCE_UNSET) &&
|
||||
i < PNP_MAX_DMA)
|
||||
i++;
|
||||
if (i < PNP_MAX_DMA) {
|
||||
res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
|
||||
if (dma == -1) {
|
||||
res->dma_resource[i].flags |= IORESOURCE_DISABLED;
|
||||
return;
|
||||
}
|
||||
res->dma_resource[i].start =(unsigned long) dma;
|
||||
res->dma_resource[i].end = (unsigned long) dma;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pnpacpi_parse_allocated_ioresource(struct pnp_resource_table * res,
|
||||
int io, int len)
|
||||
{
|
||||
int i = 0;
|
||||
while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
|
||||
i < PNP_MAX_PORT)
|
||||
i++;
|
||||
if (i < PNP_MAX_PORT) {
|
||||
res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
|
||||
if (len <= 0 || (io + len -1) >= 0x10003) {
|
||||
res->port_resource[i].flags |= IORESOURCE_DISABLED;
|
||||
return;
|
||||
}
|
||||
res->port_resource[i].start = (unsigned long) io;
|
||||
res->port_resource[i].end = (unsigned long)(io + len - 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pnpacpi_parse_allocated_memresource(struct pnp_resource_table * res,
|
||||
int mem, int len)
|
||||
{
|
||||
int i = 0;
|
||||
while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
|
||||
(i < PNP_MAX_MEM))
|
||||
i++;
|
||||
if (i < PNP_MAX_MEM) {
|
||||
res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
|
||||
if (len <= 0) {
|
||||
res->mem_resource[i].flags |= IORESOURCE_DISABLED;
|
||||
return;
|
||||
}
|
||||
res->mem_resource[i].start = (unsigned long) mem;
|
||||
res->mem_resource[i].end = (unsigned long)(mem + len - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
|
||||
void *data)
|
||||
{
|
||||
struct pnp_resource_table * res_table = (struct pnp_resource_table *)data;
|
||||
|
||||
switch (res->id) {
|
||||
case ACPI_RSTYPE_IRQ:
|
||||
if ((res->data.irq.number_of_interrupts > 0) &&
|
||||
valid_IRQ(res->data.irq.interrupts[0])) {
|
||||
pnpacpi_parse_allocated_irqresource(res_table,
|
||||
acpi_register_gsi(res->data.irq.interrupts[0],
|
||||
res->data.irq.edge_level,
|
||||
res->data.irq.active_high_low));
|
||||
pcibios_penalize_isa_irq(res->data.irq.interrupts[0]);
|
||||
}
|
||||
break;
|
||||
|
||||
case ACPI_RSTYPE_EXT_IRQ:
|
||||
if ((res->data.extended_irq.number_of_interrupts > 0) &&
|
||||
valid_IRQ(res->data.extended_irq.interrupts[0])) {
|
||||
pnpacpi_parse_allocated_irqresource(res_table,
|
||||
acpi_register_gsi(res->data.extended_irq.interrupts[0],
|
||||
res->data.extended_irq.edge_level,
|
||||
res->data.extended_irq.active_high_low));
|
||||
pcibios_penalize_isa_irq(res->data.extended_irq.interrupts[0]);
|
||||
}
|
||||
break;
|
||||
case ACPI_RSTYPE_DMA:
|
||||
if (res->data.dma.number_of_channels > 0)
|
||||
pnpacpi_parse_allocated_dmaresource(res_table,
|
||||
res->data.dma.channels[0]);
|
||||
break;
|
||||
case ACPI_RSTYPE_IO:
|
||||
pnpacpi_parse_allocated_ioresource(res_table,
|
||||
res->data.io.min_base_address,
|
||||
res->data.io.range_length);
|
||||
break;
|
||||
case ACPI_RSTYPE_FIXED_IO:
|
||||
pnpacpi_parse_allocated_ioresource(res_table,
|
||||
res->data.fixed_io.base_address,
|
||||
res->data.fixed_io.range_length);
|
||||
break;
|
||||
case ACPI_RSTYPE_MEM24:
|
||||
pnpacpi_parse_allocated_memresource(res_table,
|
||||
res->data.memory24.min_base_address,
|
||||
res->data.memory24.range_length);
|
||||
break;
|
||||
case ACPI_RSTYPE_MEM32:
|
||||
pnpacpi_parse_allocated_memresource(res_table,
|
||||
res->data.memory32.min_base_address,
|
||||
res->data.memory32.range_length);
|
||||
break;
|
||||
case ACPI_RSTYPE_FIXED_MEM32:
|
||||
pnpacpi_parse_allocated_memresource(res_table,
|
||||
res->data.fixed_memory32.range_base_address,
|
||||
res->data.fixed_memory32.range_length);
|
||||
break;
|
||||
case ACPI_RSTYPE_ADDRESS16:
|
||||
pnpacpi_parse_allocated_memresource(res_table,
|
||||
res->data.address16.min_address_range,
|
||||
res->data.address16.address_length);
|
||||
break;
|
||||
case ACPI_RSTYPE_ADDRESS32:
|
||||
pnpacpi_parse_allocated_memresource(res_table,
|
||||
res->data.address32.min_address_range,
|
||||
res->data.address32.address_length);
|
||||
break;
|
||||
case ACPI_RSTYPE_ADDRESS64:
|
||||
pnpacpi_parse_allocated_memresource(res_table,
|
||||
res->data.address64.min_address_range,
|
||||
res->data.address64.address_length);
|
||||
break;
|
||||
case ACPI_RSTYPE_VENDOR:
|
||||
break;
|
||||
default:
|
||||
pnp_warn("PnPACPI: unknown resource type %d", res->id);
|
||||
return AE_ERROR;
|
||||
}
|
||||
|
||||
return AE_OK;
|
||||
}
|
||||
|
||||
acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle, struct pnp_resource_table * res)
|
||||
{
|
||||
/* Blank the resource table values */
|
||||
pnp_init_resource_table(res);
|
||||
|
||||
return acpi_walk_resources(handle, METHOD_NAME__CRS, pnpacpi_allocated_resource, res);
|
||||
}
|
||||
|
||||
static void pnpacpi_parse_dma_option(struct pnp_option *option, struct acpi_resource_dma *p)
|
||||
{
|
||||
int i;
|
||||
struct pnp_dma * dma;
|
||||
|
||||
if (p->number_of_channels == 0)
|
||||
return;
|
||||
dma = pnpacpi_kmalloc(sizeof(struct pnp_dma), GFP_KERNEL);
|
||||
if (!dma)
|
||||
return;
|
||||
|
||||
for(i = 0; i < p->number_of_channels; i++)
|
||||
dma->map |= 1 << p->channels[i];
|
||||
dma->flags = 0;
|
||||
if (p->bus_master)
|
||||
dma->flags |= IORESOURCE_DMA_MASTER;
|
||||
switch (p->type) {
|
||||
case ACPI_COMPATIBILITY:
|
||||
dma->flags |= IORESOURCE_DMA_COMPATIBLE;
|
||||
break;
|
||||
case ACPI_TYPE_A:
|
||||
dma->flags |= IORESOURCE_DMA_TYPEA;
|
||||
break;
|
||||
case ACPI_TYPE_B:
|
||||
dma->flags |= IORESOURCE_DMA_TYPEB;
|
||||
break;
|
||||
case ACPI_TYPE_F:
|
||||
dma->flags |= IORESOURCE_DMA_TYPEF;
|
||||
break;
|
||||
default:
|
||||
/* Set a default value ? */
|
||||
dma->flags |= IORESOURCE_DMA_COMPATIBLE;
|
||||
pnp_err("Invalid DMA type");
|
||||
}
|
||||
switch (p->transfer) {
|
||||
case ACPI_TRANSFER_8:
|
||||
dma->flags |= IORESOURCE_DMA_8BIT;
|
||||
break;
|
||||
case ACPI_TRANSFER_8_16:
|
||||
dma->flags |= IORESOURCE_DMA_8AND16BIT;
|
||||
break;
|
||||
case ACPI_TRANSFER_16:
|
||||
dma->flags |= IORESOURCE_DMA_16BIT;
|
||||
break;
|
||||
default:
|
||||
/* Set a default value ? */
|
||||
dma->flags |= IORESOURCE_DMA_8AND16BIT;
|
||||
pnp_err("Invalid DMA transfer type");
|
||||
}
|
||||
|
||||
pnp_register_dma_resource(option,dma);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void pnpacpi_parse_irq_option(struct pnp_option *option,
|
||||
struct acpi_resource_irq *p)
|
||||
{
|
||||
int i;
|
||||
struct pnp_irq * irq;
|
||||
|
||||
if (p->number_of_interrupts == 0)
|
||||
return;
|
||||
irq = pnpacpi_kmalloc(sizeof(struct pnp_irq), GFP_KERNEL);
|
||||
if (!irq)
|
||||
return;
|
||||
|
||||
for(i = 0; i < p->number_of_interrupts; i++)
|
||||
if (p->interrupts[i])
|
||||
__set_bit(p->interrupts[i], irq->map);
|
||||
irq->flags = irq_flags(p->edge_level, p->active_high_low);
|
||||
|
||||
pnp_register_irq_resource(option, irq);
|
||||
return;
|
||||
}
|
||||
|
||||
static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
|
||||
struct acpi_resource_ext_irq *p)
|
||||
{
|
||||
int i;
|
||||
struct pnp_irq * irq;
|
||||
|
||||
if (p->number_of_interrupts == 0)
|
||||
return;
|
||||
irq = pnpacpi_kmalloc(sizeof(struct pnp_irq), GFP_KERNEL);
|
||||
if (!irq)
|
||||
return;
|
||||
|
||||
for(i = 0; i < p->number_of_interrupts; i++)
|
||||
if (p->interrupts[i])
|
||||
__set_bit(p->interrupts[i], irq->map);
|
||||
irq->flags = irq_flags(p->edge_level, p->active_high_low);
|
||||
|
||||
pnp_register_irq_resource(option, irq);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
pnpacpi_parse_port_option(struct pnp_option *option,
|
||||
struct acpi_resource_io *io)
|
||||
{
|
||||
struct pnp_port * port;
|
||||
|
||||
if (io->range_length == 0)
|
||||
return;
|
||||
port = pnpacpi_kmalloc(sizeof(struct pnp_port), GFP_KERNEL);
|
||||
if (!port)
|
||||
return;
|
||||
port->min = io->min_base_address;
|
||||
port->max = io->max_base_address;
|
||||
port->align = io->alignment;
|
||||
port->size = io->range_length;
|
||||
port->flags = ACPI_DECODE_16 == io->io_decode ?
|
||||
PNP_PORT_FLAG_16BITADDR : 0;
|
||||
pnp_register_port_resource(option,port);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
pnpacpi_parse_fixed_port_option(struct pnp_option *option,
|
||||
struct acpi_resource_fixed_io *io)
|
||||
{
|
||||
struct pnp_port * port;
|
||||
|
||||
if (io->range_length == 0)
|
||||
return;
|
||||
port = pnpacpi_kmalloc(sizeof(struct pnp_port), GFP_KERNEL);
|
||||
if (!port)
|
||||
return;
|
||||
port->min = port->max = io->base_address;
|
||||
port->size = io->range_length;
|
||||
port->align = 0;
|
||||
port->flags = PNP_PORT_FLAG_FIXED;
|
||||
pnp_register_port_resource(option,port);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
pnpacpi_parse_mem24_option(struct pnp_option *option,
|
||||
struct acpi_resource_mem24 *p)
|
||||
{
|
||||
struct pnp_mem * mem;
|
||||
|
||||
if (p->range_length == 0)
|
||||
return;
|
||||
mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL);
|
||||
if (!mem)
|
||||
return;
|
||||
mem->min = p->min_base_address;
|
||||
mem->max = p->max_base_address;
|
||||
mem->align = p->alignment;
|
||||
mem->size = p->range_length;
|
||||
|
||||
mem->flags = (ACPI_READ_WRITE_MEMORY == p->read_write_attribute) ?
|
||||
IORESOURCE_MEM_WRITEABLE : 0;
|
||||
|
||||
pnp_register_mem_resource(option,mem);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
pnpacpi_parse_mem32_option(struct pnp_option *option,
|
||||
struct acpi_resource_mem32 *p)
|
||||
{
|
||||
struct pnp_mem * mem;
|
||||
|
||||
if (p->range_length == 0)
|
||||
return;
|
||||
mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL);
|
||||
if (!mem)
|
||||
return;
|
||||
mem->min = p->min_base_address;
|
||||
mem->max = p->max_base_address;
|
||||
mem->align = p->alignment;
|
||||
mem->size = p->range_length;
|
||||
|
||||
mem->flags = (ACPI_READ_WRITE_MEMORY == p->read_write_attribute) ?
|
||||
IORESOURCE_MEM_WRITEABLE : 0;
|
||||
|
||||
pnp_register_mem_resource(option,mem);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
|
||||
struct acpi_resource_fixed_mem32 *p)
|
||||
{
|
||||
struct pnp_mem * mem;
|
||||
|
||||
if (p->range_length == 0)
|
||||
return;
|
||||
mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL);
|
||||
if (!mem)
|
||||
return;
|
||||
mem->min = mem->max = p->range_base_address;
|
||||
mem->size = p->range_length;
|
||||
mem->align = 0;
|
||||
|
||||
mem->flags = (ACPI_READ_WRITE_MEMORY == p->read_write_attribute) ?
|
||||
IORESOURCE_MEM_WRITEABLE : 0;
|
||||
|
||||
pnp_register_mem_resource(option,mem);
|
||||
return;
|
||||
}
|
||||
|
||||
struct acpipnp_parse_option_s {
|
||||
struct pnp_option *option;
|
||||
struct pnp_dev *dev;
|
||||
};
|
||||
|
||||
static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
|
||||
void *data)
|
||||
{
|
||||
int priority = 0;
|
||||
struct acpipnp_parse_option_s *parse_data = (struct acpipnp_parse_option_s *)data;
|
||||
struct pnp_dev *dev = parse_data->dev;
|
||||
struct pnp_option *option = parse_data->option;
|
||||
|
||||
switch (res->id) {
|
||||
case ACPI_RSTYPE_IRQ:
|
||||
pnpacpi_parse_irq_option(option, &res->data.irq);
|
||||
break;
|
||||
case ACPI_RSTYPE_EXT_IRQ:
|
||||
pnpacpi_parse_ext_irq_option(option,
|
||||
&res->data.extended_irq);
|
||||
break;
|
||||
case ACPI_RSTYPE_DMA:
|
||||
pnpacpi_parse_dma_option(option, &res->data.dma);
|
||||
break;
|
||||
case ACPI_RSTYPE_IO:
|
||||
pnpacpi_parse_port_option(option, &res->data.io);
|
||||
break;
|
||||
case ACPI_RSTYPE_FIXED_IO:
|
||||
pnpacpi_parse_fixed_port_option(option,
|
||||
&res->data.fixed_io);
|
||||
break;
|
||||
case ACPI_RSTYPE_MEM24:
|
||||
pnpacpi_parse_mem24_option(option, &res->data.memory24);
|
||||
break;
|
||||
case ACPI_RSTYPE_MEM32:
|
||||
pnpacpi_parse_mem32_option(option, &res->data.memory32);
|
||||
break;
|
||||
case ACPI_RSTYPE_FIXED_MEM32:
|
||||
pnpacpi_parse_fixed_mem32_option(option,
|
||||
&res->data.fixed_memory32);
|
||||
break;
|
||||
case ACPI_RSTYPE_START_DPF:
|
||||
switch (res->data.start_dpf.compatibility_priority) {
|
||||
case ACPI_GOOD_CONFIGURATION:
|
||||
priority = PNP_RES_PRIORITY_PREFERRED;
|
||||
break;
|
||||
|
||||
case ACPI_ACCEPTABLE_CONFIGURATION:
|
||||
priority = PNP_RES_PRIORITY_ACCEPTABLE;
|
||||
break;
|
||||
|
||||
case ACPI_SUB_OPTIMAL_CONFIGURATION:
|
||||
priority = PNP_RES_PRIORITY_FUNCTIONAL;
|
||||
break;
|
||||
default:
|
||||
priority = PNP_RES_PRIORITY_INVALID;
|
||||
break;
|
||||
}
|
||||
/* TBD: Considering performace/robustness bits */
|
||||
option = pnp_register_dependent_option(dev, priority);
|
||||
if (!option)
|
||||
return AE_ERROR;
|
||||
parse_data->option = option;
|
||||
break;
|
||||
case ACPI_RSTYPE_END_DPF:
|
||||
return AE_CTRL_TERMINATE;
|
||||
default:
|
||||
pnp_warn("PnPACPI: unknown resource type %d", res->id);
|
||||
return AE_ERROR;
|
||||
}
|
||||
|
||||
return AE_OK;
|
||||
}
|
||||
|
||||
acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
|
||||
struct pnp_dev *dev)
|
||||
{
|
||||
acpi_status status;
|
||||
struct acpipnp_parse_option_s parse_data;
|
||||
|
||||
parse_data.option = pnp_register_independent_option(dev);
|
||||
if (!parse_data.option)
|
||||
return AE_ERROR;
|
||||
parse_data.dev = dev;
|
||||
status = acpi_walk_resources(handle, METHOD_NAME__PRS,
|
||||
pnpacpi_option_resource, &parse_data);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set resource
|
||||
*/
|
||||
static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
|
||||
void *data)
|
||||
{
|
||||
int *res_cnt = (int *)data;
|
||||
switch (res->id) {
|
||||
case ACPI_RSTYPE_IRQ:
|
||||
case ACPI_RSTYPE_EXT_IRQ:
|
||||
case ACPI_RSTYPE_DMA:
|
||||
case ACPI_RSTYPE_IO:
|
||||
case ACPI_RSTYPE_FIXED_IO:
|
||||
case ACPI_RSTYPE_MEM24:
|
||||
case ACPI_RSTYPE_MEM32:
|
||||
case ACPI_RSTYPE_FIXED_MEM32:
|
||||
#if 0
|
||||
case ACPI_RSTYPE_ADDRESS16:
|
||||
case ACPI_RSTYPE_ADDRESS32:
|
||||
case ACPI_RSTYPE_ADDRESS64:
|
||||
#endif
|
||||
(*res_cnt) ++;
|
||||
default:
|
||||
return AE_OK;
|
||||
}
|
||||
return AE_OK;
|
||||
}
|
||||
|
||||
static acpi_status pnpacpi_type_resources(struct acpi_resource *res,
|
||||
void *data)
|
||||
{
|
||||
struct acpi_resource **resource = (struct acpi_resource **)data;
|
||||
switch (res->id) {
|
||||
case ACPI_RSTYPE_IRQ:
|
||||
case ACPI_RSTYPE_EXT_IRQ:
|
||||
case ACPI_RSTYPE_DMA:
|
||||
case ACPI_RSTYPE_IO:
|
||||
case ACPI_RSTYPE_FIXED_IO:
|
||||
case ACPI_RSTYPE_MEM24:
|
||||
case ACPI_RSTYPE_MEM32:
|
||||
case ACPI_RSTYPE_FIXED_MEM32:
|
||||
#if 0
|
||||
case ACPI_RSTYPE_ADDRESS16:
|
||||
case ACPI_RSTYPE_ADDRESS32:
|
||||
case ACPI_RSTYPE_ADDRESS64:
|
||||
#endif
|
||||
(*resource)->id = res->id;
|
||||
(*resource)++;
|
||||
default:
|
||||
return AE_OK;
|
||||
}
|
||||
|
||||
return AE_OK;
|
||||
}
|
||||
|
||||
int pnpacpi_build_resource_template(acpi_handle handle,
|
||||
struct acpi_buffer *buffer)
|
||||
{
|
||||
struct acpi_resource *resource;
|
||||
int res_cnt = 0;
|
||||
acpi_status status;
|
||||
|
||||
status = acpi_walk_resources(handle, METHOD_NAME__CRS,
|
||||
pnpacpi_count_resources, &res_cnt);
|
||||
if (ACPI_FAILURE(status)) {
|
||||
pnp_err("Evaluate _CRS failed");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!res_cnt)
|
||||
return -EINVAL;
|
||||
buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
|
||||
buffer->pointer = pnpacpi_kmalloc(buffer->length - 1, GFP_KERNEL);
|
||||
if (!buffer->pointer)
|
||||
return -ENOMEM;
|
||||
pnp_dbg("Res cnt %d", res_cnt);
|
||||
resource = (struct acpi_resource *)buffer->pointer;
|
||||
status = acpi_walk_resources(handle, METHOD_NAME__CRS,
|
||||
pnpacpi_type_resources, &resource);
|
||||
if (ACPI_FAILURE(status)) {
|
||||
kfree(buffer->pointer);
|
||||
pnp_err("Evaluate _CRS failed");
|
||||
return -EINVAL;
|
||||
}
|
||||
/* resource will pointer the end resource now */
|
||||
resource->id = ACPI_RSTYPE_END_TAG;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pnpacpi_encode_irq(struct acpi_resource *resource,
|
||||
struct resource *p)
|
||||
{
|
||||
int edge_level, active_high_low;
|
||||
|
||||
decode_irq_flags(p->flags & IORESOURCE_BITS, &edge_level,
|
||||
&active_high_low);
|
||||
resource->id = ACPI_RSTYPE_IRQ;
|
||||
resource->length = sizeof(struct acpi_resource);
|
||||
resource->data.irq.edge_level = edge_level;
|
||||
resource->data.irq.active_high_low = active_high_low;
|
||||
if (edge_level == ACPI_EDGE_SENSITIVE)
|
||||
resource->data.irq.shared_exclusive = ACPI_EXCLUSIVE;
|
||||
else
|
||||
resource->data.irq.shared_exclusive = ACPI_SHARED;
|
||||
resource->data.irq.number_of_interrupts = 1;
|
||||
resource->data.irq.interrupts[0] = p->start;
|
||||
}
|
||||
|
||||
static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
|
||||
struct resource *p)
|
||||
{
|
||||
int edge_level, active_high_low;
|
||||
|
||||
decode_irq_flags(p->flags & IORESOURCE_BITS, &edge_level,
|
||||
&active_high_low);
|
||||
resource->id = ACPI_RSTYPE_EXT_IRQ;
|
||||
resource->length = sizeof(struct acpi_resource);
|
||||
resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
|
||||
resource->data.extended_irq.edge_level = edge_level;
|
||||
resource->data.extended_irq.active_high_low = active_high_low;
|
||||
if (edge_level == ACPI_EDGE_SENSITIVE)
|
||||
resource->data.irq.shared_exclusive = ACPI_EXCLUSIVE;
|
||||
else
|
||||
resource->data.irq.shared_exclusive = ACPI_SHARED;
|
||||
resource->data.extended_irq.number_of_interrupts = 1;
|
||||
resource->data.extended_irq.interrupts[0] = p->start;
|
||||
}
|
||||
|
||||
static void pnpacpi_encode_dma(struct acpi_resource *resource,
|
||||
struct resource *p)
|
||||
{
|
||||
resource->id = ACPI_RSTYPE_DMA;
|
||||
resource->length = sizeof(struct acpi_resource);
|
||||
/* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
|
||||
if (p->flags & IORESOURCE_DMA_COMPATIBLE)
|
||||
resource->data.dma.type = ACPI_COMPATIBILITY;
|
||||
else if (p->flags & IORESOURCE_DMA_TYPEA)
|
||||
resource->data.dma.type = ACPI_TYPE_A;
|
||||
else if (p->flags & IORESOURCE_DMA_TYPEB)
|
||||
resource->data.dma.type = ACPI_TYPE_B;
|
||||
else if (p->flags & IORESOURCE_DMA_TYPEF)
|
||||
resource->data.dma.type = ACPI_TYPE_F;
|
||||
if (p->flags & IORESOURCE_DMA_8BIT)
|
||||
resource->data.dma.transfer = ACPI_TRANSFER_8;
|
||||
else if (p->flags & IORESOURCE_DMA_8AND16BIT)
|
||||
resource->data.dma.transfer = ACPI_TRANSFER_8_16;
|
||||
else if (p->flags & IORESOURCE_DMA_16BIT)
|
||||
resource->data.dma.transfer = ACPI_TRANSFER_16;
|
||||
resource->data.dma.bus_master = p->flags & IORESOURCE_DMA_MASTER;
|
||||
resource->data.dma.number_of_channels = 1;
|
||||
resource->data.dma.channels[0] = p->start;
|
||||
}
|
||||
|
||||
static void pnpacpi_encode_io(struct acpi_resource *resource,
|
||||
struct resource *p)
|
||||
{
|
||||
resource->id = ACPI_RSTYPE_IO;
|
||||
resource->length = sizeof(struct acpi_resource);
|
||||
/* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
|
||||
resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR)?
|
||||
ACPI_DECODE_16 : ACPI_DECODE_10;
|
||||
resource->data.io.min_base_address = p->start;
|
||||
resource->data.io.max_base_address = p->end;
|
||||
resource->data.io.alignment = 0; /* Correct? */
|
||||
resource->data.io.range_length = p->end - p->start + 1;
|
||||
}
|
||||
|
||||
static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
|
||||
struct resource *p)
|
||||
{
|
||||
resource->id = ACPI_RSTYPE_FIXED_IO;
|
||||
resource->length = sizeof(struct acpi_resource);
|
||||
resource->data.fixed_io.base_address = p->start;
|
||||
resource->data.fixed_io.range_length = p->end - p->start + 1;
|
||||
}
|
||||
|
||||
static void pnpacpi_encode_mem24(struct acpi_resource *resource,
|
||||
struct resource *p)
|
||||
{
|
||||
resource->id = ACPI_RSTYPE_MEM24;
|
||||
resource->length = sizeof(struct acpi_resource);
|
||||
/* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
|
||||
resource->data.memory24.read_write_attribute =
|
||||
(p->flags & IORESOURCE_MEM_WRITEABLE) ?
|
||||
ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
|
||||
resource->data.memory24.min_base_address = p->start;
|
||||
resource->data.memory24.max_base_address = p->end;
|
||||
resource->data.memory24.alignment = 0;
|
||||
resource->data.memory24.range_length = p->end - p->start + 1;
|
||||
}
|
||||
|
||||
static void pnpacpi_encode_mem32(struct acpi_resource *resource,
|
||||
struct resource *p)
|
||||
{
|
||||
resource->id = ACPI_RSTYPE_MEM32;
|
||||
resource->length = sizeof(struct acpi_resource);
|
||||
resource->data.memory32.read_write_attribute =
|
||||
(p->flags & IORESOURCE_MEM_WRITEABLE) ?
|
||||
ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
|
||||
resource->data.memory32.min_base_address = p->start;
|
||||
resource->data.memory32.max_base_address = p->end;
|
||||
resource->data.memory32.alignment = 0;
|
||||
resource->data.memory32.range_length = p->end - p->start + 1;
|
||||
}
|
||||
|
||||
static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
|
||||
struct resource *p)
|
||||
{
|
||||
resource->id = ACPI_RSTYPE_FIXED_MEM32;
|
||||
resource->length = sizeof(struct acpi_resource);
|
||||
resource->data.fixed_memory32.read_write_attribute =
|
||||
(p->flags & IORESOURCE_MEM_WRITEABLE) ?
|
||||
ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
|
||||
resource->data.fixed_memory32.range_base_address = p->start;
|
||||
resource->data.fixed_memory32.range_length = p->end - p->start + 1;
|
||||
}
|
||||
|
||||
int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
|
||||
struct acpi_buffer *buffer)
|
||||
{
|
||||
int i = 0;
|
||||
/* pnpacpi_build_resource_template allocates extra mem */
|
||||
int res_cnt = (buffer->length - 1)/sizeof(struct acpi_resource) - 1;
|
||||
struct acpi_resource *resource = (struct acpi_resource*)buffer->pointer;
|
||||
int port = 0, irq = 0, dma = 0, mem = 0;
|
||||
|
||||
pnp_dbg("res cnt %d", res_cnt);
|
||||
while (i < res_cnt) {
|
||||
switch(resource->id) {
|
||||
case ACPI_RSTYPE_IRQ:
|
||||
pnp_dbg("Encode irq");
|
||||
pnpacpi_encode_irq(resource,
|
||||
&res_table->irq_resource[irq]);
|
||||
irq++;
|
||||
break;
|
||||
|
||||
case ACPI_RSTYPE_EXT_IRQ:
|
||||
pnp_dbg("Encode ext irq");
|
||||
pnpacpi_encode_ext_irq(resource,
|
||||
&res_table->irq_resource[irq]);
|
||||
irq++;
|
||||
break;
|
||||
case ACPI_RSTYPE_DMA:
|
||||
pnp_dbg("Encode dma");
|
||||
pnpacpi_encode_dma(resource,
|
||||
&res_table->dma_resource[dma]);
|
||||
dma ++;
|
||||
break;
|
||||
case ACPI_RSTYPE_IO:
|
||||
pnp_dbg("Encode io");
|
||||
pnpacpi_encode_io(resource,
|
||||
&res_table->port_resource[port]);
|
||||
port ++;
|
||||
break;
|
||||
case ACPI_RSTYPE_FIXED_IO:
|
||||
pnp_dbg("Encode fixed io");
|
||||
pnpacpi_encode_fixed_io(resource,
|
||||
&res_table->port_resource[port]);
|
||||
port ++;
|
||||
break;
|
||||
case ACPI_RSTYPE_MEM24:
|
||||
pnp_dbg("Encode mem24");
|
||||
pnpacpi_encode_mem24(resource,
|
||||
&res_table->mem_resource[mem]);
|
||||
mem ++;
|
||||
break;
|
||||
case ACPI_RSTYPE_MEM32:
|
||||
pnp_dbg("Encode mem32");
|
||||
pnpacpi_encode_mem32(resource,
|
||||
&res_table->mem_resource[mem]);
|
||||
mem ++;
|
||||
break;
|
||||
case ACPI_RSTYPE_FIXED_MEM32:
|
||||
pnp_dbg("Encode fixed mem32");
|
||||
pnpacpi_encode_fixed_mem32(resource,
|
||||
&res_table->mem_resource[mem]);
|
||||
mem ++;
|
||||
break;
|
||||
default: /* other type */
|
||||
pnp_warn("unknown resource type %d", resource->id);
|
||||
return -EINVAL;
|
||||
}
|
||||
resource ++;
|
||||
i ++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
42
drivers/pnp/pnpbios/Kconfig
Normal file
42
drivers/pnp/pnpbios/Kconfig
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#
|
||||
# Plug and Play BIOS configuration
|
||||
#
|
||||
config PNPBIOS
|
||||
bool "Plug and Play BIOS support (EXPERIMENTAL)"
|
||||
depends on PNP && ISA && X86 && EXPERIMENTAL
|
||||
default n
|
||||
---help---
|
||||
Linux uses the PNPBIOS as defined in "Plug and Play BIOS
|
||||
Specification Version 1.0A May 5, 1994" to autodetect built-in
|
||||
mainboard resources (e.g. parallel port resources).
|
||||
|
||||
Some features (e.g. event notification, docking station information,
|
||||
ISAPNP services) are not currently implemented.
|
||||
|
||||
If you would like the kernel to detect and allocate resources to
|
||||
your mainboard devices (on some systems they are disabled by the
|
||||
BIOS) say Y here. Also the PNPBIOS can help prevent resource
|
||||
conflicts between mainboard devices and other bus devices.
|
||||
|
||||
Note: ACPI is expected to supersede PNPBIOS some day, currently it
|
||||
co-exists nicely. If you have a non-ISA system that supports ACPI,
|
||||
you probably don't need PNPBIOS support.
|
||||
|
||||
config PNPBIOS_PROC_FS
|
||||
bool "Plug and Play BIOS /proc interface"
|
||||
depends on PNPBIOS && PROC_FS
|
||||
---help---
|
||||
If you say Y here and to "/proc file system support", you will be
|
||||
able to directly access the PNPBIOS. This includes resource
|
||||
allocation, ESCD, and other PNPBIOS services. Using this
|
||||
interface is potentially dangerous because the PNPBIOS driver will
|
||||
not be notified of any resource changes made by writing directly.
|
||||
Also some buggy systems will fault when accessing certain features
|
||||
in the PNPBIOS /proc interface (e.g. "boot" configs).
|
||||
|
||||
See the latest pcmcia-cs (stand-alone package) for a nice set of
|
||||
PNPBIOS /proc interface tools (lspnp and setpnp).
|
||||
|
||||
Unless you are debugging or have other specific reasons, it is
|
||||
recommended that you say N here.
|
||||
|
||||
7
drivers/pnp/pnpbios/Makefile
Normal file
7
drivers/pnp/pnpbios/Makefile
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
# Makefile for the kernel PNPBIOS driver.
|
||||
#
|
||||
|
||||
pnpbios-proc-$(CONFIG_PNPBIOS_PROC_FS) = proc.o
|
||||
|
||||
obj-y := core.o bioscalls.o rsparser.o $(pnpbios-proc-y)
|
||||
544
drivers/pnp/pnpbios/bioscalls.c
Normal file
544
drivers/pnp/pnpbios/bioscalls.c
Normal file
|
|
@ -0,0 +1,544 @@
|
|||
/*
|
||||
* bioscalls.c - the lowlevel layer of the PnPBIOS driver
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/linkage.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/pnpbios.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/pnp.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/smp.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/kmod.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/spinlock.h>
|
||||
|
||||
#include <asm/page.h>
|
||||
#include <asm/desc.h>
|
||||
#include <asm/system.h>
|
||||
#include <asm/byteorder.h>
|
||||
|
||||
#include "pnpbios.h"
|
||||
|
||||
static struct {
|
||||
u16 offset;
|
||||
u16 segment;
|
||||
} pnp_bios_callpoint;
|
||||
|
||||
|
||||
/* The PnP BIOS entries in the GDT */
|
||||
#define PNP_GDT (GDT_ENTRY_PNPBIOS_BASE * 8)
|
||||
|
||||
#define PNP_CS32 (PNP_GDT+0x00) /* segment for calling fn */
|
||||
#define PNP_CS16 (PNP_GDT+0x08) /* code segment for BIOS */
|
||||
#define PNP_DS (PNP_GDT+0x10) /* data segment for BIOS */
|
||||
#define PNP_TS1 (PNP_GDT+0x18) /* transfer data segment */
|
||||
#define PNP_TS2 (PNP_GDT+0x20) /* another data segment */
|
||||
|
||||
/*
|
||||
* These are some opcodes for a "static asmlinkage"
|
||||
* As this code is *not* executed inside the linux kernel segment, but in a
|
||||
* alias at offset 0, we need a far return that can not be compiled by
|
||||
* default (please, prove me wrong! this is *really* ugly!)
|
||||
* This is the only way to get the bios to return into the kernel code,
|
||||
* because the bios code runs in 16 bit protected mode and therefore can only
|
||||
* return to the caller if the call is within the first 64kB, and the linux
|
||||
* kernel begins at offset 3GB...
|
||||
*/
|
||||
|
||||
asmlinkage void pnp_bios_callfunc(void);
|
||||
|
||||
__asm__(
|
||||
".text \n"
|
||||
__ALIGN_STR "\n"
|
||||
"pnp_bios_callfunc:\n"
|
||||
" pushl %edx \n"
|
||||
" pushl %ecx \n"
|
||||
" pushl %ebx \n"
|
||||
" pushl %eax \n"
|
||||
" lcallw *pnp_bios_callpoint\n"
|
||||
" addl $16, %esp \n"
|
||||
" lret \n"
|
||||
".previous \n"
|
||||
);
|
||||
|
||||
#define Q_SET_SEL(cpu, selname, address, size) \
|
||||
do { \
|
||||
set_base(per_cpu(cpu_gdt_table,cpu)[(selname) >> 3], __va((u32)(address))); \
|
||||
set_limit(per_cpu(cpu_gdt_table,cpu)[(selname) >> 3], size); \
|
||||
} while(0)
|
||||
|
||||
#define Q2_SET_SEL(cpu, selname, address, size) \
|
||||
do { \
|
||||
set_base(per_cpu(cpu_gdt_table,cpu)[(selname) >> 3], (u32)(address)); \
|
||||
set_limit(per_cpu(cpu_gdt_table,cpu)[(selname) >> 3], size); \
|
||||
} while(0)
|
||||
|
||||
static struct desc_struct bad_bios_desc = { 0, 0x00409200 };
|
||||
|
||||
/*
|
||||
* At some point we want to use this stack frame pointer to unwind
|
||||
* after PnP BIOS oopses.
|
||||
*/
|
||||
|
||||
u32 pnp_bios_fault_esp;
|
||||
u32 pnp_bios_fault_eip;
|
||||
u32 pnp_bios_is_utter_crap = 0;
|
||||
|
||||
static spinlock_t pnp_bios_lock;
|
||||
|
||||
|
||||
/*
|
||||
* Support Functions
|
||||
*/
|
||||
|
||||
static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
|
||||
u16 arg4, u16 arg5, u16 arg6, u16 arg7,
|
||||
void *ts1_base, u32 ts1_size,
|
||||
void *ts2_base, u32 ts2_size)
|
||||
{
|
||||
unsigned long flags;
|
||||
u16 status;
|
||||
struct desc_struct save_desc_40;
|
||||
int cpu;
|
||||
|
||||
/*
|
||||
* PnP BIOSes are generally not terribly re-entrant.
|
||||
* Also, don't rely on them to save everything correctly.
|
||||
*/
|
||||
if(pnp_bios_is_utter_crap)
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
|
||||
cpu = get_cpu();
|
||||
save_desc_40 = per_cpu(cpu_gdt_table,cpu)[0x40 / 8];
|
||||
per_cpu(cpu_gdt_table,cpu)[0x40 / 8] = bad_bios_desc;
|
||||
|
||||
/* On some boxes IRQ's during PnP BIOS calls are deadly. */
|
||||
spin_lock_irqsave(&pnp_bios_lock, flags);
|
||||
|
||||
/* The lock prevents us bouncing CPU here */
|
||||
if (ts1_size)
|
||||
Q2_SET_SEL(smp_processor_id(), PNP_TS1, ts1_base, ts1_size);
|
||||
if (ts2_size)
|
||||
Q2_SET_SEL(smp_processor_id(), PNP_TS2, ts2_base, ts2_size);
|
||||
|
||||
__asm__ __volatile__(
|
||||
"pushl %%ebp\n\t"
|
||||
"pushl %%edi\n\t"
|
||||
"pushl %%esi\n\t"
|
||||
"pushl %%ds\n\t"
|
||||
"pushl %%es\n\t"
|
||||
"pushl %%fs\n\t"
|
||||
"pushl %%gs\n\t"
|
||||
"pushfl\n\t"
|
||||
"movl %%esp, pnp_bios_fault_esp\n\t"
|
||||
"movl $1f, pnp_bios_fault_eip\n\t"
|
||||
"lcall %5,%6\n\t"
|
||||
"1:popfl\n\t"
|
||||
"popl %%gs\n\t"
|
||||
"popl %%fs\n\t"
|
||||
"popl %%es\n\t"
|
||||
"popl %%ds\n\t"
|
||||
"popl %%esi\n\t"
|
||||
"popl %%edi\n\t"
|
||||
"popl %%ebp\n\t"
|
||||
: "=a" (status)
|
||||
: "0" ((func) | (((u32)arg1) << 16)),
|
||||
"b" ((arg2) | (((u32)arg3) << 16)),
|
||||
"c" ((arg4) | (((u32)arg5) << 16)),
|
||||
"d" ((arg6) | (((u32)arg7) << 16)),
|
||||
"i" (PNP_CS32),
|
||||
"i" (0)
|
||||
: "memory"
|
||||
);
|
||||
spin_unlock_irqrestore(&pnp_bios_lock, flags);
|
||||
|
||||
per_cpu(cpu_gdt_table,cpu)[0x40 / 8] = save_desc_40;
|
||||
put_cpu();
|
||||
|
||||
/* If we get here and this is set then the PnP BIOS faulted on us. */
|
||||
if(pnp_bios_is_utter_crap)
|
||||
{
|
||||
printk(KERN_ERR "PnPBIOS: Warning! Your PnP BIOS caused a fatal error. Attempting to continue\n");
|
||||
printk(KERN_ERR "PnPBIOS: You may need to reboot with the \"pnpbios=off\" option to operate stably\n");
|
||||
printk(KERN_ERR "PnPBIOS: Check with your vendor for an updated BIOS\n");
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void pnpbios_print_status(const char * module, u16 status)
|
||||
{
|
||||
switch(status) {
|
||||
case PNP_SUCCESS:
|
||||
printk(KERN_ERR "PnPBIOS: %s: function successful\n", module);
|
||||
break;
|
||||
case PNP_NOT_SET_STATICALLY:
|
||||
printk(KERN_ERR "PnPBIOS: %s: unable to set static resources\n", module);
|
||||
break;
|
||||
case PNP_UNKNOWN_FUNCTION:
|
||||
printk(KERN_ERR "PnPBIOS: %s: invalid function number passed\n", module);
|
||||
break;
|
||||
case PNP_FUNCTION_NOT_SUPPORTED:
|
||||
printk(KERN_ERR "PnPBIOS: %s: function not supported on this system\n", module);
|
||||
break;
|
||||
case PNP_INVALID_HANDLE:
|
||||
printk(KERN_ERR "PnPBIOS: %s: invalid handle\n", module);
|
||||
break;
|
||||
case PNP_BAD_PARAMETER:
|
||||
printk(KERN_ERR "PnPBIOS: %s: invalid parameters were passed\n", module);
|
||||
break;
|
||||
case PNP_SET_FAILED:
|
||||
printk(KERN_ERR "PnPBIOS: %s: unable to set resources\n", module);
|
||||
break;
|
||||
case PNP_EVENTS_NOT_PENDING:
|
||||
printk(KERN_ERR "PnPBIOS: %s: no events are pending\n", module);
|
||||
break;
|
||||
case PNP_SYSTEM_NOT_DOCKED:
|
||||
printk(KERN_ERR "PnPBIOS: %s: the system is not docked\n", module);
|
||||
break;
|
||||
case PNP_NO_ISA_PNP_CARDS:
|
||||
printk(KERN_ERR "PnPBIOS: %s: no isapnp cards are installed on this system\n", module);
|
||||
break;
|
||||
case PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES:
|
||||
printk(KERN_ERR "PnPBIOS: %s: cannot determine the capabilities of the docking station\n", module);
|
||||
break;
|
||||
case PNP_CONFIG_CHANGE_FAILED_NO_BATTERY:
|
||||
printk(KERN_ERR "PnPBIOS: %s: unable to undock, the system does not have a battery\n", module);
|
||||
break;
|
||||
case PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT:
|
||||
printk(KERN_ERR "PnPBIOS: %s: could not dock due to resource conflicts\n", module);
|
||||
break;
|
||||
case PNP_BUFFER_TOO_SMALL:
|
||||
printk(KERN_ERR "PnPBIOS: %s: the buffer passed is too small\n", module);
|
||||
break;
|
||||
case PNP_USE_ESCD_SUPPORT:
|
||||
printk(KERN_ERR "PnPBIOS: %s: use ESCD instead\n", module);
|
||||
break;
|
||||
case PNP_MESSAGE_NOT_SUPPORTED:
|
||||
printk(KERN_ERR "PnPBIOS: %s: the message is unsupported\n", module);
|
||||
break;
|
||||
case PNP_HARDWARE_ERROR:
|
||||
printk(KERN_ERR "PnPBIOS: %s: a hardware failure has occured\n", module);
|
||||
break;
|
||||
default:
|
||||
printk(KERN_ERR "PnPBIOS: %s: unexpected status 0x%x\n", module, status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* PnP BIOS Low Level Calls
|
||||
*/
|
||||
|
||||
#define PNP_GET_NUM_SYS_DEV_NODES 0x00
|
||||
#define PNP_GET_SYS_DEV_NODE 0x01
|
||||
#define PNP_SET_SYS_DEV_NODE 0x02
|
||||
#define PNP_GET_EVENT 0x03
|
||||
#define PNP_SEND_MESSAGE 0x04
|
||||
#define PNP_GET_DOCKING_STATION_INFORMATION 0x05
|
||||
#define PNP_SET_STATIC_ALLOCED_RES_INFO 0x09
|
||||
#define PNP_GET_STATIC_ALLOCED_RES_INFO 0x0a
|
||||
#define PNP_GET_APM_ID_TABLE 0x0b
|
||||
#define PNP_GET_PNP_ISA_CONFIG_STRUC 0x40
|
||||
#define PNP_GET_ESCD_INFO 0x41
|
||||
#define PNP_READ_ESCD 0x42
|
||||
#define PNP_WRITE_ESCD 0x43
|
||||
|
||||
/*
|
||||
* Call PnP BIOS with function 0x00, "get number of system device nodes"
|
||||
*/
|
||||
static int __pnp_bios_dev_node_info(struct pnp_dev_node_info *data)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_GET_NUM_SYS_DEV_NODES, 0, PNP_TS1, 2, PNP_TS1, PNP_DS, 0, 0,
|
||||
data, sizeof(struct pnp_dev_node_info), NULL, 0);
|
||||
data->no_nodes &= 0xff;
|
||||
return status;
|
||||
}
|
||||
|
||||
int pnp_bios_dev_node_info(struct pnp_dev_node_info *data)
|
||||
{
|
||||
int status = __pnp_bios_dev_node_info( data );
|
||||
if ( status )
|
||||
pnpbios_print_status( "dev_node_info", status );
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Note that some PnP BIOSes (e.g., on Sony Vaio laptops) die a horrible
|
||||
* death if they are asked to access the "current" configuration.
|
||||
* Therefore, if it's a matter of indifference, it's better to call
|
||||
* get_dev_node() and set_dev_node() with boot=1 rather than with boot=0.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Call PnP BIOS with function 0x01, "get system device node"
|
||||
* Input: *nodenum = desired node,
|
||||
* boot = whether to get nonvolatile boot (!=0)
|
||||
* or volatile current (0) config
|
||||
* Output: *nodenum=next node or 0xff if no more nodes
|
||||
*/
|
||||
static int __pnp_bios_get_dev_node(u8 *nodenum, char boot, struct pnp_bios_node *data)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
if ( !boot && pnpbios_dont_use_current_config )
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_GET_SYS_DEV_NODE, 0, PNP_TS1, 0, PNP_TS2, boot ? 2 : 1, PNP_DS, 0,
|
||||
nodenum, sizeof(char), data, 65536);
|
||||
return status;
|
||||
}
|
||||
|
||||
int pnp_bios_get_dev_node(u8 *nodenum, char boot, struct pnp_bios_node *data)
|
||||
{
|
||||
int status;
|
||||
status = __pnp_bios_get_dev_node( nodenum, boot, data );
|
||||
if ( status )
|
||||
pnpbios_print_status( "get_dev_node", status );
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Call PnP BIOS with function 0x02, "set system device node"
|
||||
* Input: *nodenum = desired node,
|
||||
* boot = whether to set nonvolatile boot (!=0)
|
||||
* or volatile current (0) config
|
||||
*/
|
||||
static int __pnp_bios_set_dev_node(u8 nodenum, char boot, struct pnp_bios_node *data)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
if ( !boot && pnpbios_dont_use_current_config )
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_SET_SYS_DEV_NODE, nodenum, 0, PNP_TS1, boot ? 2 : 1, PNP_DS, 0, 0,
|
||||
data, 65536, NULL, 0);
|
||||
return status;
|
||||
}
|
||||
|
||||
int pnp_bios_set_dev_node(u8 nodenum, char boot, struct pnp_bios_node *data)
|
||||
{
|
||||
int status;
|
||||
status = __pnp_bios_set_dev_node( nodenum, boot, data );
|
||||
if ( status ) {
|
||||
pnpbios_print_status( "set_dev_node", status );
|
||||
return status;
|
||||
}
|
||||
if ( !boot ) { /* Update devlist */
|
||||
status = pnp_bios_get_dev_node( &nodenum, boot, data );
|
||||
if ( status )
|
||||
return status;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
#if needed
|
||||
/*
|
||||
* Call PnP BIOS with function 0x03, "get event"
|
||||
*/
|
||||
static int pnp_bios_get_event(u16 *event)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_GET_EVENT, 0, PNP_TS1, PNP_DS, 0, 0 ,0 ,0,
|
||||
event, sizeof(u16), NULL, 0);
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if needed
|
||||
/*
|
||||
* Call PnP BIOS with function 0x04, "send message"
|
||||
*/
|
||||
static int pnp_bios_send_message(u16 message)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_SEND_MESSAGE, message, PNP_DS, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Call PnP BIOS with function 0x05, "get docking station information"
|
||||
*/
|
||||
int pnp_bios_dock_station_info(struct pnp_docking_station_info *data)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_GET_DOCKING_STATION_INFORMATION, 0, PNP_TS1, PNP_DS, 0, 0, 0, 0,
|
||||
data, sizeof(struct pnp_docking_station_info), NULL, 0);
|
||||
return status;
|
||||
}
|
||||
|
||||
#if needed
|
||||
/*
|
||||
* Call PnP BIOS with function 0x09, "set statically allocated resource
|
||||
* information"
|
||||
*/
|
||||
static int pnp_bios_set_stat_res(char *info)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_SET_STATIC_ALLOCED_RES_INFO, 0, PNP_TS1, PNP_DS, 0, 0, 0, 0,
|
||||
info, *((u16 *) info), 0, 0);
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Call PnP BIOS with function 0x0a, "get statically allocated resource
|
||||
* information"
|
||||
*/
|
||||
static int __pnp_bios_get_stat_res(char *info)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_GET_STATIC_ALLOCED_RES_INFO, 0, PNP_TS1, PNP_DS, 0, 0, 0, 0,
|
||||
info, 65536, NULL, 0);
|
||||
return status;
|
||||
}
|
||||
|
||||
int pnp_bios_get_stat_res(char *info)
|
||||
{
|
||||
int status;
|
||||
status = __pnp_bios_get_stat_res( info );
|
||||
if ( status )
|
||||
pnpbios_print_status( "get_stat_res", status );
|
||||
return status;
|
||||
}
|
||||
|
||||
#if needed
|
||||
/*
|
||||
* Call PnP BIOS with function 0x0b, "get APM id table"
|
||||
*/
|
||||
static int pnp_bios_apm_id_table(char *table, u16 *size)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_GET_APM_ID_TABLE, 0, PNP_TS2, 0, PNP_TS1, PNP_DS, 0, 0,
|
||||
table, *size, size, sizeof(u16));
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Call PnP BIOS with function 0x40, "get isa pnp configuration structure"
|
||||
*/
|
||||
static int __pnp_bios_isapnp_config(struct pnp_isa_config_struc *data)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return PNP_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_GET_PNP_ISA_CONFIG_STRUC, 0, PNP_TS1, PNP_DS, 0, 0, 0, 0,
|
||||
data, sizeof(struct pnp_isa_config_struc), NULL, 0);
|
||||
return status;
|
||||
}
|
||||
|
||||
int pnp_bios_isapnp_config(struct pnp_isa_config_struc *data)
|
||||
{
|
||||
int status;
|
||||
status = __pnp_bios_isapnp_config( data );
|
||||
if ( status )
|
||||
pnpbios_print_status( "isapnp_config", status );
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Call PnP BIOS with function 0x41, "get ESCD info"
|
||||
*/
|
||||
static int __pnp_bios_escd_info(struct escd_info_struc *data)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return ESCD_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_GET_ESCD_INFO, 0, PNP_TS1, 2, PNP_TS1, 4, PNP_TS1, PNP_DS,
|
||||
data, sizeof(struct escd_info_struc), NULL, 0);
|
||||
return status;
|
||||
}
|
||||
|
||||
int pnp_bios_escd_info(struct escd_info_struc *data)
|
||||
{
|
||||
int status;
|
||||
status = __pnp_bios_escd_info( data );
|
||||
if ( status )
|
||||
pnpbios_print_status( "escd_info", status );
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Call PnP BIOS function 0x42, "read ESCD"
|
||||
* nvram_base is determined by calling escd_info
|
||||
*/
|
||||
static int __pnp_bios_read_escd(char *data, u32 nvram_base)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return ESCD_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_READ_ESCD, 0, PNP_TS1, PNP_TS2, PNP_DS, 0, 0, 0,
|
||||
data, 65536, __va(nvram_base), 65536);
|
||||
return status;
|
||||
}
|
||||
|
||||
int pnp_bios_read_escd(char *data, u32 nvram_base)
|
||||
{
|
||||
int status;
|
||||
status = __pnp_bios_read_escd( data, nvram_base );
|
||||
if ( status )
|
||||
pnpbios_print_status( "read_escd", status );
|
||||
return status;
|
||||
}
|
||||
|
||||
#if needed
|
||||
/*
|
||||
* Call PnP BIOS function 0x43, "write ESCD"
|
||||
*/
|
||||
static int pnp_bios_write_escd(char *data, u32 nvram_base)
|
||||
{
|
||||
u16 status;
|
||||
if (!pnp_bios_present())
|
||||
return ESCD_FUNCTION_NOT_SUPPORTED;
|
||||
status = call_pnp_bios(PNP_WRITE_ESCD, 0, PNP_TS1, PNP_TS2, PNP_DS, 0, 0, 0,
|
||||
data, 65536, __va(nvram_base), 65536);
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Initialization
|
||||
*/
|
||||
|
||||
void pnpbios_calls_init(union pnp_bios_install_struct *header)
|
||||
{
|
||||
int i;
|
||||
spin_lock_init(&pnp_bios_lock);
|
||||
pnp_bios_callpoint.offset = header->fields.pm16offset;
|
||||
pnp_bios_callpoint.segment = PNP_CS16;
|
||||
|
||||
set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
|
||||
_set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
|
||||
for(i=0; i < NR_CPUS; i++)
|
||||
{
|
||||
Q2_SET_SEL(i, PNP_CS32, &pnp_bios_callfunc, 64 * 1024);
|
||||
Q_SET_SEL(i, PNP_CS16, header->fields.pm16cseg, 64 * 1024);
|
||||
Q_SET_SEL(i, PNP_DS, header->fields.pm16dseg, 64 * 1024);
|
||||
}
|
||||
}
|
||||
644
drivers/pnp/pnpbios/core.c
Normal file
644
drivers/pnp/pnpbios/core.c
Normal file
|
|
@ -0,0 +1,644 @@
|
|||
/*
|
||||
* pnpbios -- PnP BIOS driver
|
||||
*
|
||||
* This driver provides access to Plug-'n'-Play services provided by
|
||||
* the PnP BIOS firmware, described in the following documents:
|
||||
* Plug and Play BIOS Specification, Version 1.0A, 5 May 1994
|
||||
* Plug and Play BIOS Clarification Paper, 6 October 1994
|
||||
* Compaq Computer Corporation, Phoenix Technologies Ltd., Intel Corp.
|
||||
*
|
||||
* Originally (C) 1998 Christian Schmidt <schmidt@digadd.de>
|
||||
* Modifications (C) 1998 Tom Lees <tom@lpsg.demon.co.uk>
|
||||
* Minor reorganizations by David Hinds <dahinds@users.sourceforge.net>
|
||||
* Further modifications (C) 2001, 2002 by:
|
||||
* Alan Cox <alan@redhat.com>
|
||||
* Thomas Hood
|
||||
* Brian Gerst <bgerst@didntduck.org>
|
||||
*
|
||||
* Ported to the PnP Layer and several additional improvements (C) 2002
|
||||
* by Adam Belay <ambx1@neo.rr.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* Change Log
|
||||
*
|
||||
* Adam Belay - <ambx1@neo.rr.com> - March 16, 2003
|
||||
* rev 1.01 Only call pnp_bios_dev_node_info once
|
||||
* Added pnpbios_print_status
|
||||
* Added several new error messages and info messages
|
||||
* Added pnpbios_interface_attach_device
|
||||
* integrated core and proc init system
|
||||
* Introduced PNPMODE flags
|
||||
* Removed some useless includes
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/linkage.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/pnpbios.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/pnp.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/smp.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/kobject_uevent.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/dmi.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/acpi.h>
|
||||
|
||||
#include <asm/page.h>
|
||||
#include <asm/desc.h>
|
||||
#include <asm/system.h>
|
||||
#include <asm/byteorder.h>
|
||||
|
||||
#include "pnpbios.h"
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* PnP BIOS INTERFACE
|
||||
*
|
||||
*/
|
||||
|
||||
static union pnp_bios_install_struct * pnp_bios_install = NULL;
|
||||
|
||||
int pnp_bios_present(void)
|
||||
{
|
||||
return (pnp_bios_install != NULL);
|
||||
}
|
||||
|
||||
struct pnp_dev_node_info node_info;
|
||||
|
||||
void *pnpbios_kmalloc(size_t size, int f)
|
||||
{
|
||||
void *p = kmalloc( size, f );
|
||||
if ( p == NULL )
|
||||
printk(KERN_ERR "PnPBIOS: kmalloc() failed\n");
|
||||
else
|
||||
memset(p, 0, size);
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* DOCKING FUNCTIONS
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_HOTPLUG
|
||||
|
||||
static int unloading = 0;
|
||||
static struct completion unload_sem;
|
||||
|
||||
/*
|
||||
* (Much of this belongs in a shared routine somewhere)
|
||||
*/
|
||||
|
||||
static int pnp_dock_event(int dock, struct pnp_docking_station_info *info)
|
||||
{
|
||||
char *argv [3], **envp, *buf, *scratch;
|
||||
int i = 0, value;
|
||||
|
||||
if (!hotplug_path [0])
|
||||
return -ENOENT;
|
||||
if (!current->fs->root) {
|
||||
return -EAGAIN;
|
||||
}
|
||||
if (!(envp = (char **) pnpbios_kmalloc (20 * sizeof (char *), GFP_KERNEL))) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
if (!(buf = pnpbios_kmalloc (256, GFP_KERNEL))) {
|
||||
kfree (envp);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* only one standardized param to hotplug command: type */
|
||||
argv [0] = hotplug_path;
|
||||
argv [1] = "dock";
|
||||
argv [2] = NULL;
|
||||
|
||||
/* minimal command environment */
|
||||
envp [i++] = "HOME=/";
|
||||
envp [i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
|
||||
|
||||
#ifdef DEBUG
|
||||
/* hint that policy agent should enter no-stdout debug mode */
|
||||
envp [i++] = "DEBUG=kernel";
|
||||
#endif
|
||||
/* extensible set of named bus-specific parameters,
|
||||
* supporting multiple driver selection algorithms.
|
||||
*/
|
||||
scratch = buf;
|
||||
|
||||
/* action: add, remove */
|
||||
envp [i++] = scratch;
|
||||
scratch += sprintf (scratch, "ACTION=%s", dock?"add":"remove") + 1;
|
||||
|
||||
/* Report the ident for the dock */
|
||||
envp [i++] = scratch;
|
||||
scratch += sprintf (scratch, "DOCK=%x/%x/%x",
|
||||
info->location_id, info->serial, info->capabilities);
|
||||
envp[i] = NULL;
|
||||
|
||||
value = call_usermodehelper (argv [0], argv, envp, 0);
|
||||
kfree (buf);
|
||||
kfree (envp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Poll the PnP docking at regular intervals
|
||||
*/
|
||||
static int pnp_dock_thread(void * unused)
|
||||
{
|
||||
static struct pnp_docking_station_info now;
|
||||
int docked = -1, d = 0;
|
||||
daemonize("kpnpbiosd");
|
||||
allow_signal(SIGKILL);
|
||||
while(!unloading && !signal_pending(current))
|
||||
{
|
||||
int status;
|
||||
|
||||
/*
|
||||
* Poll every 2 seconds
|
||||
*/
|
||||
msleep_interruptible(2000);
|
||||
|
||||
if(signal_pending(current)) {
|
||||
if (try_to_freeze(PF_FREEZE))
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
status = pnp_bios_dock_station_info(&now);
|
||||
|
||||
switch(status)
|
||||
{
|
||||
/*
|
||||
* No dock to manage
|
||||
*/
|
||||
case PNP_FUNCTION_NOT_SUPPORTED:
|
||||
complete_and_exit(&unload_sem, 0);
|
||||
case PNP_SYSTEM_NOT_DOCKED:
|
||||
d = 0;
|
||||
break;
|
||||
case PNP_SUCCESS:
|
||||
d = 1;
|
||||
break;
|
||||
default:
|
||||
pnpbios_print_status( "pnp_dock_thread", status );
|
||||
continue;
|
||||
}
|
||||
if(d != docked)
|
||||
{
|
||||
if(pnp_dock_event(d, &now)==0)
|
||||
{
|
||||
docked = d;
|
||||
#if 0
|
||||
printk(KERN_INFO "PnPBIOS: Docking station %stached\n", docked?"at":"de");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
complete_and_exit(&unload_sem, 0);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_HOTPLUG */
|
||||
|
||||
static int pnpbios_get_resources(struct pnp_dev * dev, struct pnp_resource_table * res)
|
||||
{
|
||||
u8 nodenum = dev->number;
|
||||
struct pnp_bios_node * node;
|
||||
|
||||
/* just in case */
|
||||
if(!pnpbios_is_dynamic(dev))
|
||||
return -EPERM;
|
||||
|
||||
node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL);
|
||||
if (!node)
|
||||
return -1;
|
||||
if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) {
|
||||
kfree(node);
|
||||
return -ENODEV;
|
||||
}
|
||||
pnpbios_read_resources_from_node(res, node);
|
||||
dev->active = pnp_is_active(dev);
|
||||
kfree(node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pnpbios_set_resources(struct pnp_dev * dev, struct pnp_resource_table * res)
|
||||
{
|
||||
u8 nodenum = dev->number;
|
||||
struct pnp_bios_node * node;
|
||||
int ret;
|
||||
|
||||
/* just in case */
|
||||
if (!pnpbios_is_dynamic(dev))
|
||||
return -EPERM;
|
||||
|
||||
node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL);
|
||||
if (!node)
|
||||
return -1;
|
||||
if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) {
|
||||
kfree(node);
|
||||
return -ENODEV;
|
||||
}
|
||||
if(pnpbios_write_resources_to_node(res, node)<0) {
|
||||
kfree(node);
|
||||
return -1;
|
||||
}
|
||||
ret = pnp_bios_set_dev_node(node->handle, (char)PNPMODE_DYNAMIC, node);
|
||||
kfree(node);
|
||||
if (ret > 0)
|
||||
ret = -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void pnpbios_zero_data_stream(struct pnp_bios_node * node)
|
||||
{
|
||||
unsigned char * p = (char *)node->data;
|
||||
unsigned char * end = (char *)(node->data + node->size);
|
||||
unsigned int len;
|
||||
int i;
|
||||
while ((char *)p < (char *)end) {
|
||||
if(p[0] & 0x80) { /* large tag */
|
||||
len = (p[2] << 8) | p[1];
|
||||
p += 3;
|
||||
} else {
|
||||
if (((p[0]>>3) & 0x0f) == 0x0f)
|
||||
return;
|
||||
len = p[0] & 0x07;
|
||||
p += 1;
|
||||
}
|
||||
for (i = 0; i < len; i++)
|
||||
p[i] = 0;
|
||||
p += len;
|
||||
}
|
||||
printk(KERN_ERR "PnPBIOS: Resource structure did not contain an end tag.\n");
|
||||
}
|
||||
|
||||
static int pnpbios_disable_resources(struct pnp_dev *dev)
|
||||
{
|
||||
struct pnp_bios_node * node;
|
||||
u8 nodenum = dev->number;
|
||||
int ret;
|
||||
|
||||
/* just in case */
|
||||
if(dev->flags & PNPBIOS_NO_DISABLE || !pnpbios_is_dynamic(dev))
|
||||
return -EPERM;
|
||||
|
||||
node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL);
|
||||
if (!node)
|
||||
return -ENOMEM;
|
||||
|
||||
if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) {
|
||||
kfree(node);
|
||||
return -ENODEV;
|
||||
}
|
||||
pnpbios_zero_data_stream(node);
|
||||
|
||||
ret = pnp_bios_set_dev_node(dev->number, (char)PNPMODE_DYNAMIC, node);
|
||||
kfree(node);
|
||||
if (ret > 0)
|
||||
ret = -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* PnP Layer support */
|
||||
|
||||
struct pnp_protocol pnpbios_protocol = {
|
||||
.name = "Plug and Play BIOS",
|
||||
.get = pnpbios_get_resources,
|
||||
.set = pnpbios_set_resources,
|
||||
.disable = pnpbios_disable_resources,
|
||||
};
|
||||
|
||||
static int insert_device(struct pnp_dev *dev, struct pnp_bios_node * node)
|
||||
{
|
||||
struct list_head * pos;
|
||||
struct pnp_dev * pnp_dev;
|
||||
struct pnp_id *dev_id;
|
||||
char id[8];
|
||||
|
||||
/* check if the device is already added */
|
||||
dev->number = node->handle;
|
||||
list_for_each (pos, &pnpbios_protocol.devices){
|
||||
pnp_dev = list_entry(pos, struct pnp_dev, protocol_list);
|
||||
if (dev->number == pnp_dev->number)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* set the initial values for the PnP device */
|
||||
dev_id = pnpbios_kmalloc(sizeof(struct pnp_id), GFP_KERNEL);
|
||||
if (!dev_id)
|
||||
return -1;
|
||||
pnpid32_to_pnpid(node->eisa_id,id);
|
||||
memcpy(dev_id->id,id,7);
|
||||
pnp_add_id(dev_id, dev);
|
||||
pnpbios_parse_data_stream(dev, node);
|
||||
dev->active = pnp_is_active(dev);
|
||||
dev->flags = node->flags;
|
||||
if (!(dev->flags & PNPBIOS_NO_CONFIG))
|
||||
dev->capabilities |= PNP_CONFIGURABLE;
|
||||
if (!(dev->flags & PNPBIOS_NO_DISABLE))
|
||||
dev->capabilities |= PNP_DISABLE;
|
||||
dev->capabilities |= PNP_READ;
|
||||
if (pnpbios_is_dynamic(dev))
|
||||
dev->capabilities |= PNP_WRITE;
|
||||
if (dev->flags & PNPBIOS_REMOVABLE)
|
||||
dev->capabilities |= PNP_REMOVABLE;
|
||||
dev->protocol = &pnpbios_protocol;
|
||||
|
||||
/* clear out the damaged flags */
|
||||
if (!dev->active)
|
||||
pnp_init_resource_table(&dev->res);
|
||||
|
||||
pnp_add_device(dev);
|
||||
pnpbios_interface_attach_device(node);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __init build_devlist(void)
|
||||
{
|
||||
u8 nodenum;
|
||||
unsigned int nodes_got = 0;
|
||||
unsigned int devs = 0;
|
||||
struct pnp_bios_node *node;
|
||||
struct pnp_dev *dev;
|
||||
|
||||
node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL);
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
for(nodenum=0; nodenum<0xff; ) {
|
||||
u8 thisnodenum = nodenum;
|
||||
/* eventually we will want to use PNPMODE_STATIC here but for now
|
||||
* dynamic will help us catch buggy bioses to add to the blacklist.
|
||||
*/
|
||||
if (!pnpbios_dont_use_current_config) {
|
||||
if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node))
|
||||
break;
|
||||
} else {
|
||||
if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_STATIC, node))
|
||||
break;
|
||||
}
|
||||
nodes_got++;
|
||||
dev = pnpbios_kmalloc(sizeof (struct pnp_dev), GFP_KERNEL);
|
||||
if (!dev)
|
||||
break;
|
||||
if(insert_device(dev,node)<0)
|
||||
kfree(dev);
|
||||
else
|
||||
devs++;
|
||||
if (nodenum <= thisnodenum) {
|
||||
printk(KERN_ERR "PnPBIOS: build_devlist: Node number 0x%x is out of sequence following node 0x%x. Aborting.\n", (unsigned int)nodenum, (unsigned int)thisnodenum);
|
||||
break;
|
||||
}
|
||||
}
|
||||
kfree(node);
|
||||
|
||||
printk(KERN_INFO "PnPBIOS: %i node%s reported by PnP BIOS; %i recorded by driver\n",
|
||||
nodes_got, nodes_got != 1 ? "s" : "", devs);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* INIT AND EXIT
|
||||
*
|
||||
*/
|
||||
|
||||
static int pnpbios_disabled; /* = 0 */
|
||||
int pnpbios_dont_use_current_config; /* = 0 */
|
||||
|
||||
#ifndef MODULE
|
||||
static int __init pnpbios_setup(char *str)
|
||||
{
|
||||
int invert;
|
||||
|
||||
while ((str != NULL) && (*str != '\0')) {
|
||||
if (strncmp(str, "off", 3) == 0)
|
||||
pnpbios_disabled=1;
|
||||
if (strncmp(str, "on", 2) == 0)
|
||||
pnpbios_disabled=0;
|
||||
invert = (strncmp(str, "no-", 3) == 0);
|
||||
if (invert)
|
||||
str += 3;
|
||||
if (strncmp(str, "curr", 4) == 0)
|
||||
pnpbios_dont_use_current_config = invert;
|
||||
str = strchr(str, ',');
|
||||
if (str != NULL)
|
||||
str += strspn(str, ", \t");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
__setup("pnpbios=", pnpbios_setup);
|
||||
#endif
|
||||
|
||||
/* PnP BIOS signature: "$PnP" */
|
||||
#define PNP_SIGNATURE (('$' << 0) + ('P' << 8) + ('n' << 16) + ('P' << 24))
|
||||
|
||||
static int __init pnpbios_probe_system(void)
|
||||
{
|
||||
union pnp_bios_install_struct *check;
|
||||
u8 sum;
|
||||
int length, i;
|
||||
|
||||
printk(KERN_INFO "PnPBIOS: Scanning system for PnP BIOS support...\n");
|
||||
|
||||
/*
|
||||
* Search the defined area (0xf0000-0xffff0) for a valid PnP BIOS
|
||||
* structure and, if one is found, sets up the selectors and
|
||||
* entry points
|
||||
*/
|
||||
for (check = (union pnp_bios_install_struct *) __va(0xf0000);
|
||||
check < (union pnp_bios_install_struct *) __va(0xffff0);
|
||||
check = (void *)check + 16) {
|
||||
if (check->fields.signature != PNP_SIGNATURE)
|
||||
continue;
|
||||
printk(KERN_INFO "PnPBIOS: Found PnP BIOS installation structure at 0x%p\n", check);
|
||||
length = check->fields.length;
|
||||
if (!length) {
|
||||
printk(KERN_ERR "PnPBIOS: installation structure is invalid, skipping\n");
|
||||
continue;
|
||||
}
|
||||
for (sum = 0, i = 0; i < length; i++)
|
||||
sum += check->chars[i];
|
||||
if (sum) {
|
||||
printk(KERN_ERR "PnPBIOS: installation structure is corrupted, skipping\n");
|
||||
continue;
|
||||
}
|
||||
if (check->fields.version < 0x10) {
|
||||
printk(KERN_WARNING "PnPBIOS: PnP BIOS version %d.%d is not supported\n",
|
||||
check->fields.version >> 4,
|
||||
check->fields.version & 15);
|
||||
continue;
|
||||
}
|
||||
printk(KERN_INFO "PnPBIOS: PnP BIOS version %d.%d, entry 0x%x:0x%x, dseg 0x%x\n",
|
||||
check->fields.version >> 4, check->fields.version & 15,
|
||||
check->fields.pm16cseg, check->fields.pm16offset,
|
||||
check->fields.pm16dseg);
|
||||
pnp_bios_install = check;
|
||||
return 1;
|
||||
}
|
||||
|
||||
printk(KERN_INFO "PnPBIOS: PnP BIOS support was not detected.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __init exploding_pnp_bios(struct dmi_system_id *d)
|
||||
{
|
||||
printk(KERN_WARNING "%s detected. Disabling PnPBIOS\n", d->ident);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct dmi_system_id pnpbios_dmi_table[] = {
|
||||
{ /* PnPBIOS GPF on boot */
|
||||
.callback = exploding_pnp_bios,
|
||||
.ident = "Higraded P14H",
|
||||
.matches = {
|
||||
DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
|
||||
DMI_MATCH(DMI_BIOS_VERSION, "07.00T"),
|
||||
DMI_MATCH(DMI_SYS_VENDOR, "Higraded"),
|
||||
DMI_MATCH(DMI_PRODUCT_NAME, "P14H"),
|
||||
},
|
||||
},
|
||||
{ /* PnPBIOS GPF on boot */
|
||||
.callback = exploding_pnp_bios,
|
||||
.ident = "ASUS P4P800",
|
||||
.matches = {
|
||||
DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer Inc."),
|
||||
DMI_MATCH(DMI_BOARD_NAME, "P4P800"),
|
||||
},
|
||||
},
|
||||
{ }
|
||||
};
|
||||
|
||||
static int __init pnpbios_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (pnpbios_disabled || dmi_check_system(pnpbios_dmi_table)) {
|
||||
printk(KERN_INFO "PnPBIOS: Disabled\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PNPACPI
|
||||
if (!acpi_disabled && !pnpacpi_disabled) {
|
||||
pnpbios_disabled = 1;
|
||||
printk(KERN_INFO "PnPBIOS: Disabled by ACPI PNP\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
#endif /* CONFIG_ACPI */
|
||||
|
||||
/* scan the system for pnpbios support */
|
||||
if (!pnpbios_probe_system())
|
||||
return -ENODEV;
|
||||
|
||||
/* make preparations for bios calls */
|
||||
pnpbios_calls_init(pnp_bios_install);
|
||||
|
||||
/* read the node info */
|
||||
ret = pnp_bios_dev_node_info(&node_info);
|
||||
if (ret) {
|
||||
printk(KERN_ERR "PnPBIOS: Unable to get node info. Aborting.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* register with the pnp layer */
|
||||
ret = pnp_register_protocol(&pnpbios_protocol);
|
||||
if (ret) {
|
||||
printk(KERN_ERR "PnPBIOS: Unable to register driver. Aborting.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* start the proc interface */
|
||||
ret = pnpbios_proc_init();
|
||||
if (ret)
|
||||
printk(KERN_ERR "PnPBIOS: Failed to create proc interface.\n");
|
||||
|
||||
/* scan for pnpbios devices */
|
||||
build_devlist();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
subsys_initcall(pnpbios_init);
|
||||
|
||||
static int __init pnpbios_thread_init(void)
|
||||
{
|
||||
if (pnpbios_disabled)
|
||||
return 0;
|
||||
#ifdef CONFIG_HOTPLUG
|
||||
init_completion(&unload_sem);
|
||||
if (kernel_thread(pnp_dock_thread, NULL, CLONE_KERNEL) > 0)
|
||||
unloading = 0;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef MODULE
|
||||
|
||||
/* init/main.c calls pnpbios_init early */
|
||||
|
||||
/* Start the kernel thread later: */
|
||||
module_init(pnpbios_thread_init);
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* N.B.: Building pnpbios as a module hasn't been fully implemented
|
||||
*/
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static int __init pnpbios_init_all(void)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = pnpbios_init();
|
||||
if (r)
|
||||
return r;
|
||||
r = pnpbios_thread_init();
|
||||
if (r)
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit pnpbios_exit(void)
|
||||
{
|
||||
#ifdef CONFIG_HOTPLUG
|
||||
unloading = 1;
|
||||
wait_for_completion(&unload_sem);
|
||||
#endif
|
||||
pnpbios_proc_exit();
|
||||
/* We ought to free resources here */
|
||||
return;
|
||||
}
|
||||
|
||||
module_init(pnpbios_init_all);
|
||||
module_exit(pnpbios_exit);
|
||||
|
||||
#endif
|
||||
|
||||
EXPORT_SYMBOL(pnpbios_protocol);
|
||||
47
drivers/pnp/pnpbios/pnpbios.h
Normal file
47
drivers/pnp/pnpbios/pnpbios.h
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* pnpbios.h - contains local definitions
|
||||
*/
|
||||
|
||||
#pragma pack(1)
|
||||
union pnp_bios_install_struct {
|
||||
struct {
|
||||
u32 signature; /* "$PnP" */
|
||||
u8 version; /* in BCD */
|
||||
u8 length; /* length in bytes, currently 21h */
|
||||
u16 control; /* system capabilities */
|
||||
u8 checksum; /* all bytes must add up to 0 */
|
||||
|
||||
u32 eventflag; /* phys. address of the event flag */
|
||||
u16 rmoffset; /* real mode entry point */
|
||||
u16 rmcseg;
|
||||
u16 pm16offset; /* 16 bit protected mode entry */
|
||||
u32 pm16cseg;
|
||||
u32 deviceID; /* EISA encoded system ID or 0 */
|
||||
u16 rmdseg; /* real mode data segment */
|
||||
u32 pm16dseg; /* 16 bit pm data segment base */
|
||||
} fields;
|
||||
char chars[0x21]; /* To calculate the checksum */
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
extern int pnp_bios_present(void);
|
||||
extern int pnpbios_dont_use_current_config;
|
||||
extern void *pnpbios_kmalloc(size_t size, int f);
|
||||
|
||||
extern int pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node * node);
|
||||
extern int pnpbios_read_resources_from_node(struct pnp_resource_table *res, struct pnp_bios_node * node);
|
||||
extern int pnpbios_write_resources_to_node(struct pnp_resource_table *res, struct pnp_bios_node * node);
|
||||
extern void pnpid32_to_pnpid(u32 id, char *str);
|
||||
|
||||
extern void pnpbios_print_status(const char * module, u16 status);
|
||||
extern void pnpbios_calls_init(union pnp_bios_install_struct * header);
|
||||
|
||||
#ifdef CONFIG_PNPBIOS_PROC_FS
|
||||
extern int pnpbios_interface_attach_device(struct pnp_bios_node * node);
|
||||
extern int pnpbios_proc_init (void);
|
||||
extern void pnpbios_proc_exit (void);
|
||||
#else
|
||||
static inline int pnpbios_interface_attach_device(struct pnp_bios_node * node) { return 0; }
|
||||
static inline int pnpbios_proc_init (void) { return 0; }
|
||||
static inline void pnpbios_proc_exit (void) { ; }
|
||||
#endif /* CONFIG_PNPBIOS_PROC_FS */
|
||||
292
drivers/pnp/pnpbios/proc.c
Normal file
292
drivers/pnp/pnpbios/proc.c
Normal file
|
|
@ -0,0 +1,292 @@
|
|||
/*
|
||||
* /proc/bus/pnp interface for Plug and Play devices
|
||||
*
|
||||
* Written by David Hinds, dahinds@users.sourceforge.net
|
||||
* Modified by Thomas Hood
|
||||
*
|
||||
* The .../devices and .../<node> and .../boot/<node> files are
|
||||
* utilized by the lspnp and setpnp utilities, supplied with the
|
||||
* pcmcia-cs package.
|
||||
* http://pcmcia-cs.sourceforge.net
|
||||
*
|
||||
* The .../escd file is utilized by the lsescd utility written by
|
||||
* Gunther Mayer.
|
||||
* http://home.t-online.de/home/gunther.mayer/lsescd
|
||||
*
|
||||
* The .../legacy_device_resources file is not used yet.
|
||||
*
|
||||
* The other files are human-readable.
|
||||
*/
|
||||
|
||||
//#include <pcmcia/config.h>
|
||||
//#include <pcmcia/k_compat.h>
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/pnpbios.h>
|
||||
#include <linux/init.h>
|
||||
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include "pnpbios.h"
|
||||
|
||||
static struct proc_dir_entry *proc_pnp = NULL;
|
||||
static struct proc_dir_entry *proc_pnp_boot = NULL;
|
||||
|
||||
static int proc_read_pnpconfig(char *buf, char **start, off_t pos,
|
||||
int count, int *eof, void *data)
|
||||
{
|
||||
struct pnp_isa_config_struc pnps;
|
||||
|
||||
if (pnp_bios_isapnp_config(&pnps))
|
||||
return -EIO;
|
||||
return snprintf(buf, count,
|
||||
"structure_revision %d\n"
|
||||
"number_of_CSNs %d\n"
|
||||
"ISA_read_data_port 0x%x\n",
|
||||
pnps.revision,
|
||||
pnps.no_csns,
|
||||
pnps.isa_rd_data_port
|
||||
);
|
||||
}
|
||||
|
||||
static int proc_read_escdinfo(char *buf, char **start, off_t pos,
|
||||
int count, int *eof, void *data)
|
||||
{
|
||||
struct escd_info_struc escd;
|
||||
|
||||
if (pnp_bios_escd_info(&escd))
|
||||
return -EIO;
|
||||
return snprintf(buf, count,
|
||||
"min_ESCD_write_size %d\n"
|
||||
"ESCD_size %d\n"
|
||||
"NVRAM_base 0x%x\n",
|
||||
escd.min_escd_write_size,
|
||||
escd.escd_size,
|
||||
escd.nv_storage_base
|
||||
);
|
||||
}
|
||||
|
||||
#define MAX_SANE_ESCD_SIZE (32*1024)
|
||||
static int proc_read_escd(char *buf, char **start, off_t pos,
|
||||
int count, int *eof, void *data)
|
||||
{
|
||||
struct escd_info_struc escd;
|
||||
char *tmpbuf;
|
||||
int escd_size, escd_left_to_read, n;
|
||||
|
||||
if (pnp_bios_escd_info(&escd))
|
||||
return -EIO;
|
||||
|
||||
/* sanity check */
|
||||
if (escd.escd_size > MAX_SANE_ESCD_SIZE) {
|
||||
printk(KERN_ERR "PnPBIOS: proc_read_escd: ESCD size reported by BIOS escd_info call is too great\n");
|
||||
return -EFBIG;
|
||||
}
|
||||
|
||||
tmpbuf = pnpbios_kmalloc(escd.escd_size, GFP_KERNEL);
|
||||
if (!tmpbuf) return -ENOMEM;
|
||||
|
||||
if (pnp_bios_read_escd(tmpbuf, escd.nv_storage_base)) {
|
||||
kfree(tmpbuf);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
escd_size = (unsigned char)(tmpbuf[0]) + (unsigned char)(tmpbuf[1])*256;
|
||||
|
||||
/* sanity check */
|
||||
if (escd_size > MAX_SANE_ESCD_SIZE) {
|
||||
printk(KERN_ERR "PnPBIOS: proc_read_escd: ESCD size reported by BIOS read_escd call is too great\n");
|
||||
return -EFBIG;
|
||||
}
|
||||
|
||||
escd_left_to_read = escd_size - pos;
|
||||
if (escd_left_to_read < 0) escd_left_to_read = 0;
|
||||
if (escd_left_to_read == 0) *eof = 1;
|
||||
n = min(count,escd_left_to_read);
|
||||
memcpy(buf, tmpbuf + pos, n);
|
||||
kfree(tmpbuf);
|
||||
*start = buf;
|
||||
return n;
|
||||
}
|
||||
|
||||
static int proc_read_legacyres(char *buf, char **start, off_t pos,
|
||||
int count, int *eof, void *data)
|
||||
{
|
||||
/* Assume that the following won't overflow the buffer */
|
||||
if (pnp_bios_get_stat_res(buf))
|
||||
return -EIO;
|
||||
|
||||
return count; // FIXME: Return actual length
|
||||
}
|
||||
|
||||
static int proc_read_devices(char *buf, char **start, off_t pos,
|
||||
int count, int *eof, void *data)
|
||||
{
|
||||
struct pnp_bios_node *node;
|
||||
u8 nodenum;
|
||||
char *p = buf;
|
||||
|
||||
if (pos >= 0xff)
|
||||
return 0;
|
||||
|
||||
node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL);
|
||||
if (!node) return -ENOMEM;
|
||||
|
||||
for (nodenum=pos; nodenum<0xff; ) {
|
||||
u8 thisnodenum = nodenum;
|
||||
/* 26 = the number of characters per line sprintf'ed */
|
||||
if ((p - buf + 26) > count)
|
||||
break;
|
||||
if (pnp_bios_get_dev_node(&nodenum, PNPMODE_DYNAMIC, node))
|
||||
break;
|
||||
p += sprintf(p, "%02x\t%08x\t%02x:%02x:%02x\t%04x\n",
|
||||
node->handle, node->eisa_id,
|
||||
node->type_code[0], node->type_code[1],
|
||||
node->type_code[2], node->flags);
|
||||
if (nodenum <= thisnodenum) {
|
||||
printk(KERN_ERR "%s Node number 0x%x is out of sequence following node 0x%x. Aborting.\n", "PnPBIOS: proc_read_devices:", (unsigned int)nodenum, (unsigned int)thisnodenum);
|
||||
*eof = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
kfree(node);
|
||||
if (nodenum == 0xff)
|
||||
*eof = 1;
|
||||
*start = (char *)((off_t)nodenum - pos);
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
static int proc_read_node(char *buf, char **start, off_t pos,
|
||||
int count, int *eof, void *data)
|
||||
{
|
||||
struct pnp_bios_node *node;
|
||||
int boot = (long)data >> 8;
|
||||
u8 nodenum = (long)data;
|
||||
int len;
|
||||
|
||||
node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL);
|
||||
if (!node) return -ENOMEM;
|
||||
if (pnp_bios_get_dev_node(&nodenum, boot, node)) {
|
||||
kfree(node);
|
||||
return -EIO;
|
||||
}
|
||||
len = node->size - sizeof(struct pnp_bios_node);
|
||||
memcpy(buf, node->data, len);
|
||||
kfree(node);
|
||||
return len;
|
||||
}
|
||||
|
||||
static int proc_write_node(struct file *file, const char __user *buf,
|
||||
unsigned long count, void *data)
|
||||
{
|
||||
struct pnp_bios_node *node;
|
||||
int boot = (long)data >> 8;
|
||||
u8 nodenum = (long)data;
|
||||
int ret = count;
|
||||
|
||||
node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL);
|
||||
if (!node)
|
||||
return -ENOMEM;
|
||||
if (pnp_bios_get_dev_node(&nodenum, boot, node)) {
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
if (count != node->size - sizeof(struct pnp_bios_node)) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (copy_from_user(node->data, buf, count)) {
|
||||
ret = -EFAULT;
|
||||
goto out;
|
||||
}
|
||||
if (pnp_bios_set_dev_node(node->handle, boot, node) != 0) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
ret = count;
|
||||
out:
|
||||
kfree(node);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pnpbios_interface_attach_device(struct pnp_bios_node * node)
|
||||
{
|
||||
char name[3];
|
||||
struct proc_dir_entry *ent;
|
||||
|
||||
sprintf(name, "%02x", node->handle);
|
||||
|
||||
if (!proc_pnp)
|
||||
return -EIO;
|
||||
if ( !pnpbios_dont_use_current_config ) {
|
||||
ent = create_proc_entry(name, 0, proc_pnp);
|
||||
if (ent) {
|
||||
ent->read_proc = proc_read_node;
|
||||
ent->write_proc = proc_write_node;
|
||||
ent->data = (void *)(long)(node->handle);
|
||||
}
|
||||
}
|
||||
|
||||
if (!proc_pnp_boot)
|
||||
return -EIO;
|
||||
ent = create_proc_entry(name, 0, proc_pnp_boot);
|
||||
if (ent) {
|
||||
ent->read_proc = proc_read_node;
|
||||
ent->write_proc = proc_write_node;
|
||||
ent->data = (void *)(long)(node->handle+0x100);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/*
|
||||
* When this is called, pnpbios functions are assumed to
|
||||
* work and the pnpbios_dont_use_current_config flag
|
||||
* should already have been set to the appropriate value
|
||||
*/
|
||||
int __init pnpbios_proc_init( void )
|
||||
{
|
||||
proc_pnp = proc_mkdir("pnp", proc_bus);
|
||||
if (!proc_pnp)
|
||||
return -EIO;
|
||||
proc_pnp_boot = proc_mkdir("boot", proc_pnp);
|
||||
if (!proc_pnp_boot)
|
||||
return -EIO;
|
||||
create_proc_read_entry("devices", 0, proc_pnp, proc_read_devices, NULL);
|
||||
create_proc_read_entry("configuration_info", 0, proc_pnp, proc_read_pnpconfig, NULL);
|
||||
create_proc_read_entry("escd_info", 0, proc_pnp, proc_read_escdinfo, NULL);
|
||||
create_proc_read_entry("escd", S_IRUSR, proc_pnp, proc_read_escd, NULL);
|
||||
create_proc_read_entry("legacy_device_resources", 0, proc_pnp, proc_read_legacyres, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __exit pnpbios_proc_exit(void)
|
||||
{
|
||||
int i;
|
||||
char name[3];
|
||||
|
||||
if (!proc_pnp)
|
||||
return;
|
||||
|
||||
for (i=0; i<0xff; i++) {
|
||||
sprintf(name, "%02x", i);
|
||||
if ( !pnpbios_dont_use_current_config )
|
||||
remove_proc_entry(name, proc_pnp);
|
||||
remove_proc_entry(name, proc_pnp_boot);
|
||||
}
|
||||
remove_proc_entry("legacy_device_resources", proc_pnp);
|
||||
remove_proc_entry("escd", proc_pnp);
|
||||
remove_proc_entry("escd_info", proc_pnp);
|
||||
remove_proc_entry("configuration_info", proc_pnp);
|
||||
remove_proc_entry("devices", proc_pnp);
|
||||
remove_proc_entry("boot", proc_pnp);
|
||||
remove_proc_entry("pnp", proc_bus);
|
||||
|
||||
return;
|
||||
}
|
||||
795
drivers/pnp/pnpbios/rsparser.c
Normal file
795
drivers/pnp/pnpbios/rsparser.c
Normal file
|
|
@ -0,0 +1,795 @@
|
|||
/*
|
||||
* rsparser.c - parses and encodes pnpbios resource data streams
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <linux/pnp.h>
|
||||
#include <linux/pnpbios.h>
|
||||
|
||||
#ifdef CONFIG_PCI
|
||||
#include <linux/pci.h>
|
||||
#else
|
||||
inline void pcibios_penalize_isa_irq(int irq) {}
|
||||
#endif /* CONFIG_PCI */
|
||||
|
||||
#include "pnpbios.h"
|
||||
|
||||
/* standard resource tags */
|
||||
#define SMALL_TAG_PNPVERNO 0x01
|
||||
#define SMALL_TAG_LOGDEVID 0x02
|
||||
#define SMALL_TAG_COMPATDEVID 0x03
|
||||
#define SMALL_TAG_IRQ 0x04
|
||||
#define SMALL_TAG_DMA 0x05
|
||||
#define SMALL_TAG_STARTDEP 0x06
|
||||
#define SMALL_TAG_ENDDEP 0x07
|
||||
#define SMALL_TAG_PORT 0x08
|
||||
#define SMALL_TAG_FIXEDPORT 0x09
|
||||
#define SMALL_TAG_VENDOR 0x0e
|
||||
#define SMALL_TAG_END 0x0f
|
||||
#define LARGE_TAG 0x80
|
||||
#define LARGE_TAG_MEM 0x81
|
||||
#define LARGE_TAG_ANSISTR 0x82
|
||||
#define LARGE_TAG_UNICODESTR 0x83
|
||||
#define LARGE_TAG_VENDOR 0x84
|
||||
#define LARGE_TAG_MEM32 0x85
|
||||
#define LARGE_TAG_FIXEDMEM32 0x86
|
||||
|
||||
/*
|
||||
* Resource Data Stream Format:
|
||||
*
|
||||
* Allocated Resources (required)
|
||||
* end tag ->
|
||||
* Resource Configuration Options (optional)
|
||||
* end tag ->
|
||||
* Compitable Device IDs (optional)
|
||||
* final end tag ->
|
||||
*/
|
||||
|
||||
/*
|
||||
* Allocated Resources
|
||||
*/
|
||||
|
||||
static void
|
||||
pnpbios_parse_allocated_irqresource(struct pnp_resource_table * res, int irq)
|
||||
{
|
||||
int i = 0;
|
||||
while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) && i < PNP_MAX_IRQ) i++;
|
||||
if (i < PNP_MAX_IRQ) {
|
||||
res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
|
||||
if (irq == -1) {
|
||||
res->irq_resource[i].flags |= IORESOURCE_DISABLED;
|
||||
return;
|
||||
}
|
||||
res->irq_resource[i].start =
|
||||
res->irq_resource[i].end = (unsigned long) irq;
|
||||
pcibios_penalize_isa_irq(irq);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pnpbios_parse_allocated_dmaresource(struct pnp_resource_table * res, int dma)
|
||||
{
|
||||
int i = 0;
|
||||
while (!(res->dma_resource[i].flags & IORESOURCE_UNSET) && i < PNP_MAX_DMA) i++;
|
||||
if (i < PNP_MAX_DMA) {
|
||||
res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
|
||||
if (dma == -1) {
|
||||
res->dma_resource[i].flags |= IORESOURCE_DISABLED;
|
||||
return;
|
||||
}
|
||||
res->dma_resource[i].start =
|
||||
res->dma_resource[i].end = (unsigned long) dma;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pnpbios_parse_allocated_ioresource(struct pnp_resource_table * res, int io, int len)
|
||||
{
|
||||
int i = 0;
|
||||
while (!(res->port_resource[i].flags & IORESOURCE_UNSET) && i < PNP_MAX_PORT) i++;
|
||||
if (i < PNP_MAX_PORT) {
|
||||
res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
|
||||
if (len <= 0 || (io + len -1) >= 0x10003) {
|
||||
res->port_resource[i].flags |= IORESOURCE_DISABLED;
|
||||
return;
|
||||
}
|
||||
res->port_resource[i].start = (unsigned long) io;
|
||||
res->port_resource[i].end = (unsigned long)(io + len - 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pnpbios_parse_allocated_memresource(struct pnp_resource_table * res, int mem, int len)
|
||||
{
|
||||
int i = 0;
|
||||
while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) && i < PNP_MAX_MEM) i++;
|
||||
if (i < PNP_MAX_MEM) {
|
||||
res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
|
||||
if (len <= 0) {
|
||||
res->mem_resource[i].flags |= IORESOURCE_DISABLED;
|
||||
return;
|
||||
}
|
||||
res->mem_resource[i].start = (unsigned long) mem;
|
||||
res->mem_resource[i].end = (unsigned long)(mem + len - 1);
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned char *
|
||||
pnpbios_parse_allocated_resource_data(unsigned char * p, unsigned char * end, struct pnp_resource_table * res)
|
||||
{
|
||||
unsigned int len, tag;
|
||||
int io, size, mask, i;
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
/* Blank the resource table values */
|
||||
pnp_init_resource_table(res);
|
||||
|
||||
while ((char *)p < (char *)end) {
|
||||
|
||||
/* determine the type of tag */
|
||||
if (p[0] & LARGE_TAG) { /* large tag */
|
||||
len = (p[2] << 8) | p[1];
|
||||
tag = p[0];
|
||||
} else { /* small tag */
|
||||
len = p[0] & 0x07;
|
||||
tag = ((p[0]>>3) & 0x0f);
|
||||
}
|
||||
|
||||
switch (tag) {
|
||||
|
||||
case LARGE_TAG_MEM:
|
||||
if (len != 9)
|
||||
goto len_err;
|
||||
io = *(short *) &p[4];
|
||||
size = *(short *) &p[10];
|
||||
pnpbios_parse_allocated_memresource(res, io, size);
|
||||
break;
|
||||
|
||||
case LARGE_TAG_ANSISTR:
|
||||
/* ignore this for now */
|
||||
break;
|
||||
|
||||
case LARGE_TAG_VENDOR:
|
||||
/* do nothing */
|
||||
break;
|
||||
|
||||
case LARGE_TAG_MEM32:
|
||||
if (len != 17)
|
||||
goto len_err;
|
||||
io = *(int *) &p[4];
|
||||
size = *(int *) &p[16];
|
||||
pnpbios_parse_allocated_memresource(res, io, size);
|
||||
break;
|
||||
|
||||
case LARGE_TAG_FIXEDMEM32:
|
||||
if (len != 9)
|
||||
goto len_err;
|
||||
io = *(int *) &p[4];
|
||||
size = *(int *) &p[8];
|
||||
pnpbios_parse_allocated_memresource(res, io, size);
|
||||
break;
|
||||
|
||||
case SMALL_TAG_IRQ:
|
||||
if (len < 2 || len > 3)
|
||||
goto len_err;
|
||||
io = -1;
|
||||
mask= p[1] + p[2]*256;
|
||||
for (i=0;i<16;i++, mask=mask>>1)
|
||||
if(mask & 0x01) io=i;
|
||||
pnpbios_parse_allocated_irqresource(res, io);
|
||||
break;
|
||||
|
||||
case SMALL_TAG_DMA:
|
||||
if (len != 2)
|
||||
goto len_err;
|
||||
io = -1;
|
||||
mask = p[1];
|
||||
for (i=0;i<8;i++, mask = mask>>1)
|
||||
if(mask & 0x01) io=i;
|
||||
pnpbios_parse_allocated_dmaresource(res, io);
|
||||
break;
|
||||
|
||||
case SMALL_TAG_PORT:
|
||||
if (len != 7)
|
||||
goto len_err;
|
||||
io = p[2] + p[3] *256;
|
||||
size = p[7];
|
||||
pnpbios_parse_allocated_ioresource(res, io, size);
|
||||
break;
|
||||
|
||||
case SMALL_TAG_VENDOR:
|
||||
/* do nothing */
|
||||
break;
|
||||
|
||||
case SMALL_TAG_FIXEDPORT:
|
||||
if (len != 3)
|
||||
goto len_err;
|
||||
io = p[1] + p[2] * 256;
|
||||
size = p[3];
|
||||
pnpbios_parse_allocated_ioresource(res, io, size);
|
||||
break;
|
||||
|
||||
case SMALL_TAG_END:
|
||||
p = p + 2;
|
||||
return (unsigned char *)p;
|
||||
break;
|
||||
|
||||
default: /* an unkown tag */
|
||||
len_err:
|
||||
printk(KERN_ERR "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", tag, len);
|
||||
break;
|
||||
}
|
||||
|
||||
/* continue to the next tag */
|
||||
if (p[0] & LARGE_TAG)
|
||||
p += len + 3;
|
||||
else
|
||||
p += len + 1;
|
||||
}
|
||||
|
||||
printk(KERN_ERR "PnPBIOS: Resource structure does not contain an end tag.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Resource Configuration Options
|
||||
*/
|
||||
|
||||
static void
|
||||
pnpbios_parse_mem_option(unsigned char *p, int size, struct pnp_option *option)
|
||||
{
|
||||
struct pnp_mem * mem;
|
||||
mem = pnpbios_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL);
|
||||
if (!mem)
|
||||
return;
|
||||
mem->min = ((p[5] << 8) | p[4]) << 8;
|
||||
mem->max = ((p[7] << 8) | p[6]) << 8;
|
||||
mem->align = (p[9] << 8) | p[8];
|
||||
mem->size = ((p[11] << 8) | p[10]) << 8;
|
||||
mem->flags = p[3];
|
||||
pnp_register_mem_resource(option,mem);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
pnpbios_parse_mem32_option(unsigned char *p, int size, struct pnp_option *option)
|
||||
{
|
||||
struct pnp_mem * mem;
|
||||
mem = pnpbios_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL);
|
||||
if (!mem)
|
||||
return;
|
||||
mem->min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
|
||||
mem->max = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
|
||||
mem->align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12];
|
||||
mem->size = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16];
|
||||
mem->flags = p[3];
|
||||
pnp_register_mem_resource(option,mem);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
pnpbios_parse_fixed_mem32_option(unsigned char *p, int size, struct pnp_option *option)
|
||||
{
|
||||
struct pnp_mem * mem;
|
||||
mem = pnpbios_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL);
|
||||
if (!mem)
|
||||
return;
|
||||
mem->min = mem->max = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
|
||||
mem->size = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
|
||||
mem->align = 0;
|
||||
mem->flags = p[3];
|
||||
pnp_register_mem_resource(option,mem);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
pnpbios_parse_irq_option(unsigned char *p, int size, struct pnp_option *option)
|
||||
{
|
||||
struct pnp_irq * irq;
|
||||
unsigned long bits;
|
||||
|
||||
irq = pnpbios_kmalloc(sizeof(struct pnp_irq), GFP_KERNEL);
|
||||
if (!irq)
|
||||
return;
|
||||
bits = (p[2] << 8) | p[1];
|
||||
bitmap_copy(irq->map, &bits, 16);
|
||||
if (size > 2)
|
||||
irq->flags = p[3];
|
||||
else
|
||||
irq->flags = IORESOURCE_IRQ_HIGHEDGE;
|
||||
pnp_register_irq_resource(option,irq);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
pnpbios_parse_dma_option(unsigned char *p, int size, struct pnp_option *option)
|
||||
{
|
||||
struct pnp_dma * dma;
|
||||
dma = pnpbios_kmalloc(sizeof(struct pnp_dma), GFP_KERNEL);
|
||||
if (!dma)
|
||||
return;
|
||||
dma->map = p[1];
|
||||
dma->flags = p[2];
|
||||
pnp_register_dma_resource(option,dma);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
pnpbios_parse_port_option(unsigned char *p, int size, struct pnp_option *option)
|
||||
{
|
||||
struct pnp_port * port;
|
||||
port = pnpbios_kmalloc(sizeof(struct pnp_port), GFP_KERNEL);
|
||||
if (!port)
|
||||
return;
|
||||
port->min = (p[3] << 8) | p[2];
|
||||
port->max = (p[5] << 8) | p[4];
|
||||
port->align = p[6];
|
||||
port->size = p[7];
|
||||
port->flags = p[1] ? PNP_PORT_FLAG_16BITADDR : 0;
|
||||
pnp_register_port_resource(option,port);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
pnpbios_parse_fixed_port_option(unsigned char *p, int size, struct pnp_option *option)
|
||||
{
|
||||
struct pnp_port * port;
|
||||
port = pnpbios_kmalloc(sizeof(struct pnp_port), GFP_KERNEL);
|
||||
if (!port)
|
||||
return;
|
||||
port->min = port->max = (p[2] << 8) | p[1];
|
||||
port->size = p[3];
|
||||
port->align = 0;
|
||||
port->flags = PNP_PORT_FLAG_FIXED;
|
||||
pnp_register_port_resource(option,port);
|
||||
return;
|
||||
}
|
||||
|
||||
static unsigned char *
|
||||
pnpbios_parse_resource_option_data(unsigned char * p, unsigned char * end, struct pnp_dev *dev)
|
||||
{
|
||||
unsigned int len, tag;
|
||||
int priority = 0;
|
||||
struct pnp_option *option, *option_independent;
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
option_independent = option = pnp_register_independent_option(dev);
|
||||
if (!option)
|
||||
return NULL;
|
||||
|
||||
while ((char *)p < (char *)end) {
|
||||
|
||||
/* determine the type of tag */
|
||||
if (p[0] & LARGE_TAG) { /* large tag */
|
||||
len = (p[2] << 8) | p[1];
|
||||
tag = p[0];
|
||||
} else { /* small tag */
|
||||
len = p[0] & 0x07;
|
||||
tag = ((p[0]>>3) & 0x0f);
|
||||
}
|
||||
|
||||
switch (tag) {
|
||||
|
||||
case LARGE_TAG_MEM:
|
||||
if (len != 9)
|
||||
goto len_err;
|
||||
pnpbios_parse_mem_option(p, len, option);
|
||||
break;
|
||||
|
||||
case LARGE_TAG_MEM32:
|
||||
if (len != 17)
|
||||
goto len_err;
|
||||
pnpbios_parse_mem32_option(p, len, option);
|
||||
break;
|
||||
|
||||
case LARGE_TAG_FIXEDMEM32:
|
||||
if (len != 9)
|
||||
goto len_err;
|
||||
pnpbios_parse_fixed_mem32_option(p, len, option);
|
||||
break;
|
||||
|
||||
case SMALL_TAG_IRQ:
|
||||
if (len < 2 || len > 3)
|
||||
goto len_err;
|
||||
pnpbios_parse_irq_option(p, len, option);
|
||||
break;
|
||||
|
||||
case SMALL_TAG_DMA:
|
||||
if (len != 2)
|
||||
goto len_err;
|
||||
pnpbios_parse_dma_option(p, len, option);
|
||||
break;
|
||||
|
||||
case SMALL_TAG_PORT:
|
||||
if (len != 7)
|
||||
goto len_err;
|
||||
pnpbios_parse_port_option(p, len, option);
|
||||
break;
|
||||
|
||||
case SMALL_TAG_VENDOR:
|
||||
/* do nothing */
|
||||
break;
|
||||
|
||||
case SMALL_TAG_FIXEDPORT:
|
||||
if (len != 3)
|
||||
goto len_err;
|
||||
pnpbios_parse_fixed_port_option(p, len, option);
|
||||
break;
|
||||
|
||||
case SMALL_TAG_STARTDEP:
|
||||
if (len > 1)
|
||||
goto len_err;
|
||||
priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE;
|
||||
if (len > 0)
|
||||
priority = 0x100 | p[1];
|
||||
option = pnp_register_dependent_option(dev, priority);
|
||||
if (!option)
|
||||
return NULL;
|
||||
break;
|
||||
|
||||
case SMALL_TAG_ENDDEP:
|
||||
if (len != 0)
|
||||
goto len_err;
|
||||
if (option_independent == option)
|
||||
printk(KERN_WARNING "PnPBIOS: Missing SMALL_TAG_STARTDEP tag\n");
|
||||
option = option_independent;
|
||||
break;
|
||||
|
||||
case SMALL_TAG_END:
|
||||
if (option_independent != option)
|
||||
printk(KERN_WARNING "PnPBIOS: Missing SMALL_TAG_ENDDEP tag\n");
|
||||
p = p + 2;
|
||||
return (unsigned char *)p;
|
||||
break;
|
||||
|
||||
default: /* an unkown tag */
|
||||
len_err:
|
||||
printk(KERN_ERR "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", tag, len);
|
||||
break;
|
||||
}
|
||||
|
||||
/* continue to the next tag */
|
||||
if (p[0] & LARGE_TAG)
|
||||
p += len + 3;
|
||||
else
|
||||
p += len + 1;
|
||||
}
|
||||
|
||||
printk(KERN_ERR "PnPBIOS: Resource structure does not contain an end tag.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Compatible Device IDs
|
||||
*/
|
||||
|
||||
#define HEX(id,a) hex[((id)>>a) & 15]
|
||||
#define CHAR(id,a) (0x40 + (((id)>>a) & 31))
|
||||
//
|
||||
|
||||
void pnpid32_to_pnpid(u32 id, char *str)
|
||||
{
|
||||
const char *hex = "0123456789abcdef";
|
||||
|
||||
id = be32_to_cpu(id);
|
||||
str[0] = CHAR(id, 26);
|
||||
str[1] = CHAR(id, 21);
|
||||
str[2] = CHAR(id,16);
|
||||
str[3] = HEX(id, 12);
|
||||
str[4] = HEX(id, 8);
|
||||
str[5] = HEX(id, 4);
|
||||
str[6] = HEX(id, 0);
|
||||
str[7] = '\0';
|
||||
|
||||
return;
|
||||
}
|
||||
//
|
||||
#undef CHAR
|
||||
#undef HEX
|
||||
|
||||
static unsigned char *
|
||||
pnpbios_parse_compatible_ids(unsigned char *p, unsigned char *end, struct pnp_dev *dev)
|
||||
{
|
||||
int len, tag;
|
||||
char id[8];
|
||||
struct pnp_id *dev_id;
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
while ((char *)p < (char *)end) {
|
||||
|
||||
/* determine the type of tag */
|
||||
if (p[0] & LARGE_TAG) { /* large tag */
|
||||
len = (p[2] << 8) | p[1];
|
||||
tag = p[0];
|
||||
} else { /* small tag */
|
||||
len = p[0] & 0x07;
|
||||
tag = ((p[0]>>3) & 0x0f);
|
||||
}
|
||||
|
||||
switch (tag) {
|
||||
|
||||
case LARGE_TAG_ANSISTR:
|
||||
strncpy(dev->name, p + 3, len >= PNP_NAME_LEN ? PNP_NAME_LEN - 2 : len);
|
||||
dev->name[len >= PNP_NAME_LEN ? PNP_NAME_LEN - 1 : len] = '\0';
|
||||
break;
|
||||
|
||||
case SMALL_TAG_COMPATDEVID: /* compatible ID */
|
||||
if (len != 4)
|
||||
goto len_err;
|
||||
dev_id = pnpbios_kmalloc(sizeof (struct pnp_id), GFP_KERNEL);
|
||||
if (!dev_id)
|
||||
return NULL;
|
||||
memset(dev_id, 0, sizeof(struct pnp_id));
|
||||
pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] << 24,id);
|
||||
memcpy(&dev_id->id, id, 7);
|
||||
pnp_add_id(dev_id, dev);
|
||||
break;
|
||||
|
||||
case SMALL_TAG_END:
|
||||
p = p + 2;
|
||||
return (unsigned char *)p;
|
||||
break;
|
||||
|
||||
default: /* an unkown tag */
|
||||
len_err:
|
||||
printk(KERN_ERR "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", tag, len);
|
||||
break;
|
||||
}
|
||||
|
||||
/* continue to the next tag */
|
||||
if (p[0] & LARGE_TAG)
|
||||
p += len + 3;
|
||||
else
|
||||
p += len + 1;
|
||||
}
|
||||
|
||||
printk(KERN_ERR "PnPBIOS: Resource structure does not contain an end tag.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Allocated Resource Encoding
|
||||
*/
|
||||
|
||||
static void pnpbios_encode_mem(unsigned char *p, struct resource * res)
|
||||
{
|
||||
unsigned long base = res->start;
|
||||
unsigned long len = res->end - res->start + 1;
|
||||
p[4] = (base >> 8) & 0xff;
|
||||
p[5] = ((base >> 8) >> 8) & 0xff;
|
||||
p[6] = (base >> 8) & 0xff;
|
||||
p[7] = ((base >> 8) >> 8) & 0xff;
|
||||
p[10] = (len >> 8) & 0xff;
|
||||
p[11] = ((len >> 8) >> 8) & 0xff;
|
||||
return;
|
||||
}
|
||||
|
||||
static void pnpbios_encode_mem32(unsigned char *p, struct resource * res)
|
||||
{
|
||||
unsigned long base = res->start;
|
||||
unsigned long len = res->end - res->start + 1;
|
||||
p[4] = base & 0xff;
|
||||
p[5] = (base >> 8) & 0xff;
|
||||
p[6] = (base >> 16) & 0xff;
|
||||
p[7] = (base >> 24) & 0xff;
|
||||
p[8] = base & 0xff;
|
||||
p[9] = (base >> 8) & 0xff;
|
||||
p[10] = (base >> 16) & 0xff;
|
||||
p[11] = (base >> 24) & 0xff;
|
||||
p[16] = len & 0xff;
|
||||
p[17] = (len >> 8) & 0xff;
|
||||
p[18] = (len >> 16) & 0xff;
|
||||
p[19] = (len >> 24) & 0xff;
|
||||
return;
|
||||
}
|
||||
|
||||
static void pnpbios_encode_fixed_mem32(unsigned char *p, struct resource * res)
|
||||
{ unsigned long base = res->start;
|
||||
unsigned long len = res->end - res->start + 1;
|
||||
p[4] = base & 0xff;
|
||||
p[5] = (base >> 8) & 0xff;
|
||||
p[6] = (base >> 16) & 0xff;
|
||||
p[7] = (base >> 24) & 0xff;
|
||||
p[8] = len & 0xff;
|
||||
p[9] = (len >> 8) & 0xff;
|
||||
p[10] = (len >> 16) & 0xff;
|
||||
p[11] = (len >> 24) & 0xff;
|
||||
return;
|
||||
}
|
||||
|
||||
static void pnpbios_encode_irq(unsigned char *p, struct resource * res)
|
||||
{
|
||||
unsigned long map = 0;
|
||||
map = 1 << res->start;
|
||||
p[1] = map & 0xff;
|
||||
p[2] = (map >> 8) & 0xff;
|
||||
return;
|
||||
}
|
||||
|
||||
static void pnpbios_encode_dma(unsigned char *p, struct resource * res)
|
||||
{
|
||||
unsigned long map = 0;
|
||||
map = 1 << res->start;
|
||||
p[1] = map & 0xff;
|
||||
return;
|
||||
}
|
||||
|
||||
static void pnpbios_encode_port(unsigned char *p, struct resource * res)
|
||||
{
|
||||
unsigned long base = res->start;
|
||||
unsigned long len = res->end - res->start + 1;
|
||||
p[2] = base & 0xff;
|
||||
p[3] = (base >> 8) & 0xff;
|
||||
p[4] = base & 0xff;
|
||||
p[5] = (base >> 8) & 0xff;
|
||||
p[7] = len & 0xff;
|
||||
return;
|
||||
}
|
||||
|
||||
static void pnpbios_encode_fixed_port(unsigned char *p, struct resource * res)
|
||||
{
|
||||
unsigned long base = res->start;
|
||||
unsigned long len = res->end - res->start + 1;
|
||||
p[1] = base & 0xff;
|
||||
p[2] = (base >> 8) & 0xff;
|
||||
p[3] = len & 0xff;
|
||||
return;
|
||||
}
|
||||
|
||||
static unsigned char *
|
||||
pnpbios_encode_allocated_resource_data(unsigned char * p, unsigned char * end, struct pnp_resource_table * res)
|
||||
{
|
||||
unsigned int len, tag;
|
||||
int port = 0, irq = 0, dma = 0, mem = 0;
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
while ((char *)p < (char *)end) {
|
||||
|
||||
/* determine the type of tag */
|
||||
if (p[0] & LARGE_TAG) { /* large tag */
|
||||
len = (p[2] << 8) | p[1];
|
||||
tag = p[0];
|
||||
} else { /* small tag */
|
||||
len = p[0] & 0x07;
|
||||
tag = ((p[0]>>3) & 0x0f);
|
||||
}
|
||||
|
||||
switch (tag) {
|
||||
|
||||
case LARGE_TAG_MEM:
|
||||
if (len != 9)
|
||||
goto len_err;
|
||||
pnpbios_encode_mem(p, &res->mem_resource[mem]);
|
||||
mem++;
|
||||
break;
|
||||
|
||||
case LARGE_TAG_MEM32:
|
||||
if (len != 17)
|
||||
goto len_err;
|
||||
pnpbios_encode_mem32(p, &res->mem_resource[mem]);
|
||||
mem++;
|
||||
break;
|
||||
|
||||
case LARGE_TAG_FIXEDMEM32:
|
||||
if (len != 9)
|
||||
goto len_err;
|
||||
pnpbios_encode_fixed_mem32(p, &res->mem_resource[mem]);
|
||||
mem++;
|
||||
break;
|
||||
|
||||
case SMALL_TAG_IRQ:
|
||||
if (len < 2 || len > 3)
|
||||
goto len_err;
|
||||
pnpbios_encode_irq(p, &res->irq_resource[irq]);
|
||||
irq++;
|
||||
break;
|
||||
|
||||
case SMALL_TAG_DMA:
|
||||
if (len != 2)
|
||||
goto len_err;
|
||||
pnpbios_encode_dma(p, &res->dma_resource[dma]);
|
||||
dma++;
|
||||
break;
|
||||
|
||||
case SMALL_TAG_PORT:
|
||||
if (len != 7)
|
||||
goto len_err;
|
||||
pnpbios_encode_port(p, &res->port_resource[port]);
|
||||
port++;
|
||||
break;
|
||||
|
||||
case SMALL_TAG_VENDOR:
|
||||
/* do nothing */
|
||||
break;
|
||||
|
||||
case SMALL_TAG_FIXEDPORT:
|
||||
if (len != 3)
|
||||
goto len_err;
|
||||
pnpbios_encode_fixed_port(p, &res->port_resource[port]);
|
||||
port++;
|
||||
break;
|
||||
|
||||
case SMALL_TAG_END:
|
||||
p = p + 2;
|
||||
return (unsigned char *)p;
|
||||
break;
|
||||
|
||||
default: /* an unkown tag */
|
||||
len_err:
|
||||
printk(KERN_ERR "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", tag, len);
|
||||
break;
|
||||
}
|
||||
|
||||
/* continue to the next tag */
|
||||
if (p[0] & LARGE_TAG)
|
||||
p += len + 3;
|
||||
else
|
||||
p += len + 1;
|
||||
}
|
||||
|
||||
printk(KERN_ERR "PnPBIOS: Resource structure does not contain an end tag.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Core Parsing Functions
|
||||
*/
|
||||
|
||||
int
|
||||
pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node * node)
|
||||
{
|
||||
unsigned char * p = (char *)node->data;
|
||||
unsigned char * end = (char *)(node->data + node->size);
|
||||
p = pnpbios_parse_allocated_resource_data(p,end,&dev->res);
|
||||
if (!p)
|
||||
return -EIO;
|
||||
p = pnpbios_parse_resource_option_data(p,end,dev);
|
||||
if (!p)
|
||||
return -EIO;
|
||||
p = pnpbios_parse_compatible_ids(p,end,dev);
|
||||
if (!p)
|
||||
return -EIO;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pnpbios_read_resources_from_node(struct pnp_resource_table *res,
|
||||
struct pnp_bios_node * node)
|
||||
{
|
||||
unsigned char * p = (char *)node->data;
|
||||
unsigned char * end = (char *)(node->data + node->size);
|
||||
p = pnpbios_parse_allocated_resource_data(p,end,res);
|
||||
if (!p)
|
||||
return -EIO;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pnpbios_write_resources_to_node(struct pnp_resource_table *res,
|
||||
struct pnp_bios_node * node)
|
||||
{
|
||||
unsigned char * p = (char *)node->data;
|
||||
unsigned char * end = (char *)(node->data + node->size);
|
||||
p = pnpbios_encode_allocated_resource_data(p,end,res);
|
||||
if (!p)
|
||||
return -EIO;
|
||||
return 0;
|
||||
}
|
||||
152
drivers/pnp/quirks.c
Normal file
152
drivers/pnp/quirks.c
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* This file contains quirk handling code for PnP devices
|
||||
* Some devices do not report all their resources, and need to have extra
|
||||
* resources added. This is most easily accomplished at initialisation time
|
||||
* when building up the resource structure for the first time.
|
||||
*
|
||||
* Copyright (c) 2000 Peter Denison <peterd@pnd-pc.demon.co.uk>
|
||||
*
|
||||
* Heavily based on PCI quirks handling which is
|
||||
*
|
||||
* Copyright (c) 1999 Martin Mares <mj@ucw.cz>
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#ifdef CONFIG_PNP_DEBUG
|
||||
#define DEBUG
|
||||
#else
|
||||
#undef DEBUG
|
||||
#endif
|
||||
|
||||
#include <linux/pnp.h>
|
||||
#include "base.h"
|
||||
|
||||
|
||||
static void quirk_awe32_resources(struct pnp_dev *dev)
|
||||
{
|
||||
struct pnp_port *port, *port2, *port3;
|
||||
struct pnp_option *res = dev->dependent;
|
||||
|
||||
/*
|
||||
* Unfortunately the isapnp_add_port_resource is too tightly bound
|
||||
* into the PnP discovery sequence, and cannot be used. Link in the
|
||||
* two extra ports (at offset 0x400 and 0x800 from the one given) by
|
||||
* hand.
|
||||
*/
|
||||
for ( ; res ; res = res->next ) {
|
||||
port2 = pnp_alloc(sizeof(struct pnp_port));
|
||||
if (!port2)
|
||||
return;
|
||||
port3 = pnp_alloc(sizeof(struct pnp_port));
|
||||
if (!port3) {
|
||||
kfree(port2);
|
||||
return;
|
||||
}
|
||||
port = res->port;
|
||||
memcpy(port2, port, sizeof(struct pnp_port));
|
||||
memcpy(port3, port, sizeof(struct pnp_port));
|
||||
port->next = port2;
|
||||
port2->next = port3;
|
||||
port2->min += 0x400;
|
||||
port2->max += 0x400;
|
||||
port3->min += 0x800;
|
||||
port3->max += 0x800;
|
||||
}
|
||||
printk(KERN_INFO "pnp: AWE32 quirk - adding two ports\n");
|
||||
}
|
||||
|
||||
static void quirk_cmi8330_resources(struct pnp_dev *dev)
|
||||
{
|
||||
struct pnp_option *res = dev->dependent;
|
||||
unsigned long tmp;
|
||||
|
||||
for ( ; res ; res = res->next ) {
|
||||
|
||||
struct pnp_irq *irq;
|
||||
struct pnp_dma *dma;
|
||||
|
||||
for( irq = res->irq; irq; irq = irq->next ) { // Valid irqs are 5, 7, 10
|
||||
tmp = 0x04A0;
|
||||
bitmap_copy(irq->map, &tmp, 16); // 0000 0100 1010 0000
|
||||
}
|
||||
|
||||
for( dma = res->dma; dma; dma = dma->next ) // Valid 8bit dma channels are 1,3
|
||||
if( ( dma->flags & IORESOURCE_DMA_TYPE_MASK ) == IORESOURCE_DMA_8BIT )
|
||||
dma->map = 0x000A;
|
||||
}
|
||||
printk(KERN_INFO "pnp: CMI8330 quirk - fixing interrupts and dma\n");
|
||||
}
|
||||
|
||||
static void quirk_sb16audio_resources(struct pnp_dev *dev)
|
||||
{
|
||||
struct pnp_port *port;
|
||||
struct pnp_option *res = dev->dependent;
|
||||
int changed = 0;
|
||||
|
||||
/*
|
||||
* The default range on the mpu port for these devices is 0x388-0x388.
|
||||
* Here we increase that range so that two such cards can be
|
||||
* auto-configured.
|
||||
*/
|
||||
|
||||
for( ; res ; res = res->next ) {
|
||||
port = res->port;
|
||||
if(!port)
|
||||
continue;
|
||||
port = port->next;
|
||||
if(!port)
|
||||
continue;
|
||||
port = port->next;
|
||||
if(!port)
|
||||
continue;
|
||||
if(port->min != port->max)
|
||||
continue;
|
||||
port->max += 0x70;
|
||||
changed = 1;
|
||||
}
|
||||
if(changed)
|
||||
printk(KERN_INFO "pnp: SB audio device quirk - increasing port range\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* PnP Quirks
|
||||
* Cards or devices that need some tweaking due to incomplete resource info
|
||||
*/
|
||||
|
||||
static struct pnp_fixup pnp_fixups[] = {
|
||||
/* Soundblaster awe io port quirk */
|
||||
{ "CTL0021", quirk_awe32_resources },
|
||||
{ "CTL0022", quirk_awe32_resources },
|
||||
{ "CTL0023", quirk_awe32_resources },
|
||||
/* CMI 8330 interrupt and dma fix */
|
||||
{ "@X@0001", quirk_cmi8330_resources },
|
||||
/* Soundblaster audio device io port range quirk */
|
||||
{ "CTL0001", quirk_sb16audio_resources },
|
||||
{ "CTL0031", quirk_sb16audio_resources },
|
||||
{ "CTL0041", quirk_sb16audio_resources },
|
||||
{ "CTL0042", quirk_sb16audio_resources },
|
||||
{ "CTL0043", quirk_sb16audio_resources },
|
||||
{ "CTL0044", quirk_sb16audio_resources },
|
||||
{ "CTL0045", quirk_sb16audio_resources },
|
||||
{ "" }
|
||||
};
|
||||
|
||||
void pnp_fixup_device(struct pnp_dev *dev)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (*pnp_fixups[i].id) {
|
||||
if (compare_pnp_id(dev->id,pnp_fixups[i].id)) {
|
||||
pnp_dbg("Calling quirk for %s",
|
||||
dev->dev.bus_id);
|
||||
pnp_fixups[i].quirk_function(dev);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
542
drivers/pnp/resource.c
Normal file
542
drivers/pnp/resource.c
Normal file
|
|
@ -0,0 +1,542 @@
|
|||
/*
|
||||
* resource.c - Contains functions for registering and analyzing resource information
|
||||
*
|
||||
* based on isapnp.c resource management (c) Jaroslav Kysela <perex@suse.cz>
|
||||
* Copyright 2003 Adam Belay <ambx1@neo.rr.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <asm/io.h>
|
||||
#include <asm/dma.h>
|
||||
#include <asm/irq.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/init.h>
|
||||
|
||||
#include <linux/pnp.h>
|
||||
#include "base.h"
|
||||
|
||||
static int pnp_reserve_irq[16] = { [0 ... 15] = -1 }; /* reserve (don't use) some IRQ */
|
||||
static int pnp_reserve_dma[8] = { [0 ... 7] = -1 }; /* reserve (don't use) some DMA */
|
||||
static int pnp_reserve_io[16] = { [0 ... 15] = -1 }; /* reserve (don't use) some I/O region */
|
||||
static int pnp_reserve_mem[16] = { [0 ... 15] = -1 }; /* reserve (don't use) some memory region */
|
||||
|
||||
|
||||
/*
|
||||
* option registration
|
||||
*/
|
||||
|
||||
static struct pnp_option * pnp_build_option(int priority)
|
||||
{
|
||||
struct pnp_option *option = pnp_alloc(sizeof(struct pnp_option));
|
||||
|
||||
/* check if pnp_alloc ran out of memory */
|
||||
if (!option)
|
||||
return NULL;
|
||||
|
||||
option->priority = priority & 0xff;
|
||||
/* make sure the priority is valid */
|
||||
if (option->priority > PNP_RES_PRIORITY_FUNCTIONAL)
|
||||
option->priority = PNP_RES_PRIORITY_INVALID;
|
||||
|
||||
return option;
|
||||
}
|
||||
|
||||
struct pnp_option * pnp_register_independent_option(struct pnp_dev *dev)
|
||||
{
|
||||
struct pnp_option *option;
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
option = pnp_build_option(PNP_RES_PRIORITY_PREFERRED);
|
||||
|
||||
/* this should never happen but if it does we'll try to continue */
|
||||
if (dev->independent)
|
||||
pnp_err("independent resource already registered");
|
||||
dev->independent = option;
|
||||
return option;
|
||||
}
|
||||
|
||||
struct pnp_option * pnp_register_dependent_option(struct pnp_dev *dev, int priority)
|
||||
{
|
||||
struct pnp_option *option;
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
option = pnp_build_option(priority);
|
||||
|
||||
if (dev->dependent) {
|
||||
struct pnp_option *parent = dev->dependent;
|
||||
while (parent->next)
|
||||
parent = parent->next;
|
||||
parent->next = option;
|
||||
} else
|
||||
dev->dependent = option;
|
||||
return option;
|
||||
}
|
||||
|
||||
int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data)
|
||||
{
|
||||
struct pnp_irq *ptr;
|
||||
if (!option)
|
||||
return -EINVAL;
|
||||
if (!data)
|
||||
return -EINVAL;
|
||||
|
||||
ptr = option->irq;
|
||||
while (ptr && ptr->next)
|
||||
ptr = ptr->next;
|
||||
if (ptr)
|
||||
ptr->next = data;
|
||||
else
|
||||
option->irq = data;
|
||||
|
||||
#ifdef CONFIG_PCI
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
if (test_bit(i, data->map))
|
||||
pcibios_penalize_isa_irq(i);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data)
|
||||
{
|
||||
struct pnp_dma *ptr;
|
||||
if (!option)
|
||||
return -EINVAL;
|
||||
if (!data)
|
||||
return -EINVAL;
|
||||
|
||||
ptr = option->dma;
|
||||
while (ptr && ptr->next)
|
||||
ptr = ptr->next;
|
||||
if (ptr)
|
||||
ptr->next = data;
|
||||
else
|
||||
option->dma = data;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data)
|
||||
{
|
||||
struct pnp_port *ptr;
|
||||
if (!option)
|
||||
return -EINVAL;
|
||||
if (!data)
|
||||
return -EINVAL;
|
||||
|
||||
ptr = option->port;
|
||||
while (ptr && ptr->next)
|
||||
ptr = ptr->next;
|
||||
if (ptr)
|
||||
ptr->next = data;
|
||||
else
|
||||
option->port = data;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data)
|
||||
{
|
||||
struct pnp_mem *ptr;
|
||||
if (!option)
|
||||
return -EINVAL;
|
||||
if (!data)
|
||||
return -EINVAL;
|
||||
|
||||
ptr = option->mem;
|
||||
while (ptr && ptr->next)
|
||||
ptr = ptr->next;
|
||||
if (ptr)
|
||||
ptr->next = data;
|
||||
else
|
||||
option->mem = data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pnp_free_port(struct pnp_port *port)
|
||||
{
|
||||
struct pnp_port *next;
|
||||
|
||||
while (port) {
|
||||
next = port->next;
|
||||
kfree(port);
|
||||
port = next;
|
||||
}
|
||||
}
|
||||
|
||||
static void pnp_free_irq(struct pnp_irq *irq)
|
||||
{
|
||||
struct pnp_irq *next;
|
||||
|
||||
while (irq) {
|
||||
next = irq->next;
|
||||
kfree(irq);
|
||||
irq = next;
|
||||
}
|
||||
}
|
||||
|
||||
static void pnp_free_dma(struct pnp_dma *dma)
|
||||
{
|
||||
struct pnp_dma *next;
|
||||
|
||||
while (dma) {
|
||||
next = dma->next;
|
||||
kfree(dma);
|
||||
dma = next;
|
||||
}
|
||||
}
|
||||
|
||||
static void pnp_free_mem(struct pnp_mem *mem)
|
||||
{
|
||||
struct pnp_mem *next;
|
||||
|
||||
while (mem) {
|
||||
next = mem->next;
|
||||
kfree(mem);
|
||||
mem = next;
|
||||
}
|
||||
}
|
||||
|
||||
void pnp_free_option(struct pnp_option *option)
|
||||
{
|
||||
struct pnp_option *next;
|
||||
|
||||
while (option) {
|
||||
next = option->next;
|
||||
pnp_free_port(option->port);
|
||||
pnp_free_irq(option->irq);
|
||||
pnp_free_dma(option->dma);
|
||||
pnp_free_mem(option->mem);
|
||||
kfree(option);
|
||||
option = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* resource validity checking
|
||||
*/
|
||||
|
||||
#define length(start, end) (*(end) - *(start) + 1)
|
||||
|
||||
/* Two ranges conflict if one doesn't end before the other starts */
|
||||
#define ranged_conflict(starta, enda, startb, endb) \
|
||||
!((*(enda) < *(startb)) || (*(endb) < *(starta)))
|
||||
|
||||
#define cannot_compare(flags) \
|
||||
((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED))
|
||||
|
||||
int pnp_check_port(struct pnp_dev * dev, int idx)
|
||||
{
|
||||
int tmp;
|
||||
struct pnp_dev *tdev;
|
||||
unsigned long *port, *end, *tport, *tend;
|
||||
port = &dev->res.port_resource[idx].start;
|
||||
end = &dev->res.port_resource[idx].end;
|
||||
|
||||
/* if the resource doesn't exist, don't complain about it */
|
||||
if (cannot_compare(dev->res.port_resource[idx].flags))
|
||||
return 1;
|
||||
|
||||
/* check if the resource is already in use, skip if the
|
||||
* device is active because it itself may be in use */
|
||||
if(!dev->active) {
|
||||
if (__check_region(&ioport_resource, *port, length(port,end)))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check if the resource is reserved */
|
||||
for (tmp = 0; tmp < 8; tmp++) {
|
||||
int rport = pnp_reserve_io[tmp << 1];
|
||||
int rend = pnp_reserve_io[(tmp << 1) + 1] + rport - 1;
|
||||
if (ranged_conflict(port,end,&rport,&rend))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check for internal conflicts */
|
||||
for (tmp = 0; tmp < PNP_MAX_PORT && tmp != idx; tmp++) {
|
||||
if (dev->res.port_resource[tmp].flags & IORESOURCE_IO) {
|
||||
tport = &dev->res.port_resource[tmp].start;
|
||||
tend = &dev->res.port_resource[tmp].end;
|
||||
if (ranged_conflict(port,end,tport,tend))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* check for conflicts with other pnp devices */
|
||||
pnp_for_each_dev(tdev) {
|
||||
if (tdev == dev)
|
||||
continue;
|
||||
for (tmp = 0; tmp < PNP_MAX_PORT; tmp++) {
|
||||
if (tdev->res.port_resource[tmp].flags & IORESOURCE_IO) {
|
||||
if (cannot_compare(tdev->res.port_resource[tmp].flags))
|
||||
continue;
|
||||
tport = &tdev->res.port_resource[tmp].start;
|
||||
tend = &tdev->res.port_resource[tmp].end;
|
||||
if (ranged_conflict(port,end,tport,tend))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pnp_check_mem(struct pnp_dev * dev, int idx)
|
||||
{
|
||||
int tmp;
|
||||
struct pnp_dev *tdev;
|
||||
unsigned long *addr, *end, *taddr, *tend;
|
||||
addr = &dev->res.mem_resource[idx].start;
|
||||
end = &dev->res.mem_resource[idx].end;
|
||||
|
||||
/* if the resource doesn't exist, don't complain about it */
|
||||
if (cannot_compare(dev->res.mem_resource[idx].flags))
|
||||
return 1;
|
||||
|
||||
/* check if the resource is already in use, skip if the
|
||||
* device is active because it itself may be in use */
|
||||
if(!dev->active) {
|
||||
if (check_mem_region(*addr, length(addr,end)))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check if the resource is reserved */
|
||||
for (tmp = 0; tmp < 8; tmp++) {
|
||||
int raddr = pnp_reserve_mem[tmp << 1];
|
||||
int rend = pnp_reserve_mem[(tmp << 1) + 1] + raddr - 1;
|
||||
if (ranged_conflict(addr,end,&raddr,&rend))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check for internal conflicts */
|
||||
for (tmp = 0; tmp < PNP_MAX_MEM && tmp != idx; tmp++) {
|
||||
if (dev->res.mem_resource[tmp].flags & IORESOURCE_MEM) {
|
||||
taddr = &dev->res.mem_resource[tmp].start;
|
||||
tend = &dev->res.mem_resource[tmp].end;
|
||||
if (ranged_conflict(addr,end,taddr,tend))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* check for conflicts with other pnp devices */
|
||||
pnp_for_each_dev(tdev) {
|
||||
if (tdev == dev)
|
||||
continue;
|
||||
for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) {
|
||||
if (tdev->res.mem_resource[tmp].flags & IORESOURCE_MEM) {
|
||||
if (cannot_compare(tdev->res.mem_resource[tmp].flags))
|
||||
continue;
|
||||
taddr = &tdev->res.mem_resource[tmp].start;
|
||||
tend = &tdev->res.mem_resource[tmp].end;
|
||||
if (ranged_conflict(addr,end,taddr,tend))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static irqreturn_t pnp_test_handler(int irq, void *dev_id, struct pt_regs *regs)
|
||||
{
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
int pnp_check_irq(struct pnp_dev * dev, int idx)
|
||||
{
|
||||
int tmp;
|
||||
struct pnp_dev *tdev;
|
||||
unsigned long * irq = &dev->res.irq_resource[idx].start;
|
||||
|
||||
/* if the resource doesn't exist, don't complain about it */
|
||||
if (cannot_compare(dev->res.irq_resource[idx].flags))
|
||||
return 1;
|
||||
|
||||
/* check if the resource is valid */
|
||||
if (*irq < 0 || *irq > 15)
|
||||
return 0;
|
||||
|
||||
/* check if the resource is reserved */
|
||||
for (tmp = 0; tmp < 16; tmp++) {
|
||||
if (pnp_reserve_irq[tmp] == *irq)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check for internal conflicts */
|
||||
for (tmp = 0; tmp < PNP_MAX_IRQ && tmp != idx; tmp++) {
|
||||
if (dev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) {
|
||||
if (dev->res.irq_resource[tmp].start == *irq)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PCI
|
||||
/* check if the resource is being used by a pci device */
|
||||
{
|
||||
struct pci_dev *pci = NULL;
|
||||
for_each_pci_dev(pci) {
|
||||
if (pci->irq == *irq)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* check if the resource is already in use, skip if the
|
||||
* device is active because it itself may be in use */
|
||||
if(!dev->active) {
|
||||
if (request_irq(*irq, pnp_test_handler, SA_INTERRUPT, "pnp", NULL))
|
||||
return 0;
|
||||
free_irq(*irq, NULL);
|
||||
}
|
||||
|
||||
/* check for conflicts with other pnp devices */
|
||||
pnp_for_each_dev(tdev) {
|
||||
if (tdev == dev)
|
||||
continue;
|
||||
for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) {
|
||||
if (tdev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) {
|
||||
if (cannot_compare(tdev->res.irq_resource[tmp].flags))
|
||||
continue;
|
||||
if ((tdev->res.irq_resource[tmp].start == *irq))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pnp_check_dma(struct pnp_dev * dev, int idx)
|
||||
{
|
||||
#ifndef CONFIG_IA64
|
||||
int tmp;
|
||||
struct pnp_dev *tdev;
|
||||
unsigned long * dma = &dev->res.dma_resource[idx].start;
|
||||
|
||||
/* if the resource doesn't exist, don't complain about it */
|
||||
if (cannot_compare(dev->res.dma_resource[idx].flags))
|
||||
return 1;
|
||||
|
||||
/* check if the resource is valid */
|
||||
if (*dma < 0 || *dma == 4 || *dma > 7)
|
||||
return 0;
|
||||
|
||||
/* check if the resource is reserved */
|
||||
for (tmp = 0; tmp < 8; tmp++) {
|
||||
if (pnp_reserve_dma[tmp] == *dma)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check for internal conflicts */
|
||||
for (tmp = 0; tmp < PNP_MAX_DMA && tmp != idx; tmp++) {
|
||||
if (dev->res.dma_resource[tmp].flags & IORESOURCE_DMA) {
|
||||
if (dev->res.dma_resource[tmp].start == *dma)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* check if the resource is already in use, skip if the
|
||||
* device is active because it itself may be in use */
|
||||
if(!dev->active) {
|
||||
if (request_dma(*dma, "pnp"))
|
||||
return 0;
|
||||
free_dma(*dma);
|
||||
}
|
||||
|
||||
/* check for conflicts with other pnp devices */
|
||||
pnp_for_each_dev(tdev) {
|
||||
if (tdev == dev)
|
||||
continue;
|
||||
for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) {
|
||||
if (tdev->res.dma_resource[tmp].flags & IORESOURCE_DMA) {
|
||||
if (cannot_compare(tdev->res.dma_resource[tmp].flags))
|
||||
continue;
|
||||
if ((tdev->res.dma_resource[tmp].start == *dma))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
#else
|
||||
/* IA64 hasn't legacy DMA */
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
EXPORT_SYMBOL(pnp_register_dependent_option);
|
||||
EXPORT_SYMBOL(pnp_register_independent_option);
|
||||
EXPORT_SYMBOL(pnp_register_irq_resource);
|
||||
EXPORT_SYMBOL(pnp_register_dma_resource);
|
||||
EXPORT_SYMBOL(pnp_register_port_resource);
|
||||
EXPORT_SYMBOL(pnp_register_mem_resource);
|
||||
|
||||
|
||||
/* format is: pnp_reserve_irq=irq1[,irq2] .... */
|
||||
|
||||
static int __init pnp_setup_reserve_irq(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
if (get_option(&str,&pnp_reserve_irq[i]) != 2)
|
||||
break;
|
||||
return 1;
|
||||
}
|
||||
|
||||
__setup("pnp_reserve_irq=", pnp_setup_reserve_irq);
|
||||
|
||||
/* format is: pnp_reserve_dma=dma1[,dma2] .... */
|
||||
|
||||
static int __init pnp_setup_reserve_dma(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
if (get_option(&str,&pnp_reserve_dma[i]) != 2)
|
||||
break;
|
||||
return 1;
|
||||
}
|
||||
|
||||
__setup("pnp_reserve_dma=", pnp_setup_reserve_dma);
|
||||
|
||||
/* format is: pnp_reserve_io=io1,size1[,io2,size2] .... */
|
||||
|
||||
static int __init pnp_setup_reserve_io(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
if (get_option(&str,&pnp_reserve_io[i]) != 2)
|
||||
break;
|
||||
return 1;
|
||||
}
|
||||
|
||||
__setup("pnp_reserve_io=", pnp_setup_reserve_io);
|
||||
|
||||
/* format is: pnp_reserve_mem=mem1,size1[,mem2,size2] .... */
|
||||
|
||||
static int __init pnp_setup_reserve_mem(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
if (get_option(&str,&pnp_reserve_mem[i]) != 2)
|
||||
break;
|
||||
return 1;
|
||||
}
|
||||
|
||||
__setup("pnp_reserve_mem=", pnp_setup_reserve_mem);
|
||||
40
drivers/pnp/support.c
Normal file
40
drivers/pnp/support.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* support.c - provides standard pnp functions for the use of pnp protocol drivers,
|
||||
*
|
||||
* Copyright 2003 Adam Belay <ambx1@neo.rr.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/ctype.h>
|
||||
|
||||
#ifdef CONFIG_PNP_DEBUG
|
||||
#define DEBUG
|
||||
#else
|
||||
#undef DEBUG
|
||||
#endif
|
||||
|
||||
#include <linux/pnp.h>
|
||||
#include "base.h"
|
||||
|
||||
/**
|
||||
* pnp_is_active - Determines if a device is active based on its current resources
|
||||
* @dev: pointer to the desired PnP device
|
||||
*
|
||||
*/
|
||||
|
||||
int pnp_is_active(struct pnp_dev * dev)
|
||||
{
|
||||
if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 &&
|
||||
!pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 &&
|
||||
pnp_irq(dev, 0) == -1 &&
|
||||
pnp_dma(dev, 0) == -1)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
EXPORT_SYMBOL(pnp_is_active);
|
||||
111
drivers/pnp/system.c
Normal file
111
drivers/pnp/system.c
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* system.c - a driver for reserving pnp system resources
|
||||
*
|
||||
* Some code is based on pnpbios_core.c
|
||||
* Copyright 2002 Adam Belay <ambx1@neo.rr.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/pnp.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/ioport.h>
|
||||
|
||||
static const struct pnp_device_id pnp_dev_table[] = {
|
||||
/* General ID for reserving resources */
|
||||
{ "PNP0c02", 0 },
|
||||
/* memory controller */
|
||||
{ "PNP0c01", 0 },
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
static void reserve_ioport_range(char *pnpid, int start, int end)
|
||||
{
|
||||
struct resource *res;
|
||||
char *regionid;
|
||||
|
||||
regionid = kmalloc(16, GFP_KERNEL);
|
||||
if ( regionid == NULL )
|
||||
return;
|
||||
snprintf(regionid, 16, "pnp %s", pnpid);
|
||||
res = request_region(start,end-start+1,regionid);
|
||||
if ( res == NULL )
|
||||
kfree( regionid );
|
||||
else
|
||||
res->flags &= ~IORESOURCE_BUSY;
|
||||
/*
|
||||
* Failures at this point are usually harmless. pci quirks for
|
||||
* example do reserve stuff they know about too, so we may well
|
||||
* have double reservations.
|
||||
*/
|
||||
printk(KERN_INFO
|
||||
"pnp: %s: ioport range 0x%x-0x%x %s reserved\n",
|
||||
pnpid, start, end,
|
||||
NULL != res ? "has been" : "could not be"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void reserve_resources_of_dev( struct pnp_dev *dev )
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0;i<PNP_MAX_PORT;i++) {
|
||||
if (!pnp_port_valid(dev, i))
|
||||
/* end of resources */
|
||||
continue;
|
||||
if (pnp_port_start(dev, i) == 0)
|
||||
/* disabled */
|
||||
/* Do nothing */
|
||||
continue;
|
||||
if (pnp_port_start(dev, i) < 0x100)
|
||||
/*
|
||||
* Below 0x100 is only standard PC hardware
|
||||
* (pics, kbd, timer, dma, ...)
|
||||
* We should not get resource conflicts there,
|
||||
* and the kernel reserves these anyway
|
||||
* (see arch/i386/kernel/setup.c).
|
||||
* So, do nothing
|
||||
*/
|
||||
continue;
|
||||
if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
|
||||
/* invalid endpoint */
|
||||
/* Do nothing */
|
||||
continue;
|
||||
reserve_ioport_range(
|
||||
dev->dev.bus_id,
|
||||
pnp_port_start(dev, i),
|
||||
pnp_port_end(dev, i)
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int system_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id)
|
||||
{
|
||||
reserve_resources_of_dev(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct pnp_driver system_pnp_driver = {
|
||||
.name = "system",
|
||||
.id_table = pnp_dev_table,
|
||||
.flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
|
||||
.probe = system_pnp_probe,
|
||||
.remove = NULL,
|
||||
};
|
||||
|
||||
static int __init pnp_system_init(void)
|
||||
{
|
||||
return pnp_register_driver(&system_pnp_driver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve motherboard resources after PCI claim BARs,
|
||||
* but before PCI assign resources for uninitialized PCI devices
|
||||
*/
|
||||
fs_initcall(pnp_system_init);
|
||||
Loading…
Reference in a new issue