aboutsummaryrefslogblamecommitdiffstats
path: root/Documentation/pnp.txt
blob: af0f6eabfa1c47ee0740664826caacdc15cca94c (plain) (tree)
























































































































































































































































                                                                                       
Linux Plug and Play Documentation
by Adam Belay <ambx1@neo.rr.com>
last updated: Oct. 16, 2002
---------------------------------------------------------------------------------------



Overview
--------
	Plug and Play provides a means of detecting and setting resources for legacy or
otherwise unconfigurable devices.  The Linux Plug and Play Layer provides these 
services to compatible drivers.



The User Interface
------------------
	The Linux Plug and Play user interface provides a means to activate PnP devices
for legacy and user level drivers that do not support Linux Plug and Play.  The 
user interface is integrated into driverfs.

In addition to the standard driverfs file the following are created in each 
device's directory:
id - displays a list of support EISA IDs
options - displays possible resource configurations
resources - displays currently allocated resources and allows resource changes

-activating a device

#echo "auto" > resources

this will invoke the automatic resource config system to activate the device

-manually activating a device

#echo "manual <depnum> <mode>" > resources
<depnum> - the configuration number
<mode> - static or dynamic
		static = for next boot
		dynamic = now

-disabling a device

#echo "disable" > resources


EXAMPLE:

Suppose you need to activate the floppy disk controller.
1.) change to the proper directory, in my case it is 
/driver/bus/pnp/devices/00:0f
# cd /driver/bus/pnp/devices/00:0f
# cat name
PC standard floppy disk controller

2.) check if the device is already active
# cat resources
DISABLED

- Notice the string "DISABLED".  THis means the device is not active.

3.) check the device's possible configurations (optional)
# cat options
Dependent: 01 - Priority acceptable
    port 0x3f0-0x3f0, align 0x7, size 0x6, 16-bit address decoding
    port 0x3f7-0x3f7, align 0x0, size 0x1, 16-bit address decoding
    irq 6
    dma 2 8-bit compatible
Dependent: 02 - Priority acceptable
    port 0x370-0x370, align 0x7, size 0x6, 16-bit address decoding
    port 0x377-0x377, align 0x0, size 0x1, 16-bit address decoding
    irq 6
    dma 2 8-bit compatible

4.) now activate the device
# echo "auto" > resources

5.) finally check if the device is active
# cat resources
io 0x3f0-0x3f5
io 0x3f7-0x3f7
irq 6
dma 2

also there are a series of kernel parameters:
pnp_reserve_irq=irq1[,irq2] ....
pnp_reserve_dma=dma1[,dma2] ....
pnp_reserve_io=io1,size1[,io2,size2] ....
pnp_reserve_mem=mem1,size1[,mem2,size2] ....



The Unified Plug and Play Layer
-------------------------------
	All Plug and Play drivers, protocols, and services meet at a central location 
called the Plug and Play Layer.  This layer is responsible for the exchange of 
information between PnP drivers and PnP protocols.  Thus it automatically 
forwards commands to the proper protocol.  This makes writing PnP drivers 
significantly easier.

The following functions are available from the Plug and Play Layer:

pnp_get_protocol
- increments the number of uses by one

pnp_put_protocol
- deincrements the number of uses by one

pnp_register_protocol
- use this to register a new PnP protocol

pnp_unregister_protocol
- use this function to remove a PnP protocol from the Plug and Play Layer

pnp_register_driver
- adds a PnP driver to the Plug and Play Layer
- this includes driver model integration

pnp_unregister_driver
- removes a PnP driver from the Plug and Play Layer



Plug and Play Protocols
-----------------------
	This section contains information for PnP protocol developers.

The following Protocols are currently available in the computing world:
- PNPBIOS: used for system devices such as serial and parallel ports.
- ISAPNP: provides PnP support for the ISA bus
- ACPI: among its many uses, ACPI provides information about system level 
devices.
It is meant to replace the PNPBIOS.  It is not currently supported by Linux
Plug and Play but it is planned to be in the near future.


Requirements for a Linux PnP protocol:
1.) the protocol must use EISA IDs
2.) the protocol must inform the PnP Layer of a devices current configuration
- the ability to set resources is optional but prefered.

The following are PnP protocol related functions:

pnp_add_device
- use this function to add a PnP device to the PnP layer
- only call this function when all wanted values are set in the pnp_dev 
structure

pnp_init_device
- call this to initialize the PnP structure

pnp_remove_device
- call this to remove a device from the Plug and Play Layer.
- it will fail if the device is still in use.
- automatically will free mem used by the device and related structures

pnp_add_id
- adds a EISA ID to the list of supported IDs for the specified device

For more information consult the source of a protocol such as
/drivers/pnp/pnpbios/core.c.



Linux Plug and Play Drivers
---------------------------
	This section contains information for linux PnP driver developers.

The New Way
...........
1.) first make a list of supported EISA IDS
ex:
static const struct pnp_id pnp_dev_table[] = {
	/* Standard LPT Printer Port */
	{.id = "PNP0400", .driver_data = 0},
	/* ECP Printer Port */
	{.id = "PNP0401", .driver_data = 0},
	{.id = ""}
};

Please note that the character 'X' can be used as a wild card in the function
portion (last four characters).
ex:
	/* Unkown PnP modems */
	{	"PNPCXXX",		UNKNOWN_DEV	},

Supported PnP card IDs can optionally be defined.
ex:
static const struct pnp_id pnp_card_table[] = {
	{	"ANYDEVS",		0	},
	{	"",			0	}
};

2.) Optionally define probe and remove functions.  It may make sense not to 
define these functions if the driver already has a reliable method of detecting
the resources, such as the parport_pc driver.
ex:
static int
serial_pnp_probe(struct pnp_dev * dev, const struct pnp_id *card_id, const 
                 struct pnp_id *dev_id)
{
. . .

ex:
static void serial_pnp_remove(struct pnp_dev * dev)
{
. . .

consult /drivers/serial/8250_pnp.c for more information.

3.) create a driver structure
ex:

static struct pnp_driver serial_pnp_driver = {
	.name		= "serial",
	.card_id_table	= pnp_card_table,
	.id_table	= pnp_dev_table,
	.probe		= serial_pnp_probe,
	.remove		= serial_pnp_remove,
};

* name and id_table can not be NULL.

4.) register the driver
ex:

static int __init serial8250_pnp_init(void)
{
	return pnp_register_driver(&serial_pnp_driver);
}

The Old Way
...........

a series of compatibility functions have been created to make it easy to convert 

ISAPNP drivers.  They should serve as a temporary solution only.

they are as follows:

struct pnp_card *pnp_find_card(unsigned short vendor,
				 unsigned short device,
				 struct pnp_card *from)

struct pnp_dev *pnp_find_dev(struct pnp_card *card,
				unsigned short vendor,
				unsigned short function,
				struct pnp_dev *from)

638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888























































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
‹