← Documents Documentation/admin-guide/pnp.rst GitHub 원문 ↗

Linux 6.18.37 · Administration

Linux Plug and Play Documentation

Linux PnP의 sysfs resource 제어, 중앙 protocol layer와 PnP driver 등록 방식을 설명합니다.

Source pathDocumentation/admin-guide/pnp.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

pnp.rst:1-285

Linux PnP는 legacy device의 resource를 검색·할당하고, userspace sysfs interface와 protocol-neutral driver API를 연결합니다.

이 문서는 2002년 기준의 경로와 API를 설명하므로 역사적 source path와 ACPI 지원 상태는 원문 그대로 읽되, 실제 kernel version에서 현재 API를 별도로 확인해야 합니다.

영역핵심
Userspacesysfs의 `id`, `options`, `resources`
자동 활성화`echo "auto" > resources`
수동 활성화`manual <depnum> <mode>`; `static` 또는 `dynamic`
비활성화`echo "disable" > resources`
중앙 계층PnP driver와 protocol 사이 command 전달
ProtocolPNPBIOS, ISAPNP, ACPI; EISA ID와 current configuration 필요
Driver 등록`pnp_id` table, optional probe/remove, `pnp_driver`, register
호환 API기존 ISAPNP driver 전환용 임시 compatibility function

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 =================================
2 Linux Plug and Play Documentation
3 =================================
4
5 :Author: Adam Belay <ambx1@neo.rr.com>
6 :Last updated: Oct. 16, 2002
7
8
9 Overview
10 --------
11
12 Plug and Play provides a means of detecting and setting resources for legacy or
13 otherwise unconfigurable devices. The Linux Plug and Play Layer provides these
14 services to compatible drivers.
15
16
17 The User Interface
18 ------------------
19
20 The Linux Plug and Play user interface provides a means to activate PnP devices
21 for legacy and user level drivers that do not support Linux Plug and Play. The
22 user interface is integrated into sysfs.
23
24 In addition to the standard sysfs file the following are created in each
25 device's directory:
26 - id - displays a list of support EISA IDs
27 - options - displays possible resource configurations
28 - resources - displays currently allocated resources and allows resource changes
29
30 activating a device
31 ^^^^^^^^^^^^^^^^^^^
32
33 ::
34
35 # echo "auto" > resources
36
37 this will invoke the automatic resource config system to activate the device
38
39 manually activating a device
40 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41
42 ::
43
44 # echo "manual <depnum> <mode>" > resources
45
46 <depnum> - the configuration number
47 <mode> - static or dynamic
48 static = for next boot
49 dynamic = now
50
51 disabling a device
52 ^^^^^^^^^^^^^^^^^^
53
54 ::
55
56 # echo "disable" > resources
57
58
59 EXAMPLE:
60
61 Suppose you need to activate the floppy disk controller.
62
63 1. change to the proper directory, in my case it is
64 /driver/bus/pnp/devices/00:0f::
65
66 # cd /driver/bus/pnp/devices/00:0f
67 # cat name
68 PC standard floppy disk controller
69
70 2. check if the device is already active::
71
72 # cat resources
73 DISABLED
74
75 - Notice the string "DISABLED". This means the device is not active.
76
77 3. check the device's possible configurations (optional)::
78
79 # cat options
80 Dependent: 01 - Priority acceptable
81 port 0x3f0-0x3f0, align 0x7, size 0x6, 16-bit address decoding
82 port 0x3f7-0x3f7, align 0x0, size 0x1, 16-bit address decoding
83 irq 6
84 dma 2 8-bit compatible
85 Dependent: 02 - Priority acceptable
86 port 0x370-0x370, align 0x7, size 0x6, 16-bit address decoding
87 port 0x377-0x377, align 0x0, size 0x1, 16-bit address decoding
88 irq 6
89 dma 2 8-bit compatible
90
91 4. now activate the device::
92
93 # echo "auto" > resources
94
95 5. finally check if the device is active::
96
97 # cat resources
98 io 0x3f0-0x3f5
99 io 0x3f7-0x3f7
100 irq 6
101 dma 2
102
103 also there are a series of kernel parameters::
104
105 pnp_reserve_irq=irq1[,irq2] ....
106 pnp_reserve_dma=dma1[,dma2] ....
107 pnp_reserve_io=io1,size1[,io2,size2] ....
108 pnp_reserve_mem=mem1,size1[,mem2,size2] ....
109
110
111
112 The Unified Plug and Play Layer
113 -------------------------------
114
115 All Plug and Play drivers, protocols, and services meet at a central location
116 called the Plug and Play Layer. This layer is responsible for the exchange of
117 information between PnP drivers and PnP protocols. Thus it automatically
118 forwards commands to the proper protocol. This makes writing PnP drivers
119 significantly easier.
120
121 The following functions are available from the Plug and Play Layer:
122
123 pnp_get_protocol
124 increments the number of uses by one
125
126 pnp_put_protocol
127 deincrements the number of uses by one
128
129 pnp_register_protocol
130 use this to register a new PnP protocol
131
132 pnp_register_driver
133 adds a PnP driver to the Plug and Play Layer
134
135 this includes driver model integration
136 returns zero for success or a negative error number for failure; count
137 calls to the .add() method if you need to know how many devices bind to
138 the driver
139
140 pnp_unregister_driver
141 removes a PnP driver from the Plug and Play Layer
142
143
144
145 Plug and Play Protocols
146 -----------------------
147
148 This section contains information for PnP protocol developers.
149
150 The following Protocols are currently available in the computing world:
151
152 - PNPBIOS:
153 used for system devices such as serial and parallel ports.
154 - ISAPNP:
155 provides PnP support for the ISA bus
156 - ACPI:
157 among its many uses, ACPI provides information about system level
158 devices.
159
160 It is meant to replace the PNPBIOS. It is not currently supported by Linux
161 Plug and Play but it is planned to be in the near future.
162
163
164 Requirements for a Linux PnP protocol:
165 1. the protocol must use EISA IDs
166 2. the protocol must inform the PnP Layer of a device's current configuration
167
168 - the ability to set resources is optional but preferred.
169
170 The following are PnP protocol related functions:
171
172 pnp_add_device
173 use this function to add a PnP device to the PnP layer
174
175 only call this function when all wanted values are set in the pnp_dev
176 structure
177
178 pnp_init_device
179 call this to initialize the PnP structure
180
181 pnp_remove_device
182 call this to remove a device from the Plug and Play Layer.
183 it will fail if the device is still in use.
184 automatically will free mem used by the device and related structures
185
186 pnp_add_id
187 adds an EISA ID to the list of supported IDs for the specified device
188
189 For more information consult the source of a protocol such as
190 /drivers/pnp/pnpbios/core.c.
191
192
193
194 Linux Plug and Play Drivers
195 ---------------------------
196
197 This section contains information for Linux PnP driver developers.
198
199 The New Way
200 ^^^^^^^^^^^
201
202 1. first make a list of supported EISA IDS
203
204 ex::
205
206 static const struct pnp_id pnp_dev_table[] = {
207 /* Standard LPT Printer Port */
208 {.id = "PNP0400", .driver_data = 0},
209 /* ECP Printer Port */
210 {.id = "PNP0401", .driver_data = 0},
211 {.id = ""}
212 };
213
214 Please note that the character 'X' can be used as a wild card in the function
215 portion (last four characters).
216
217 ex::
218
219 /* Unknown PnP modems */
220 { "PNPCXXX", UNKNOWN_DEV },
221
222 Supported PnP card IDs can optionally be defined.
223 ex::
224
225 static const struct pnp_id pnp_card_table[] = {
226 { "ANYDEVS", 0 },
227 { "", 0 }
228 };
229
230 2. Optionally define probe and remove functions. It may make sense not to
231 define these functions if the driver already has a reliable method of detecting
232 the resources, such as the parport_pc driver.
233
234 ex::
235
236 static int
237 serial_pnp_probe(struct pnp_dev * dev, const struct pnp_id *card_id, const
238 struct pnp_id *dev_id)
239 {
240 . . .
241
242 ex::
243
244 static void serial_pnp_remove(struct pnp_dev * dev)
245 {
246 . . .
247
248 consult /drivers/serial/8250_pnp.c for more information.
249
250 3. create a driver structure
251
252 ex::
253
254 static struct pnp_driver serial_pnp_driver = {
255 .name = "serial",
256 .card_id_table = pnp_card_table,
257 .id_table = pnp_dev_table,
258 .probe = serial_pnp_probe,
259 .remove = serial_pnp_remove,
260 };
261
262 * name and id_table cannot be NULL.
263
264 4. register the driver
265
266 ex::
267
268 static int __init serial8250_pnp_init(void)
269 {
270 return pnp_register_driver(&serial_pnp_driver);
271 }
272
273 The Old Way
274 ^^^^^^^^^^^
275
276 A series of compatibility functions have been created to make it easy to convert
277 ISAPNP drivers. They should serve as a temporary solution only.
278
279 They are as follows::
280
281 struct pnp_dev *pnp_find_dev(struct pnp_card *card,
282 unsigned short vendor,
283 unsigned short function,
284 struct pnp_dev *from)
285
286

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

개요와 user interface

1-29

이 문서는 Linux Plug and Play Documentation입니다. 작성자는 Adam Belay `<ambx1@neo.rr.com>`이며 마지막 갱신일은 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-109

Device를 자동 활성화하려면 다음 명령을 사용합니다. 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)