← Documents Documentation/userspace-api/gpio/gpio-get-linehandle-ioctl.rst GitHub 원문 ↗

Linux 6.18.37 · Userspace API

GPIO_GET_LINEHANDLE_IOCTL

ABI v1 line 집합 요청의 배타적 접근, 구성 flag 조합, hardware 미지원 기능 처리와 반환값을 설명합니다.

Source pathDocumentation/userspace-api/gpio/gpio-get-linehandle-ioctl.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

gpio-get-linehandle-ioctl.rst:1-125

ABI v1 line 집합 요청의 배타적 접근, 구성 flag 조합, hardware 미지원 기능 처리와 반환값을 설명합니다.

원문의 ioctl prototype, struct, flag, errno, source path와 줄 좌표를 보존해 전문 번역했습니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 .. _GPIO_GET_LINEHANDLE_IOCTL:
4
5 *************************
6 GPIO_GET_LINEHANDLE_IOCTL
7 *************************
8
9 .. warning::
10 This ioctl is part of chardev_v1.rst and is obsoleted by
11 gpio-v2-get-line-ioctl.rst.
12
13 Name
14 ====
15
16 GPIO_GET_LINEHANDLE_IOCTL - Request a line or lines from the kernel.
17
18 Synopsis
19 ========
20
21 .. c:macro:: GPIO_GET_LINEHANDLE_IOCTL
22
23 ``int ioctl(int chip_fd, GPIO_GET_LINEHANDLE_IOCTL, struct gpiohandle_request *request)``
24
25 Arguments
26 =========
27
28 ``chip_fd``
29 The file descriptor of the GPIO character device returned by `open()`.
30
31 ``request``
32 The :c:type:`handle_request<gpiohandle_request>` specifying the lines to
33 request and their configuration.
34
35 Description
36 ===========
37
38 Request a line or lines from the kernel.
39
40 While multiple lines may be requested, the same configuration applies to all
41 lines in the request.
42
43 On success, the requesting process is granted exclusive access to the line
44 value and write access to the line configuration.
45
46 The state of a line, including the value of output lines, is guaranteed to
47 remain as requested until the returned file descriptor is closed. Once the
48 file descriptor is closed, the state of the line becomes uncontrolled from
49 the userspace perspective, and may revert to its default state.
50
51 Requesting a line already in use is an error (**EBUSY**).
52
53 Closing the ``chip_fd`` has no effect on existing line handles.
54
55 .. _gpio-get-linehandle-config-rules:
56
57 Configuration Rules
58 -------------------
59
60 The following configuration rules apply:
61
62 The direction flags, ``GPIOHANDLE_REQUEST_INPUT`` and
63 ``GPIOHANDLE_REQUEST_OUTPUT``, cannot be combined. If neither are set then the
64 only other flag that may be set is ``GPIOHANDLE_REQUEST_ACTIVE_LOW`` and the
65 line is requested "as-is" to allow reading of the line value without altering
66 the electrical configuration.
67
68 The drive flags, ``GPIOHANDLE_REQUEST_OPEN_xxx``, require the
69 ``GPIOHANDLE_REQUEST_OUTPUT`` to be set.
70 Only one drive flag may be set.
71 If none are set then the line is assumed push-pull.
72
73 Only one bias flag, ``GPIOHANDLE_REQUEST_BIAS_xxx``, may be set, and
74 it requires a direction flag to also be set.
75 If no bias flags are set then the bias configuration is not changed.
76
77 Requesting an invalid configuration is an error (**EINVAL**).
78
79
80 .. _gpio-get-linehandle-config-support:
81
82 Configuration Support
83 ---------------------
84
85 Where the requested configuration is not directly supported by the underlying
86 hardware and driver, the kernel applies one of these approaches:
87
88 - reject the request
89 - emulate the feature in software
90 - treat the feature as best effort
91
92 The approach applied depends on whether the feature can reasonably be emulated
93 in software, and the impact on the hardware and userspace if the feature is not
94 supported.
95 The approach applied for each feature is as follows:
96
97 ============== ===========
98 Feature Approach
99 ============== ===========
100 Bias best effort
101 Direction reject
102 Drive emulate
103 ============== ===========
104
105 Bias is treated as best effort to allow userspace to apply the same
106 configuration for platforms that support internal bias as those that require
107 external bias.
108 Worst case the line floats rather than being biased as expected.
109
110 Drive is emulated by switching the line to an input when the line should not
111 be driven.
112
113 In all cases, the configuration reported by gpio-get-lineinfo-ioctl.rst
114 is the requested configuration, not the resulting hardware configuration.
115 Userspace cannot determine if a feature is supported in hardware, is
116 emulated, or is best effort.
117
118 Return Value
119 ============
120
121 On success 0 and the :c:type:`request.fd<gpiohandle_request>` contains the
122 file descriptor for the request.
123
124 On error -1 and the ``errno`` variable is set appropriately.
125 Common error codes are described in error-codes.rst.
126

3. 한국어 전문 번역

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

상태, 이름, 호출 형식

1-34

`GPIO_GET_LINEHANDLE_IOCTL`은 kernel에서 하나 이상의 GPIO line을 요청합니다. 이 ioctl은 `chardev_v1.rst`의 ABI v1에 속하며 `gpio-v2-get-line-ioctl.rst`로 대체되었습니다.

호출 형식은 `int ioctl(int chip_fd, GPIO_GET_LINEHANDLE_IOCTL, struct gpiohandle_request *request)`입니다. `chip_fd`는 GPIO character device를 `open()`해 얻고, `request`는 요청할 line 집합과 공통 구성을 지정하는 `gpiohandle_request` 구조체입니다.

Line handle 요청 인자
항목설명
chip_fdGPIO character device file descriptor
requeststruct gpiohandle_request pointer
결과 fdrequest.fd

한 요청 안의 모든 line에는 같은 구성이 적용됩니다.

.. SPDX-License-Identifier: GPL-2.0

.. _GPIO_GET_LINEHANDLE_IOCTL:

*************************
GPIO_GET_LINEHANDLE_IOCTL
*************************

.. warning::
    This ioctl is part of chardev_v1.rst and is obsoleted by
    gpio-v2-get-line-ioctl.rst.

Name
====

GPIO_GET_LINEHANDLE_IOCTL - Request a line or lines from the kernel.

Synopsis
========

.. c:macro:: GPIO_GET_LINEHANDLE_IOCTL

``int ioctl(int chip_fd, GPIO_GET_LINEHANDLE_IOCTL, struct gpiohandle_request *request)``

Arguments
=========

``chip_fd``
    The file descriptor of the GPIO character device returned by `open()`.

``request``
    The :c:type:`handle_request<gpiohandle_request>` specifying the lines to
    request and their configuration.

배타적 접근과 수명

35-54

한 번에 여러 line을 요청할 수 있지만 요청에 포함된 모든 line에는 동일한 구성이 적용됩니다. 성공하면 요청 process는 line 값에 대한 배타적 접근 권한과 line configuration에 대한 쓰기 권한을 얻습니다.

Output line의 값을 포함한 line 상태는 반환된 file descriptor가 닫힐 때까지 요청대로 유지됩니다. Descriptor를 닫으면 사용자 공간 관점에서 상태가 더 이상 제어되지 않고 기본 상태로 돌아갈 수 있습니다.

이미 사용 중인 line을 요청하면 `EBUSY`입니다. 기존 line handle이 있는 상태에서 `chip_fd`를 닫아도 해당 handle에는 영향이 없습니다.

Line handle 수명
chip_fd로 line 집합 요청배타적 값 접근과 구성 쓰기 권한 획득request.fd로 값 읽기/쓰기와 재구성chip_fd를 닫아도 handle 유지request.fd를 닫으면 상태 보장 종료

Chip descriptor는 요청 생성에 쓰이고 handle descriptor가 line 소유권을 유지합니다.

Description
===========

Request a line or lines from the kernel.

While multiple lines may be requested, the same configuration applies to all
lines in the request.

On success, the requesting process is granted exclusive access to the line
value and write access to the line configuration.

The state of a line, including the value of output lines, is guaranteed to
remain as requested until the returned file descriptor is closed. Once the
file descriptor is closed, the state of the line becomes uncontrolled from
the userspace perspective, and may revert to its default state.

Requesting a line already in use is an error (**EBUSY**).

Closing the ``chip_fd`` has no effect on existing line handles.

방향, drive, bias 구성 규칙

55-78

방향 flag `GPIOHANDLE_REQUEST_INPUT`과 `GPIOHANDLE_REQUEST_OUTPUT`은 함께 설정할 수 없습니다. 둘 다 설정하지 않았다면 허용되는 다른 flag는 `GPIOHANDLE_REQUEST_ACTIVE_LOW`뿐입니다. 이 경우 전기적 구성을 바꾸지 않고 값을 읽도록 line을 현재 상태 그대로, 즉 as-is로 요청합니다.

`GPIOHANDLE_REQUEST_OPEN_xxx` drive flag를 쓰려면 `GPIOHANDLE_REQUEST_OUTPUT`도 설정해야 하며 drive flag는 하나만 선택할 수 있습니다. Drive flag가 없으면 push-pull로 간주합니다.

`GPIOHANDLE_REQUEST_BIAS_xxx` bias flag도 하나만 선택할 수 있고 방향 flag가 함께 있어야 합니다. Bias flag가 없으면 bias 구성을 변경하지 않습니다. 유효하지 않은 구성을 요청하면 `EINVAL`입니다.

Line handle 구성 규칙
항목설명
INPUT + OUTPUT동시 설정 금지
방향 flag 없음ACTIVE_LOW만 추가 가능, line을 as-is로 요청
OPEN_xxxOUTPUT 필요, 하나만 선택
Drive flag 없음Push-pull로 간주
BIAS_xxx방향 flag 필요, 하나만 선택
Bias flag 없음기존 bias 유지
Invalid configurationEINVAL

Flag 그룹별 조합 제약입니다.

.. _gpio-get-linehandle-config-rules:

Configuration Rules
-------------------

The following configuration rules apply:

The direction flags, ``GPIOHANDLE_REQUEST_INPUT`` and
``GPIOHANDLE_REQUEST_OUTPUT``, cannot be combined. If neither are set then the
only other flag that may be set is ``GPIOHANDLE_REQUEST_ACTIVE_LOW`` and the
line is requested "as-is" to allow reading of the line value without altering
the electrical configuration.

The drive flags, ``GPIOHANDLE_REQUEST_OPEN_xxx``, require the
``GPIOHANDLE_REQUEST_OUTPUT`` to be set.
Only one drive flag may be set.
If none are set then the line is assumed push-pull.

Only one bias flag, ``GPIOHANDLE_REQUEST_BIAS_xxx``, may be set, and
it requires a direction flag to also be set.
If no bias flags are set then the bias configuration is not changed.

Requesting an invalid configuration is an error (**EINVAL**).

하드웨어 미지원 기능의 처리

79-117

요청 구성을 하위 hardware와 driver가 직접 지원하지 않으면 kernel은 요청 거부, software emulation, best effort 중 하나를 적용합니다. 어떤 방식을 쓸지는 기능을 software로 합리적으로 모사할 수 있는지와 미지원 상태가 hardware 및 userspace에 미치는 영향에 따라 결정됩니다.

Bias는 best effort, direction은 reject, drive는 emulate 방식입니다. 내부 bias가 있는 platform과 외부 bias가 필요한 platform에서 userspace가 같은 구성을 적용할 수 있도록 bias를 best effort로 취급합니다. 최악의 경우 예상한 bias가 걸리지 않고 line이 floating 상태가 됩니다.

Drive는 line을 구동하지 않아야 할 때 input으로 전환하는 방식으로 모사합니다. 모든 경우 `gpio-get-lineinfo-ioctl.rst`가 보고하는 구성은 실제 hardware 구성이 아니라 요청한 구성입니다. 따라서 userspace는 기능이 hardware에서 직접 지원되는지, emulation되는지, best effort인지 판별할 수 없습니다.

미지원 구성 처리
기능처리 방식
BiasBest effort; 미지원 시 line이 floating일 수 있음
Direction요청 거부
Drive구동하지 않을 때 input으로 전환해 emulation
Line info 보고결과 hardware 상태가 아니라 요청한 구성

ABI가 기능별로 정한 fallback입니다.

구성 적용 판단
공통 line 구성 요청Hardware와 driver의 직접 지원 확인Direction 미지원이면 요청 거부Drive 미지원이면 software emulationBias 미지원이면 best effortLine info에는 요청 구성을 보고

Driver와 hardware의 지원 수준에 따라 kernel이 정해진 정책을 적용합니다.


.. _gpio-get-linehandle-config-support:

Configuration Support
---------------------

Where the requested configuration is not directly supported by the underlying
hardware and driver, the kernel applies one of these approaches:

 - reject the request
 - emulate the feature in software
 - treat the feature as best effort

The approach applied depends on whether the feature can reasonably be emulated
in software, and the impact on the hardware and userspace if the feature is not
supported.
The approach applied for each feature is as follows:

==============   ===========
Feature          Approach
==============   ===========
Bias             best effort
Direction        reject
Drive            emulate
==============   ===========

Bias is treated as best effort to allow userspace to apply the same
configuration for platforms that support internal bias as those that require
external bias.
Worst case the line floats rather than being biased as expected.

Drive is emulated by switching the line to an input when the line should not
be driven.

In all cases, the configuration reported by gpio-get-lineinfo-ioctl.rst
is the requested configuration, not the resulting hardware configuration.
Userspace cannot determine if a feature is supported in hardware, is
emulated, or is best effort.

반환값

118-125

성공하면 0을 반환하고 `gpiohandle_request`의 `request.fd`에 요청 file descriptor를 저장합니다. 실패하면 -1을 반환하고 `errno`를 설정합니다. 공통 오류 코드는 `error-codes.rst`에 설명되어 있습니다.

Return Value
============

On success 0 and the :c:type:`request.fd<gpiohandle_request>` contains the
file descriptor for the request.

On error -1 and the ``errno`` variable is set appropriately.
Common error codes are described in error-codes.rst.