1/* @ajax/mesh-abi-pipe-table: The pipe block (PP_*): a slot's inbox, connected feeds and pushes in flight.
2 *
3 * Part of alpha-c-mesh, a C port of alpha-rust-mesh (README.md says from where). */
4#ifndef MESH_ABI_PIPE_TABLE_H
5#define MESH_ABI_PIPE_TABLE_H
67#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10#include "mesh/abi/base.h"
11#include "mesh/abi/fields.h"
1213/* ---------------------------------------------------------------- views */
14/* ---------------------------------------------------------------- pipes */
15/* The view heap: meshd allocates each program's view as whole pages,
16 * first fit; a view keeps its offset across an upgrade when view_abi and
17 * view_bytes are unchanged.
18 * Per slot, PP_BYTES at `pipe_entry(s)`: its inbox (manifest `inbox`,
19 * `inbox_type`) and the pipes meshd connected (manifest `feeds`; v2::pipe).
20 * Host-written with the table entry, under the slot's PT_GEN seqlock; a
21 * runtime reads it at every push/pop (feeds connect and disconnect while
22 * programs run: no relaunch). */
23#define MESH_PIPE_TABLE 0x4A000
24#define MESH_PP_BYTES 0x40
25#define MESH_PP_IN_OFF 0x00 /* u32 the inbox's offset in the slot's view */
26#define MESH_PP_IN_CAP 0x04 /* u32 records (a power of two); 0: no inbox */
27#define MESH_PP_IN_REC 0x08 /* u32 bytes a record (a multiple of 4) */
28#define MESH_PP_IN_TYPE 0x0c /* u32 pipe::type_hash of inbox_type */
29#define MESH_PP_FEEDS_MASK 0x10 /* u32 bit c: this slot may push into slot c's inbox (connected) */
30#define MESH_PP_FED_MASK 0x14 /* u32 bit p: slot p's pushes into this inbox are connected */
31/* u32 host: nonzero while meshd rewrites this inbox in place (a reset):
32 * pushes answer "full" (pipe::PipeErr::Busy). Under PT_GEN like the rest. */
33#define MESH_PP_IN_HOLD 0x18
34/* u32 x 2: this slot's pushes in progress, any inbox, counted in the word of
35 * parity H_PIPE_EPOCH & 1 (pipe::flight_begin/end; `flight_word`):
36 * read-modify-written by the slot's own executor only; meshd reads them, and
37 * zeroes them only once the slot runs no code. Not part of the block meshd
38 * rewrites (`write_pipe` leaves them). */
39#define MESH_PP_FLIGHT 0x1c
40#define MESH_PP_FLIGHT1 0x30
41#define MESH_PP_TYPE_NAME 0x20 /* [u8; NAME_BYTES] inbox_type, NUL padded */
42#define MESH_PIPE_FIELDS_LEN 10
43extern const mesh_field MESH_PIPE_FIELDS[10];
4445/* Slot s's pipe block. */
46static inline size_t mesh_pipe_entry(uint32_t slot) { return MESH_PIPE_TABLE + MESH_PP_BYTES * (size_t)slot; }
47/* Slot s's flight word of parity `parity` (0 or 1). */
48static inline size_t mesh_flight_word(uint32_t s, uint32_t parity) {
49 return mesh_pipe_entry(s) + ((parity & 1u) == 0 ? MESH_PP_FLIGHT : MESH_PP_FLIGHT1);
50}
5152#endif