<alp/rpc.h> — Framed RPC over OpenAMP/RPMsg
The customer-facing IPC API on heterogeneous SoMs. <alp/rpc.h> is the only header app code needs to talk between an A-cluster Yocto half and an M-class Zephyr half declared in one board.yaml. It sits on top of <alp/mproc.h> (mailbox + shared memory + hardware semaphore) and the build-time-generated <alp/system_ipc.h> macros emitted by the orchestrator (scripts/alp_orchestrate/).
Landed in v0.6. Surface is
[ABI-STABLE]— adding optional fields toalp_rpc_config_tis permitted; reshaping callback signatures is not.
When to use this header
| Want to… | Use this |
|---|---|
| Talk between two cores running different OSes | <alp/rpc.h> (this page) |
| Raw mailbox + shared memory + semaphore primitives | <alp/mproc.h> |
| Send packets over Ethernet / Wi-Fi to a peer | <alp/iot.h> |
If you find yourself typing endpoint IDs, carve-out addresses, or mailbox channel numbers by hand, stop — they belong in board.yaml's ipc: block and the generated <alp/system_ipc.h>, not app code.
On-wire framing
Every RPMsg payload carries a tiny ASCII method header followed by an opaque application-defined byte string:
+-----------------+-----------------------------------+
| <method>\0 | application payload (verbatim) |
| 1..32 bytes | 0..N bytes |
+-----------------+-----------------------------------+
- Method names match the regex
[A-Za-z0-9_.-]+and are ≤ 32 bytes including the NUL terminator. - The payload is passed through verbatim to the callback — the SDK does not parse it.
- As of alp-sdk v0.17.0 the framing is still the ASCII method header. A length-prefixed binary / nanopb framing is an unscheduled possible upgrade that would reuse the same public API. Both ends of a channel must agree on the framing format.
Backends
| Side | Backend |
|---|---|
| Zephyr / M-class | subsys/ipc/ipc_service with the rpmsg backend (src/backends/rpc/zephyr_drv.c). |
| Linux / A-class | libmetal + librpmsg user-space chardev access to /dev/rpmsg* (src/backends/rpc/yocto_drv.c). |
| Linux / A-class, UIO | Userspace OpenAMP / libmetal over UIO, on SoCs without the mainline rpmsg_char glue (src/backends/rpc/yocto_uio_drv.c). This is the backend that wins on every RZ/V2N silicon ref. |
| Bare-metal / trimmed image | NOSUPPORT stub (call returns NULL with ALP_ERR_NOSUPPORT). native_sim without a real OpenAMP transport gets a software fallback instead. |
Constants
#define ALP_RPC_METHOD_MAX_LEN 32 /* incl. trailing NUL — on-wire limit */
#define ALP_RPC_DEFAULT_MBOX_CH 0u /* used when alp_rpc_config_t.mbox_ch == 0 */
Types
alp_rpc_channel_t
Opaque RPC channel handle. Allocate via alp_rpc_open(), release via alp_rpc_close(). All API entry points except alp_rpc_open take the handle as their first argument.
alp_rpc_config_t
typedef struct {
const char *name; /* matches ALP_IPC_<NAME>_NAME from <alp/system_ipc.h> */
uint32_t src_ept; /* this side; 0 → FNV-1a hash of name */
uint32_t dst_ept; /* peer side; 0 → src_ept + 1 */
uint32_t mbox_ch; /* defaults to ALP_RPC_DEFAULT_MBOX_CH (0) */
} alp_rpc_config_t;
Every member except name is optional. Pass a designated-initialiser literal directly to alp_rpc_open() for terse use.
cacheable removed in v0.17.0The bool cacheable member is gone — code that sets .cacheable no longer compiles. The RPMsg carve-out is non-cacheable by design and the SDK performs no cache flush or invalidate. For board.yaml ipc: endpoints the generator emits CONFIG_DCACHE=n for every endpoint core; hand-written firmware must map the carve-out non-cacheable in the MPU. There is no per-channel cache setting.
Callback signatures
typedef void (*alp_rpc_msg_cb_t)(const char *method,
const void *payload, size_t len,
void *user);
typedef void (*alp_rpc_method_cb_t)(const void *payload, size_t len,
void *user);
The typed method_cb_t is filtered by alp_rpc_subscribe() so callbacks don't need to re-check the method name.
Callbacks run on the backend's RX worker (Zephyr
ipc_servicecallback thread; Linux per-channel poll thread inside librpmsg). Keep the body short — the worker is shared with every other subscribe on this channel.
Lifecycle
alp_rpc_open()
alp_rpc_channel_t *alp_rpc_open(const alp_rpc_config_t *cfg);
Resolves the carve-out memory region declared in <alp/system_ipc.h>, brings up the OpenAMP virtio queues, and registers the local endpoint. The peer must have called alp_rpc_open() with matching name / src_ept / dst_ept; the resolver retries the name-service handshake transparently for up to 2 s (Zephyr) or 5 s (Linux) before returning NULL.
alp_last_error() value | Cause |
|---|---|
ALP_ERR_INVAL | cfg / name NULL, or method-name too long. |
ALP_ERR_NOMEM | Channel pool exhausted. |
ALP_ERR_NOT_READY | RPMsg device or memory region not yet up (peer hasn't booted), or (Linux UIO) no CM33 beacon. |
ALP_ERR_BUSY | Linux UIO: the CM33 is still attached to an earlier session and cannot reset, or another process holds the link; also a second concurrent open of the single link. |
ALP_ERR_TIMEOUT | Linux UIO: the CM33 did not acknowledge the attach reset. |
ALP_ERR_NOSUPPORT | SDK built without CONFIG_ALP_SDK_RPC / no OpenAMP backend, or (Linux UIO) the CM33 image serves no RPC. |
alp_rpc_close()
void alp_rpc_close(alp_rpc_channel_t *ch);
Drops every subscription, deregisters the local endpoint, releases the handle back to the pool. Outstanding alp_rpc_call() invocations return ALP_ERR_NOT_READY before unblocking. NULL handle is a no-op.
Concurrent-close contract
v0.10 redesigned the close protocol to be deadlock-free (GHSA-xhm8-7f87-93q5). The resulting contract mirrors POSIX's close(2) vs read(2):
Supported and race-free — calling alp_rpc_close() concurrently from two threads on the same still-open channel, including a subscriber callback or a link-state callback closing its own channel from inside the callback while another thread closes it too. Exactly one caller performs the teardown, the other is a safe no-op; neither blocks, crashes, nor double-frees.
Not supported — racing a close against an alp_rpc_subscribe / alp_rpc_unsubscribe / alp_rpc_send / alp_rpc_call that has not yet started when the close is first called. Once any alp_rpc_close() on a handle has completed, no thread may still be initiating a new op on that handle. You own that ordering, exactly as POSIX requires you to ensure no thread starts a fresh read(2) on an fd another thread has closed.
Every op already in flight when a close begins is still handled correctly — it either completes or unblocks with ALP_ERR_NOT_READY, per that op's own contract. Only a fresh op racing to start after a close has finished is unsupported.
Calling alp_rpc_close() a second time on a handle that has already completed a full close is a use-after-close bug in your code — not a no-op. The slot may since have been reused by an unrelated alp_rpc_open(), and ch is a raw pointer carrying no generation across calls, so the SDK cannot detect the reuse. (A generation counter would close that residual window, but needs a fatter handle — an ABI break — so it is out of scope pre-v1.0.) NULL is still a safe no-op.
Subscriptions
alp_rpc_subscribe()
alp_status_t alp_rpc_subscribe(alp_rpc_channel_t *ch,
const char *method,
alp_rpc_method_cb_t cb,
void *user);
Registers cb for frames whose method matches. Replaces any prior registration for the same (ch, method) pair. Passing cb == NULL is equivalent to alp_rpc_unsubscribe().
Per-channel subscribe table cap in v0.6: 8 entries.
alp_rpc_unsubscribe()
alp_status_t alp_rpc_unsubscribe(alp_rpc_channel_t *ch, const char *method);
Waits for an in-flight callback of that method to return (except when called from that callback itself), so you may free the callback's user pointer afterwards. A callback must therefore not block on anything the unsubscribing thread holds.
Link liveness
New in v0.17.0. A far-core reset or crash used to be invisible: alp_rpc_send() kept returning ALP_OK into a dead vring. Each channel now tracks the RPMsg peer-bind state.
typedef enum {
ALP_RPC_LINK_DOWN = 0, /* not yet bound to the peer */
ALP_RPC_LINK_UP = 1, /* peer endpoint bound; traffic flows */
ALP_RPC_LINK_LOST = 2, /* peer went away after being UP */
} alp_rpc_link_state_t;
typedef void (*alp_rpc_link_cb_t)(alp_rpc_link_state_t state, void *user);
alp_status_t alp_rpc_set_link_callback(alp_rpc_channel_t *ch, alp_rpc_link_cb_t cb, void *user);
alp_status_t alp_rpc_link_state(alp_rpc_channel_t *ch, alp_rpc_link_state_t *out_state);
Every channel starts DOWN and moves to UP when the backend's bind signal fires. LOST is reachable only from UP — a link that never bound stays DOWN.
alp_rpc_set_link_callback()replaces any prior registration (cb == NULLclears it). It does not fire with the current state — callalp_rpc_link_state()first if that matters. Register once, right afteralp_rpc_open(); concurrent registrations on the same channel race. ReturnsALP_ERR_NOT_READYfor aNULL/ closed channel andALP_ERR_NOSUPPORTon the bare-metal stub.alp_rpc_link_state()reads the last-observed state; same errors, plusALP_ERR_INVALfor aNULLout_state.- The callback runs on the backend's transport context (usually an RX worker thread, not yours). Keep it short and non-blocking. Closing this same channel from inside it is supported; closing a different channel from inside it is not.
Once a channel has observed ALP_RPC_LINK_LOST, alp_rpc_send() and any new alp_rpc_call() fail with ALP_ERR_NOT_READY instead of queueing into the dead link. A call already in flight is not woken early — it runs out its own timeout_ms.
LINK_LOST is not observable on every backend yet| Backend | UP | LOST |
|---|---|---|
Linux chardev (yocto_drv.c) | Yes (chardev open) | Yes (RX thread poll() / read() failure) |
Zephyr (zephyr_drv.c) | Yes (ipc_service bound callback) | No — the pinned Zephyr v4.4.1 RPMsg static-vrings backend never invokes the unbound / error callbacks, so a far-core reset stays reported as UP. |
RZ/V2N UIO (yocto_uio_drv.c) | Yes | No — not wired for link liveness yet. |
In this release, LINK_LOST is reliable only on a Linux A-class peer running the plain chardev backend — not on Zephyr, and not on V2N's own A55.
Send + call
alp_rpc_send() — fire-and-forget
alp_status_t alp_rpc_send(alp_rpc_channel_t *ch,
const char *method,
const void *payload, size_t len);
Frames the (method, payload) pair and hands it to the OpenAMP TX queue. Returns as soon as the queue accepts the frame; does not wait for the peer.
alp_rpc_call() — synchronous request/response
alp_status_t alp_rpc_call(alp_rpc_channel_t *ch,
const char *method,
const void *req, size_t req_len,
void *resp, size_t *resp_len,
uint32_t timeout_ms);
Sends (method, req, req_len), blocks until the peer replies with a frame whose method matches OR timeout_ms elapses. The peer replies on the same channel with the same method name; the SDK does not impose a method.reply convention — both sides agree per application.
resp / resp_len | Behaviour |
|---|---|
Both NULL | Caller doesn't care about the response body. |
resp != NULL | resp_len must be non-NULL; on entry holds capacity, on exit length. |
timeout_ms == UINT32_MAX | Unbounded wait. |
Concurrent calls on the same channel from multiple threads are serialised by the SDK; the second caller blocks until the first returns or times out.
Replies are matched by method name only — the frame has no sequence id. So after a call times out (or its wait fails), the channel refuses every later alp_rpc_call() with ALP_ERR_NOT_READY until you close and reopen it; otherwise the late reply would be handed to the next call of the same method.
On the UIO / OpenAMP backend, calling alp_rpc_call() from a subscribe callback returns ALP_ERR_BUSY instead of blocking, because that callback's thread is the one that delivers replies.
ALP_ERR_NOT_READY from alp_rpc_call() therefore means one of: NULL / closed channel, the link has already observed ALP_RPC_LINK_LOST (checked at entry), or an earlier call on this channel timed out.
Canonical usage
Producer (M33-SM / Zephyr)
#include <alp/rpc.h>
#include <alp/system_ipc.h> /* generated by tan build */
#include <zephyr/kernel.h>
int main(void) {
alp_rpc_channel_t *ch = alp_rpc_open(&(alp_rpc_config_t){
.name = ALP_IPC_ALP_DEFAULT_RPMSG_NAME,
.src_ept = ALP_IPC_ALP_DEFAULT_RPMSG_SRC_EPT,
.dst_ept = ALP_IPC_ALP_DEFAULT_RPMSG_DST_EPT,
.mbox_ch = ALP_IPC_ALP_DEFAULT_RPMSG_MBOX_CH,
});
if (!ch) return -1; /* alp_last_error() reports why */
while (1) {
float c = read_thermistor();
alp_rpc_send(ch, "temperature", &c, sizeof c);
k_msleep(1000);
}
}
Consumer (A55 / Yocto)
#include <alp/rpc.h>
#include <alp/system_ipc.h>
static void on_temperature(const void *payload, size_t len, void *u) {
(void)u;
float c;
if (len == sizeof c) {
memcpy(&c, payload, sizeof c);
printf("[a55] temperature=%.2f C\n", c);
}
}
int main(void) {
alp_rpc_channel_t *ch = alp_rpc_open(&(alp_rpc_config_t){
.name = ALP_IPC_ALP_DEFAULT_RPMSG_NAME,
.src_ept = ALP_IPC_ALP_DEFAULT_RPMSG_DST_EPT, /* swap src/dst */
.dst_ept = ALP_IPC_ALP_DEFAULT_RPMSG_SRC_EPT,
});
alp_rpc_subscribe(ch, "temperature", on_temperature, NULL);
for (;;) pause();
}
Both sides #include the same generated header. Producer's src_ept is consumer's dst_ept — that symmetry is the only piece a developer keeps straight.
Declaring the channel in board.yaml
ipc:
- kind: rpmsg
endpoints: [a55_cluster, m33_sm]
carve_out_kb: 512
name: alp_default_rpmsg
The orchestrator allocates the carve-out from the SoM preset's memory_map: and emits matching ALP_IPC_ALP_DEFAULT_RPMSG_* macros into <alp/system_ipc.h>. The carve-out is non-cacheable on every SoM and the generator emits CONFIG_DCACHE=n for the endpoint cores. The ipc: entry's cacheable: true override is rejected on rpmsg; it exists only as the raw_shmem opt-out for applications that do their own cache maintenance.
Default-initialiser macro
ALP_RPC_CONFIG_DEFAULT(id) (v0.10) takes the endpoint name as its identity argument:
alp_rpc_config_t cfg = ALP_RPC_CONFIG_DEFAULT("alp-rpc");
It sets name from id plus: src_ept = 0, dst_ept = 0, mbox_ch = ALP_RPC_DEFAULT_MBOX_CH.
See the shared macro contract for the C++ compound-literal caveat that applies to every ALP_*_CONFIG_DEFAULT.
See also
- Heterogeneous Builds — full project walkthrough
board.yamlreference —ipc:block schema<alp/mproc.h>— lower-level mailbox + shared memory primitivesrpmsg-v2n— V2N flagship example