요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
=================================
Linux Plug and Play Documentation
=================================
:Author: Adam Belay <[email protected]>
: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 sysfs.
In addition to the standard sysfs 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_register_driver
adds a PnP driver to the Plug and Play Layer
this includes driver model integration
returns zero for success or a negative error number for failure; count
calls to the .add() method if you need to know how many devices bind to
the driver
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 device's current configuration
- the ability to set resources is optional but preferred.
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 an 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::
/* Unknown 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 cannot 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_dev *pnp_find_dev(struct pnp_card *card,
unsigned short vendor,
unsigned short function,
struct pnp_dev *from)
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
개요와 user interface
1-29이 문서는 Linux Plug and Play Documentation입니다. 작성자는 Adam Belay `<[email protected]>`이며 마지막 갱신일은 2002년 10월 16일입니다.
Plug and Play는 legacy device나 그 밖에 직접 구성할 수 없는 device를 감지하고 resource를 설정하는 수단을 제공합니다. Linux Plug and Play Layer는 호환 driver에 이 service를 제공합니다.
Linux Plug and Play user interface는 Linux Plug and Play를 지원하지 않는 legacy driver와 user-level driver를 위해 PnP device를 활성화하는 수단을 제공하며 sysfs에 통합되어 있습니다.
표준 sysfs file에 더해 각 device directory에는 세 file이 생깁니다. `id`는 지원되는 EISA IDs 목록을 표시하고, `options`는 가능한 resource configuration을 표시하며, `resources`는 현재 할당된 resource를 표시하고 resource 변경을 허용합니다.
Device 활성화와 floppy controller 예제
30-109Device를 자동 활성화하려면 다음 명령을 사용합니다. Automatic resource configuration system을 호출해 device를 활성화합니다.
# echo "auto" > resources
Device를 수동 활성화하려면 다음 형식을 사용합니다. `<depnum>`은 configuration number이고 `<mode>`는 `static` 또는 `dynamic`입니다. `static`은 다음 boot에 적용하고 `dynamic`은 지금 적용합니다.
# echo "manual <depnum> <mode>" > resources
<depnum> - the configuration number
<mode> - static or dynamic
static = for next boot
dynamic = now
Device를 비활성화하려면 다음 명령을 사용합니다.
# echo "disable" > resources
Floppy disk controller 활성화를 예로 듭니다. 첫째, 알맞은 directory로 이동합니다. 원문의 예는 `/driver/bus/pnp/devices/00:0f`이며 `name` file에서 PC standard floppy disk controller임을 확인합니다.
# cd /driver/bus/pnp/devices/00:0f
# cat name
PC standard floppy disk controller
둘째, `resources`를 읽어 device가 이미 active인지 확인합니다. `DISABLED` string은 device가 active하지 않다는 뜻입니다.
# cat resources
DISABLED
셋째, 선택적으로 `options`를 읽어 가능한 configuration을 확인합니다. 예제에는 I/O port, IRQ 6, DMA 2를 사용하는 두 dependent configuration이 있습니다.
# 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
넷째, `auto`를 `resources`에 써서 device를 활성화합니다.
# echo "auto" > resources
다섯째, `resources`를 다시 읽어 device가 active인지 확인합니다. 예제에서는 I/O range 두 개, IRQ 6, DMA 2가 할당됩니다.
# cat resources
io 0x3f0-0x3f5
io 0x3f7-0x3f7
irq 6
dma 2
또한 IRQ, DMA, I/O, memory resource를 예약하는 kernel parameter 계열이 있습니다.
pnp_reserve_irq=irq1[,irq2] ....
pnp_reserve_dma=dma1[,dma2] ....
pnp_reserve_io=io1,size1[,io2,size2] ....
pnp_reserve_mem=mem1,size1[,mem2,size2] ....
Unified Plug and Play Layer
110-143모든 Plug and Play driver, protocol, service는 Plug and Play Layer라는 중앙 위치에서 만납니다. 이 layer는 PnP driver와 PnP protocol 사이의 정보 교환을 담당하고 command를 적절한 protocol로 자동 전달합니다. 따라서 PnP driver 작성이 훨씬 쉬워집니다.
`pnp_get_protocol`은 사용 횟수를 1 늘리고 `pnp_put_protocol`은 1 줄입니다. `pnp_register_protocol`은 새 PnP protocol을 등록합니다.
`pnp_register_driver`는 PnP driver를 Plug and Play Layer에 추가하며 driver model 통합도 포함합니다. 성공하면 0, 실패하면 negative error number를 반환합니다. Driver에 bind된 device 수가 필요하면 `.add()` method 호출 횟수를 세어야 합니다.
`pnp_unregister_driver`는 PnP driver를 Plug and Play Layer에서 제거합니다.
Plug and Play protocol
144-193이 절은 PnP protocol developer를 위한 정보입니다. Computing 환경에서 사용할 수 있는 protocol로 PNPBIOS, ISAPNP, ACPI를 나열합니다.
PNPBIOS는 serial port와 parallel port 같은 system device에 사용합니다. ISAPNP는 ISA bus의 PnP 지원을 제공합니다. ACPI는 여러 용도 가운데 system-level device에 관한 정보도 제공합니다.
원문은 ACPI가 PNPBIOS를 대체하도록 설계되었으며, 문서 작성 당시에는 Linux Plug and Play가 아직 지원하지 않았지만 가까운 미래에 지원할 계획이라고 설명합니다.
Linux PnP protocol은 EISA IDs를 사용해야 하고 device의 current configuration을 PnP Layer에 알려야 합니다. Resource 설정 능력은 optional이지만 권장됩니다.
`pnp_add_device`는 PnP device를 PnP Layer에 추가합니다. `pnp_dev` structure에 필요한 값을 모두 설정한 뒤에만 호출해야 합니다. `pnp_init_device`는 PnP structure를 초기화합니다.
`pnp_remove_device`는 Plug and Play Layer에서 device를 제거합니다. Device가 아직 사용 중이면 실패하며 device와 관련 structure가 사용한 memory를 자동으로 해제합니다. `pnp_add_id`는 지정된 device의 지원 ID 목록에 EISA ID를 추가합니다.
더 자세한 내용은 `/drivers/pnp/pnpbios/core.c` 같은 protocol source를 참조하십시오.
Linux PnP driver의 새 방식
194-272이 절은 Linux PnP driver developer를 위한 정보입니다. 새 방식의 첫 단계는 지원되는 EISA IDS 목록을 만드는 것입니다. 다음 `pnp_dev_table`은 standard LPT printer port `PNP0400`과 ECP printer port `PNP0401`을 등록하고 빈 ID로 끝납니다.
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 = ""}
};
Function 부분인 마지막 네 character에는 `X`를 wildcard로 사용할 수 있습니다. 다음 예는 알 수 없는 PnP modem을 `PNPCXXX`로 표현합니다.
/* Unknown PnP modems */
{ "PNPCXXX", UNKNOWN_DEV },
지원되는 PnP card ID도 선택적으로 정의할 수 있습니다. 다음 `pnp_card_table`은 `ANYDEVS`와 종료 entry를 포함합니다.
static const struct pnp_id pnp_card_table[] = {
{ "ANYDEVS", 0 },
{ "", 0 }
};
둘째, 선택적으로 probe와 remove function을 정의합니다. `parport_pc` driver처럼 이미 신뢰할 수 있는 resource 감지 방법이 있다면 이 function들을 정의하지 않는 편이 합리적일 수 있습니다.
다음은 `serial_pnp_probe` 선언 예제입니다.
static int
serial_pnp_probe(struct pnp_dev * dev, const struct pnp_id *card_id, const
struct pnp_id *dev_id)
{
. . .
다음은 `serial_pnp_remove` 선언 예제입니다. 자세한 내용은 `/drivers/serial/8250_pnp.c`를 참조하십시오.
static void serial_pnp_remove(struct pnp_dev * dev)
{
. . .
셋째, driver structure를 만듭니다. `serial_pnp_driver`는 name, card ID table, device ID table, probe, remove callback을 연결합니다. `name`과 `id_table`은 NULL일 수 없습니다.
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,
};
넷째, driver를 등록합니다. `serial8250_pnp_init`은 `pnp_register_driver(&serial_pnp_driver)`의 결과를 반환합니다.
static int __init serial8250_pnp_init(void)
{
return pnp_register_driver(&serial_pnp_driver);
}
기존 ISAPNP driver 호환 방식
273-285기존 ISAPNP driver를 쉽게 전환하도록 compatibility function 계열이 만들어졌습니다. 이는 임시 해법으로만 사용해야 합니다.
원문이 나열하는 compatibility function은 다음 `pnp_find_dev` 선언입니다.
struct pnp_dev *pnp_find_dev(struct pnp_card *card,
unsigned short vendor,
unsigned short function,
struct pnp_dev *from)
요약과 해설
pnp.rst:1-285Linux PnP는 legacy device의 resource를 검색·할당하고, userspace sysfs interface와 protocol-neutral driver API를 연결합니다.
이 문서는 2002년 기준의 경로와 API를 설명하므로 역사적 source path와 ACPI 지원 상태는 원문 그대로 읽되, 실제 kernel version에서 현재 API를 별도로 확인해야 합니다.