요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
============================================
Remote Processor Messaging (rpmsg) Framework
============================================
.. note::
This document describes the rpmsg bus and how to write rpmsg drivers.
To learn how to add rpmsg support for new platforms, check out remoteproc.txt
(also a resident of Documentation/).
Introduction
============
Modern SoCs typically employ heterogeneous remote processor devices in
asymmetric multiprocessing (AMP) configurations, which may be running
different instances of operating system, whether it's Linux or any other
flavor of real-time OS.
OMAP4, for example, has dual Cortex-A9, dual Cortex-M3 and a C64x+ DSP.
Typically, the dual cortex-A9 is running Linux in a SMP configuration,
and each of the other three cores (two M3 cores and a DSP) is running
its own instance of RTOS in an AMP configuration.
Typically AMP remote processors employ dedicated DSP codecs and multimedia
hardware accelerators, and therefore are often used to offload CPU-intensive
multimedia tasks from the main application processor.
These remote processors could also be used to control latency-sensitive
sensors, drive random hardware blocks, or just perform background tasks
while the main CPU is idling.
Users of those remote processors can either be userland apps (e.g. multimedia
frameworks talking with remote OMX components) or kernel drivers (controlling
hardware accessible only by the remote processor, reserving kernel-controlled
resources on behalf of the remote processor, etc..).
Rpmsg is a virtio-based messaging bus that allows kernel drivers to communicate
with remote processors available on the system. In turn, drivers could then
expose appropriate user space interfaces, if needed.
When writing a driver that exposes rpmsg communication to userland, please
keep in mind that remote processors might have direct access to the
system's physical memory and other sensitive hardware resources (e.g. on
OMAP4, remote cores and hardware accelerators may have direct access to the
physical memory, gpio banks, dma controllers, i2c bus, gptimers, mailbox
devices, hwspinlocks, etc..). Moreover, those remote processors might be
running RTOS where every task can access the entire memory/devices exposed
to the processor. To minimize the risks of rogue (or buggy) userland code
exploiting remote bugs, and by that taking over the system, it is often
desired to limit userland to specific rpmsg channels (see definition below)
it can send messages on, and if possible, minimize how much control
it has over the content of the messages.
Every rpmsg device is a communication channel with a remote processor (thus
rpmsg devices are called channels). Channels are identified by a textual name
and have a local ("source") rpmsg address, and remote ("destination") rpmsg
address.
When a driver starts listening on a channel, its rx callback is bound with
a unique rpmsg local address (a 32-bit integer). This way when inbound messages
arrive, the rpmsg core dispatches them to the appropriate driver according
to their destination address (this is done by invoking the driver's rx handler
with the payload of the inbound message).
User API
========
::
int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len);
sends a message across to the remote processor from the given endpoint.
The caller should specify the endpoint, the data it wants to send,
and its length (in bytes). The message will be sent on the specified
endpoint's channel, i.e. its source and destination address fields will be
respectively set to the endpoint's src address and its parent channel
dst addresses.
In case there are no TX buffers available, the function will block until
one becomes available (i.e. until the remote processor consumes
a tx buffer and puts it back on virtio's used descriptor ring),
or a timeout of 15 seconds elapses. When the latter happens,
-ERESTARTSYS is returned.
The function can only be called from a process context (for now).
Returns 0 on success and an appropriate error value on failure.
::
int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
sends a message across to the remote processor from a given endpoint,
to a destination address provided by the caller.
The caller should specify the endpoint, the data it wants to send,
its length (in bytes), and an explicit destination address.
The message will then be sent to the remote processor to which the
endpoints's channel belongs, using the endpoints's src address,
and the user-provided dst address (thus the channel's dst address
will be ignored).
In case there are no TX buffers available, the function will block until
one becomes available (i.e. until the remote processor consumes
a tx buffer and puts it back on virtio's used descriptor ring),
or a timeout of 15 seconds elapses. When the latter happens,
-ERESTARTSYS is returned.
The function can only be called from a process context (for now).
Returns 0 on success and an appropriate error value on failure.
::
int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len);
sends a message across to the remote processor from a given endpoint.
The caller should specify the endpoint, the data it wants to send,
and its length (in bytes). The message will be sent on the specified
endpoint's channel, i.e. its source and destination address fields will be
respectively set to the endpoint's src address and its parent channel
dst addresses.
In case there are no TX buffers available, the function will immediately
return -ENOMEM without waiting until one becomes available.
The function can only be called from a process context (for now).
Returns 0 on success and an appropriate error value on failure.
::
int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
sends a message across to the remote processor from a given endpoint,
to a destination address provided by the user.
The user should specify the channel, the data it wants to send,
its length (in bytes), and an explicit destination address.
The message will then be sent to the remote processor to which the
channel belongs, using the channel's src address, and the user-provided
dst address (thus the channel's dst address will be ignored).
In case there are no TX buffers available, the function will immediately
return -ENOMEM without waiting until one becomes available.
The function can only be called from a process context (for now).
Returns 0 on success and an appropriate error value on failure.
::
struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
rpmsg_rx_cb_t cb, void *priv,
struct rpmsg_channel_info chinfo);
every rpmsg address in the system is bound to an rx callback (so when
inbound messages arrive, they are dispatched by the rpmsg bus using the
appropriate callback handler) by means of an rpmsg_endpoint struct.
This function allows drivers to create such an endpoint, and by that,
bind a callback, and possibly some private data too, to an rpmsg address
(either one that is known in advance, or one that will be dynamically
assigned for them).
Simple rpmsg drivers need not call rpmsg_create_ept, because an endpoint
is already created for them when they are probed by the rpmsg bus
(using the rx callback they provide when they registered to the rpmsg bus).
So things should just work for simple drivers: they already have an
endpoint, their rx callback is bound to their rpmsg address, and when
relevant inbound messages arrive (i.e. messages which their dst address
equals to the src address of their rpmsg channel), the driver's handler
is invoked to process it.
That said, more complicated drivers might do need to allocate
additional rpmsg addresses, and bind them to different rx callbacks.
To accomplish that, those drivers need to call this function.
Drivers should provide their channel (so the new endpoint would bind
to the same remote processor their channel belongs to), an rx callback
function, an optional private data (which is provided back when the
rx callback is invoked), and an address they want to bind with the
callback. If addr is RPMSG_ADDR_ANY, then rpmsg_create_ept will
dynamically assign them an available rpmsg address (drivers should have
a very good reason why not to always use RPMSG_ADDR_ANY here).
Returns a pointer to the endpoint on success, or NULL on error.
::
void rpmsg_destroy_ept(struct rpmsg_endpoint *ept);
destroys an existing rpmsg endpoint. user should provide a pointer
to an rpmsg endpoint that was previously created with rpmsg_create_ept().
::
int register_rpmsg_driver(struct rpmsg_driver *rpdrv);
registers an rpmsg driver with the rpmsg bus. user should provide
a pointer to an rpmsg_driver struct, which contains the driver's
->probe() and ->remove() functions, an rx callback, and an id_table
specifying the names of the channels this driver is interested to
be probed with.
::
void unregister_rpmsg_driver(struct rpmsg_driver *rpdrv);
unregisters an rpmsg driver from the rpmsg bus. user should provide
a pointer to a previously-registered rpmsg_driver struct.
Returns 0 on success, and an appropriate error value on failure.
Typical usage
=============
The following is a simple rpmsg driver, that sends an "hello!" message
on probe(), and whenever it receives an incoming message, it dumps its
content to the console.
::
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/rpmsg.h>
static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len,
void *priv, u32 src)
{
print_hex_dump(KERN_INFO, "incoming message:", DUMP_PREFIX_NONE,
16, 1, data, len, true);
}
static int rpmsg_sample_probe(struct rpmsg_channel *rpdev)
{
int err;
dev_info(&rpdev->dev, "chnl: 0x%x -> 0x%x\n", rpdev->src, rpdev->dst);
/* send a message on our channel */
err = rpmsg_send(rpdev->ept, "hello!", 6);
if (err) {
pr_err("rpmsg_send failed: %d\n", err);
return err;
}
return 0;
}
static void rpmsg_sample_remove(struct rpmsg_channel *rpdev)
{
dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
}
static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
{ .name = "rpmsg-client-sample" },
{ },
};
MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
static struct rpmsg_driver rpmsg_sample_client = {
.drv.name = KBUILD_MODNAME,
.id_table = rpmsg_driver_sample_id_table,
.probe = rpmsg_sample_probe,
.callback = rpmsg_sample_cb,
.remove = rpmsg_sample_remove,
};
module_rpmsg_driver(rpmsg_sample_client);
.. note::
a similar sample which can be built and loaded can be found
in samples/rpmsg/.
Allocations of rpmsg channels
=============================
At this point we only support dynamic allocations of rpmsg channels.
This is possible only with remote processors that have the VIRTIO_RPMSG_F_NS
virtio device feature set. This feature bit means that the remote
processor supports dynamic name service announcement messages.
When this feature is enabled, creation of rpmsg devices (i.e. channels)
is completely dynamic: the remote processor announces the existence of a
remote rpmsg service by sending a name service message (which contains
the name and rpmsg addr of the remote service, see struct rpmsg_ns_msg).
This message is then handled by the rpmsg bus, which in turn dynamically
creates and registers an rpmsg channel (which represents the remote service).
If/when a relevant rpmsg driver is registered, it will be immediately probed
by the bus, and can then start sending messages to the remote service.
The plan is also to add static creation of rpmsg channels via the virtio
config space, but it's not implemented yet.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
문서의 범위
1-9이 문서는 `rpmsg` 버스의 역할과 `rpmsg` 드라이버 작성 방법을 설명한다. 새 플랫폼에 `rpmsg` 지원을 추가하는 절차는 Documentation 디렉터리의 `remoteproc.txt`를 보라고 안내한다. 현재 트리에서 이 참조에 해당하는 문서는 `Documentation/staging/remoteproc.rst`이다.
rpmsg와 remoteproc 문서가 나누어 다루는 범위다.
============================================
Remote Processor Messaging (rpmsg) Framework
============================================
.. note::
This document describes the rpmsg bus and how to write rpmsg drivers.
To learn how to add rpmsg support for new platforms, check out remoteproc.txt
(also a resident of Documentation/).
AMP 구성과 rpmsg 채널 모델
10-63현대 SoC는 서로 다른 운영체제 인스턴스를 실행하는 이기종 원격 프로세서를 AMP(asymmetric multiprocessing) 구성으로 함께 사용하는 경우가 많다. 실시간 운영체제일 수도 있고 Linux일 수도 있다. OMAP4를 예로 들면 dual Cortex-A9은 SMP Linux를 실행하고, 두 Cortex-M3와 C64x+ DSP는 각각 별도의 RTOS 인스턴스를 실행한다.
AMP 원격 프로세서는 전용 DSP codec이나 multimedia hardware accelerator를 이용해 CPU 사용량이 큰 multimedia 작업을 주 application processor에서 넘겨받는다. 그 밖에도 지연에 민감한 sensor 제어, 임의의 hardware block 구동, main CPU가 idle인 동안의 background 작업에 쓸 수 있다.
원격 프로세서 사용자는 remote OMX component와 통신하는 multimedia framework 같은 userland application일 수도 있고, 원격 프로세서만 접근할 수 있는 hardware를 제어하거나 원격 프로세서를 대신해 kernel 관리 resource를 예약하는 kernel driver일 수도 있다.
`rpmsg`는 system에서 사용할 수 있는 원격 프로세서와 kernel driver가 통신하게 하는 virtio 기반 messaging bus다. 필요하다면 해당 driver가 적절한 user-space interface를 다시 노출할 수 있다.
userland에 rpmsg 통신을 노출하는 driver는 보안 경계를 주의해야 한다. 원격 프로세서와 accelerator는 system physical memory, GPIO bank, DMA controller, I2C bus, general-purpose timer, mailbox device, hardware spinlock 같은 민감한 자원에 직접 접근할 수 있다. 원격 RTOS의 모든 task가 그 프로세서에 공개된 memory와 device 전체에 접근할 수도 있다.
따라서 악의적이거나 결함이 있는 userland code가 원격 측 bug를 악용해 system을 장악할 위험을 줄이려면, userland가 message를 보낼 수 있는 rpmsg channel을 특정 channel로 제한하고 가능하면 message 내용에 행사할 수 있는 제어도 최소화해야 한다.
각 `rpmsg` device는 원격 프로세서와의 통신 channel이다. channel은 text name으로 식별하며 local, 즉 source rpmsg address와 remote, 즉 destination rpmsg address를 갖는다.
driver가 channel 수신을 시작하면 rx callback은 고유한 32-bit local rpmsg address에 연결된다. inbound message가 도착하면 rpmsg core는 message의 destination address를 기준으로 해당 driver를 찾아 payload와 함께 rx handler를 호출한다.
destination address가 수신 callback을 선택한다.
하나의 rpmsg device가 나타내는 통신 관계다.
Introduction
============
Modern SoCs typically employ heterogeneous remote processor devices in
asymmetric multiprocessing (AMP) configurations, which may be running
different instances of operating system, whether it's Linux or any other
flavor of real-time OS.
OMAP4, for example, has dual Cortex-A9, dual Cortex-M3 and a C64x+ DSP.
Typically, the dual cortex-A9 is running Linux in a SMP configuration,
and each of the other three cores (two M3 cores and a DSP) is running
its own instance of RTOS in an AMP configuration.
Typically AMP remote processors employ dedicated DSP codecs and multimedia
hardware accelerators, and therefore are often used to offload CPU-intensive
multimedia tasks from the main application processor.
These remote processors could also be used to control latency-sensitive
sensors, drive random hardware blocks, or just perform background tasks
while the main CPU is idling.
Users of those remote processors can either be userland apps (e.g. multimedia
frameworks talking with remote OMX components) or kernel drivers (controlling
hardware accessible only by the remote processor, reserving kernel-controlled
resources on behalf of the remote processor, etc..).
Rpmsg is a virtio-based messaging bus that allows kernel drivers to communicate
with remote processors available on the system. In turn, drivers could then
expose appropriate user space interfaces, if needed.
When writing a driver that exposes rpmsg communication to userland, please
keep in mind that remote processors might have direct access to the
system's physical memory and other sensitive hardware resources (e.g. on
OMAP4, remote cores and hardware accelerators may have direct access to the
physical memory, gpio banks, dma controllers, i2c bus, gptimers, mailbox
devices, hwspinlocks, etc..). Moreover, those remote processors might be
running RTOS where every task can access the entire memory/devices exposed
to the processor. To minimize the risks of rogue (or buggy) userland code
exploiting remote bugs, and by that taking over the system, it is often
desired to limit userland to specific rpmsg channels (see definition below)
it can send messages on, and if possible, minimize how much control
it has over the content of the messages.
Every rpmsg device is a communication channel with a remote processor (thus
rpmsg devices are called channels). Channels are identified by a textual name
and have a local ("source") rpmsg address, and remote ("destination") rpmsg
address.
When a driver starts listening on a channel, its rx callback is bound with
a unique rpmsg local address (a 32-bit integer). This way when inbound messages
arrive, the rpmsg core dispatches them to the appropriate driver according
to their destination address (this is done by invoking the driver's rx handler
with the payload of the inbound message).
차단 전송: rpmsg_send와 rpmsg_sendto
64-111`rpmsg_send(ept, data, len)`은 지정한 endpoint에서 원격 프로세서로 message를 보낸다. 호출자는 endpoint, 보낼 data, byte 단위 길이를 지정한다. message의 source address는 endpoint의 `src`, destination address는 parent channel의 `dst`로 설정된다.
사용 가능한 TX buffer가 없으면 원격 프로세서가 TX buffer를 소비하고 virtio used descriptor ring에 돌려놓을 때까지 기다린다. 대기는 최대 15초이며 timeout이면 `-ERESTARTSYS`를 반환한다. 현재는 process context에서만 호출할 수 있고, 성공하면 0, 실패하면 알맞은 error 값을 반환한다.
`rpmsg_sendto(ept, data, len, dst)`는 caller가 destination address를 명시한다. endpoint, data, byte 길이와 `dst`를 받고 endpoint channel이 속한 원격 프로세서로 보낸다. source는 endpoint의 `src`를 사용하지만 channel의 `dst`는 무시하고 caller가 준 `dst`를 사용한다.
`rpmsg_sendto()`도 TX buffer가 없으면 최대 15초 동안 기다리며 timeout 시 `-ERESTARTSYS`를 반환한다. process context 전용이라는 조건과 성공 시 0, 실패 시 error 값을 반환하는 규칙도 `rpmsg_send()`와 같다.
두 함수는 destination address 선택 방식만 다르다.
TX descriptor가 부족하면 used ring 반환을 기다린다.
User API
========
::
int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len);
sends a message across to the remote processor from the given endpoint.
The caller should specify the endpoint, the data it wants to send,
and its length (in bytes). The message will be sent on the specified
endpoint's channel, i.e. its source and destination address fields will be
respectively set to the endpoint's src address and its parent channel
dst addresses.
In case there are no TX buffers available, the function will block until
one becomes available (i.e. until the remote processor consumes
a tx buffer and puts it back on virtio's used descriptor ring),
or a timeout of 15 seconds elapses. When the latter happens,
-ERESTARTSYS is returned.
The function can only be called from a process context (for now).
Returns 0 on success and an appropriate error value on failure.
::
int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
sends a message across to the remote processor from a given endpoint,
to a destination address provided by the caller.
The caller should specify the endpoint, the data it wants to send,
its length (in bytes), and an explicit destination address.
The message will then be sent to the remote processor to which the
endpoints's channel belongs, using the endpoints's src address,
and the user-provided dst address (thus the channel's dst address
will be ignored).
In case there are no TX buffers available, the function will block until
one becomes available (i.e. until the remote processor consumes
a tx buffer and puts it back on virtio's used descriptor ring),
or a timeout of 15 seconds elapses. When the latter happens,
-ERESTARTSYS is returned.
The function can only be called from a process context (for now).
Returns 0 on success and an appropriate error value on failure.
비차단 전송: rpmsg_trysend와 rpmsg_trysendto
112-149`rpmsg_trysend(ept, data, len)`은 endpoint channel의 address를 이용해 원격 프로세서로 message를 보낸다. source는 endpoint의 `src`, destination은 parent channel의 `dst`가 된다.
`rpmsg_send()`와 달리 TX buffer가 없으면 기다리지 않고 즉시 `-ENOMEM`을 반환한다. 현재는 process context에서만 호출할 수 있으며, 성공 시 0, 실패 시 적절한 error 값을 반환한다.
`rpmsg_trysendto(ept, data, len, dst)`는 caller가 destination address를 제공하는 비차단 변형이다. endpoint가 속한 channel의 원격 프로세서로 보내며 source address는 channel의 source address, destination은 caller의 `dst`를 사용하므로 channel의 destination address는 무시한다.
`rpmsg_trysendto()` 역시 TX buffer가 없으면 `-ENOMEM`을 즉시 반환하고 process context에서만 호출할 수 있다. 성공 시 0, 실패 시 알맞은 error 값을 반환한다.
두 함수 모두 buffer를 기다리지 않는다.
::
int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len);
sends a message across to the remote processor from a given endpoint.
The caller should specify the endpoint, the data it wants to send,
and its length (in bytes). The message will be sent on the specified
endpoint's channel, i.e. its source and destination address fields will be
respectively set to the endpoint's src address and its parent channel
dst addresses.
In case there are no TX buffers available, the function will immediately
return -ENOMEM without waiting until one becomes available.
The function can only be called from a process context (for now).
Returns 0 on success and an appropriate error value on failure.
::
int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
sends a message across to the remote processor from a given endpoint,
to a destination address provided by the user.
The user should specify the channel, the data it wants to send,
its length (in bytes), and an explicit destination address.
The message will then be sent to the remote processor to which the
channel belongs, using the channel's src address, and the user-provided
dst address (thus the channel's dst address will be ignored).
In case there are no TX buffers available, the function will immediately
return -ENOMEM without waiting until one becomes available.
The function can only be called from a process context (for now).
Returns 0 on success and an appropriate error value on failure.
endpoint 생성과 callback 결합
150-187system의 각 rpmsg address는 inbound message를 적절한 handler로 전달할 수 있도록 `struct rpmsg_endpoint`를 통해 rx callback에 연결된다. `rpmsg_create_ept(rpdev, cb, priv, chinfo)`는 새 endpoint를 만들고 rpmsg address에 callback과 선택적인 private data를 결합한다. address는 미리 알려진 값일 수도 있고 동적으로 배정할 수도 있다.
단순한 rpmsg driver는 `rpmsg_create_ept()`를 직접 호출할 필요가 없다. rpmsg bus가 driver를 probe할 때 driver 등록 시 제공한 rx callback으로 endpoint를 이미 생성한다.
따라서 단순 driver에는 endpoint와 address에 연결된 rx callback이 준비되어 있다. inbound message의 destination address가 rpmsg channel의 source address와 같으면 driver handler가 호출되어 message를 처리한다.
복잡한 driver는 여러 rpmsg address를 추가로 할당하고 각각 다른 rx callback에 연결할 수 있다. 이때 같은 원격 프로세서에 연결하도록 channel, rx callback, callback 호출 때 되돌려 받을 선택적 private data, 결합할 address를 제공해 `rpmsg_create_ept()`를 호출한다.
address가 `RPMSG_ADDR_ANY`이면 사용할 수 있는 rpmsg address를 동적으로 배정한다. 문서는 특별히 강한 이유가 없다면 항상 `RPMSG_ADDR_ANY`를 사용하라고 권한다. 성공하면 endpoint pointer, 실패하면 `NULL`을 반환한다.
단순 driver는 자동 endpoint를 쓰고 복합 driver만 추가 endpoint를 만든다.
새 endpoint가 어떤 관계를 결합하는지 보여 준다.
::
struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
rpmsg_rx_cb_t cb, void *priv,
struct rpmsg_channel_info chinfo);
every rpmsg address in the system is bound to an rx callback (so when
inbound messages arrive, they are dispatched by the rpmsg bus using the
appropriate callback handler) by means of an rpmsg_endpoint struct.
This function allows drivers to create such an endpoint, and by that,
bind a callback, and possibly some private data too, to an rpmsg address
(either one that is known in advance, or one that will be dynamically
assigned for them).
Simple rpmsg drivers need not call rpmsg_create_ept, because an endpoint
is already created for them when they are probed by the rpmsg bus
(using the rx callback they provide when they registered to the rpmsg bus).
So things should just work for simple drivers: they already have an
endpoint, their rx callback is bound to their rpmsg address, and when
relevant inbound messages arrive (i.e. messages which their dst address
equals to the src address of their rpmsg channel), the driver's handler
is invoked to process it.
That said, more complicated drivers might do need to allocate
additional rpmsg addresses, and bind them to different rx callbacks.
To accomplish that, those drivers need to call this function.
Drivers should provide their channel (so the new endpoint would bind
to the same remote processor their channel belongs to), an rx callback
function, an optional private data (which is provided back when the
rx callback is invoked), and an address they want to bind with the
callback. If addr is RPMSG_ADDR_ANY, then rpmsg_create_ept will
dynamically assign them an available rpmsg address (drivers should have
a very good reason why not to always use RPMSG_ADDR_ANY here).
Returns a pointer to the endpoint on success, or NULL on error.
endpoint 파기와 driver 등록
188-215`rpmsg_destroy_ept(ept)`는 기존 endpoint를 파기한다. 호출자는 앞서 `rpmsg_create_ept()`로 만든 endpoint의 pointer를 전달해야 한다.
`register_rpmsg_driver(rpdrv)`는 `struct rpmsg_driver`를 rpmsg bus에 등록한다. 구조체에는 driver의 `probe()`와 `remove()` 함수, rx callback, 그리고 이 driver가 probe되기를 원하는 channel name을 나열하는 `id_table`이 들어 있다.
`unregister_rpmsg_driver(rpdrv)`는 이전에 등록한 rpmsg driver를 bus에서 해제한다. 원문 prototype은 반환형을 `void`로 선언하지만 뒤 문장은 성공 시 0, 실패 시 적절한 error 값을 반환한다고 적고 있다. 페이지는 이 원문 불일치를 그대로 보존하며 실제 사용 시 현재 header의 prototype을 기준으로 해야 한다.
endpoint와 driver는 서로 다른 단위로 관리한다.
::
void rpmsg_destroy_ept(struct rpmsg_endpoint *ept);
destroys an existing rpmsg endpoint. user should provide a pointer
to an rpmsg endpoint that was previously created with rpmsg_create_ept().
::
int register_rpmsg_driver(struct rpmsg_driver *rpdrv);
registers an rpmsg driver with the rpmsg bus. user should provide
a pointer to an rpmsg_driver struct, which contains the driver's
->probe() and ->remove() functions, an rx callback, and an id_table
specifying the names of the channels this driver is interested to
be probed with.
::
void unregister_rpmsg_driver(struct rpmsg_driver *rpdrv);
unregisters an rpmsg driver from the rpmsg bus. user should provide
a pointer to a previously-registered rpmsg_driver struct.
Returns 0 on success, and an appropriate error value on failure.
간단한 rpmsg client driver 예제
216-278예제 driver는 `probe()`에서 `"hello!"` message를 보내고 inbound message를 받을 때마다 내용을 console에 hex dump한다. 필요한 header는 `<linux/kernel.h>`, `<linux/module.h>`, `<linux/rpmsg.h>`다.
`rpmsg_sample_cb()`는 callback으로 받은 `data`와 `len`을 `print_hex_dump()`에 넘긴다. `rpmsg_sample_probe()`는 channel의 source와 destination address를 기록한 다음 `rpmsg_send(rpdev->ept, "hello!", 6)`을 호출한다. 전송이 실패하면 error를 기록하고 해당 error를 반환하며, 성공하면 0을 반환한다.
`rpmsg_sample_remove()`는 client driver 제거 사실을 기록한다. `rpmsg_driver_sample_id_table`은 `rpmsg-client-sample` channel name과 일치하며 `MODULE_DEVICE_TABLE(rpmsg, ...)`로 공개된다.
`rpmsg_sample_client`는 module name, id table, probe callback, receive callback, remove callback을 묶는다. `module_rpmsg_driver(rpmsg_sample_client)`가 module의 등록과 해제 boilerplate를 제공한다.
실제로 build하고 load할 수 있는 유사 예제는 `samples/rpmsg/`에 있다.
sample client의 callback과 등록 정보를 정리한다.
channel match부터 message 송수신까지의 흐름이다.
Typical usage
=============
The following is a simple rpmsg driver, that sends an "hello!" message
on probe(), and whenever it receives an incoming message, it dumps its
content to the console.
::
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/rpmsg.h>
static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len,
void *priv, u32 src)
{
print_hex_dump(KERN_INFO, "incoming message:", DUMP_PREFIX_NONE,
16, 1, data, len, true);
}
static int rpmsg_sample_probe(struct rpmsg_channel *rpdev)
{
int err;
dev_info(&rpdev->dev, "chnl: 0x%x -> 0x%x\n", rpdev->src, rpdev->dst);
/* send a message on our channel */
err = rpmsg_send(rpdev->ept, "hello!", 6);
if (err) {
pr_err("rpmsg_send failed: %d\n", err);
return err;
}
return 0;
}
static void rpmsg_sample_remove(struct rpmsg_channel *rpdev)
{
dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
}
static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
{ .name = "rpmsg-client-sample" },
{ },
};
MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
static struct rpmsg_driver rpmsg_sample_client = {
.drv.name = KBUILD_MODNAME,
.id_table = rpmsg_driver_sample_id_table,
.probe = rpmsg_sample_probe,
.callback = rpmsg_sample_cb,
.remove = rpmsg_sample_remove,
};
module_rpmsg_driver(rpmsg_sample_client);
.. note::
a similar sample which can be built and loaded can be found
in samples/rpmsg/.
rpmsg channel의 동적 할당
279-299현재 지원하는 rpmsg channel 할당 방식은 동적 할당뿐이다. 이를 사용하려면 원격 프로세서가 virtio device feature `VIRTIO_RPMSG_F_NS`를 설정해야 하며, 이 bit는 동적 name-service announcement message를 지원한다는 뜻이다.
feature가 활성화되면 rpmsg device, 즉 channel 생성은 완전히 동적으로 이루어진다. 원격 프로세서는 remote rpmsg service의 name과 rpmsg address를 담은 name-service message인 `struct rpmsg_ns_msg`를 보내 service의 존재를 알린다.
rpmsg bus는 이 message를 처리해 remote service를 나타내는 rpmsg channel을 동적으로 생성하고 등록한다. 일치하는 rpmsg driver가 이미 등록되어 있거나 나중에 등록되면 bus가 즉시 probe하고, driver는 remote service로 message를 보낼 수 있다.
virtio config space를 통한 rpmsg channel의 정적 생성도 계획되어 있지만 아직 구현되지 않았다.
원격 name-service announcement가 Linux device와 driver probe를 만든다.
문서가 설명하는 현재와 계획 상태다.
Allocations of rpmsg channels
=============================
At this point we only support dynamic allocations of rpmsg channels.
This is possible only with remote processors that have the VIRTIO_RPMSG_F_NS
virtio device feature set. This feature bit means that the remote
processor supports dynamic name service announcement messages.
When this feature is enabled, creation of rpmsg devices (i.e. channels)
is completely dynamic: the remote processor announces the existence of a
remote rpmsg service by sending a name service message (which contains
the name and rpmsg addr of the remote service, see struct rpmsg_ns_msg).
This message is then handled by the rpmsg bus, which in turn dynamically
creates and registers an rpmsg channel (which represents the remote service).
If/when a relevant rpmsg driver is registered, it will be immediately probed
by the bus, and can then start sending messages to the remote service.
The plan is also to add static creation of rpmsg channels via the virtio
config space, but it's not implemented yet.
요약·해설
rpmsg.rst:1-299virtio 기반 rpmsg bus의 channel·address 모델, 차단·비차단 전송 API, endpoint와 driver 수명 주기, sample client, name-service 기반 동적 channel 할당을 설명합니다.