RPMsg inter-partition messaging over shared memory
README.md

rpmsg #

Linux RPMsg endpoints for OCaml, for messaging between partitions.

A system-on-chip such as the Zynq UltraScale+ runs Linux beside real-time
cores or partitions, under a hypervisor such as Jailhouse or Xen. RPMsg
(Remote Processor Messaging) is how Linux exchanges messages with them: small
datagrams over virtio rings, exposed to user space as character devices. A
virtio ring is a circular queue of buffer descriptors in memory that both
sides share: one side posts buffers, the other consumes them and signals with
an interrupt, so the processors exchange messages with no device between
them.
rpmsg creates and destroys endpoints through the control device
(/dev/rpmsg_ctrlN), opens the endpoint devices (/dev/rpmsgN), and sends
and receives messages over Eio flows. RPMsg exists only on Linux; elsewhere
every control call raises Failure.

Installation #

Install with opam:

$ opam install rpmsg

If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install rpmsg

Usage #

Send and receive messages on an endpoint #

Open an endpoint beneath /dev and exchange messages:

let run () =
  Eio_main.run @@ fun env ->
  Eio.Switch.run @@ fun sw ->
  let ctrl = Rpmsg.Ctrl.open_ () in
  let idx =
    Rpmsg.Ctrl.create_endpoint ctrl ~name:"my-ep" ~src:1024 ~dst:1025
  in
  let dev = Eio.Path.(Eio.Stdenv.fs env / "/dev") in
  let ep = Rpmsg.Endpoint.open_ ~sw ~dev idx in
  Rpmsg.Endpoint.send ep "hello";
  (match Rpmsg.Endpoint.recv ep ~max_size:Rpmsg.Endpoint.max_message_size with
   | Some reply -> Fmt.pr "got: %s@." reply
   | None -> Fmt.pr "peer closed@.");
  Rpmsg.Endpoint.close ep;
  Rpmsg.Ctrl.destroy_endpoint ctrl ~name:"my-ep" ~src:1024 ~dst:1025;
  Rpmsg.Ctrl.close ctrl

Messages are at most 496 bytes (512 virtio buffer minus the 16-byte RPMsg
header); see Rpmsg.Endpoint.max_message_size.

Rpmsg.Ctrl.create_endpoint returns the index N of the new /dev/rpmsgN
device, which Rpmsg.Endpoint.open_ opens. Rpmsg.endpoint_info_codec encodes
the kernel's struct rpmsg_endpoint_info (a 32-byte name and two 32-bit
addresses, 40 bytes) with a Wire codec instead of hand-packed C.

References #

Licence #

ISC. See LICENSE.md.