diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-05-05 23:13:42 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-05-05 23:13:42 +0300 |
| commit | 1a2ff9a1e5b91b7e307246ed2f4b898f1e179806 (patch) | |
| tree | 6da407851e3b01fadd1ffba64fbdffce71dab68a /include | |
| parent | 79f67d5ca820b663e9e5682aaaad07118fdbfad8 (diff) | |
| download | gran-1a2ff9a1e5b91b7e307246ed2f4b898f1e179806.tar.gz gran-1a2ff9a1e5b91b7e307246ed2f4b898f1e179806.zip | |
add async packets
Diffstat (limited to 'include')
| -rw-r--r-- | include/gran/component.h | 68 | ||||
| -rw-r--r-- | include/gran/mem/simple_mem.h | 1 | ||||
| -rw-r--r-- | include/gran/packet.h | 38 | ||||
| -rw-r--r-- | include/gran/snoop.h | 20 |
4 files changed, 91 insertions, 36 deletions
diff --git a/include/gran/component.h b/include/gran/component.h index 15dc875..4ef94ad 100644 --- a/include/gran/component.h +++ b/include/gran/component.h @@ -6,20 +6,25 @@ #include <stdint.h> #include <stdio.h> +#include <assert.h> #include <stdlib.h> #include <inttypes.h> #include <gran/common.h> +#include <gran/packet.h> +#include <gran/snoop.h> struct component; -typedef stat (*write_callback)(struct component *, uintptr_t, size_t, void *); -typedef stat (*read_callback)(struct component *, uintptr_t, size_t, void *); -typedef stat (*swap_callback)(struct component *, uintptr_t, size_t, void *, - size_t, void *); +typedef stat (*read_callback)(struct component *, struct packet *pkt); +typedef stat (*write_callback)(struct component *, struct packet *pkt); +typedef stat (*swap_callback)(struct component *, struct packet *pkt); + +typedef stat (*snoop_callback)(struct component *, struct snoop *snoop); +typedef stat (*ctrl_callback)(struct component *, struct packet *pkt); + typedef stat (*irq_callback)(struct component *, int); typedef stat (*clock_callback)(struct component *); - typedef stat (*stat_callback)(struct component *, FILE *); typedef stat (*dts_callback)(struct component *, FILE *); @@ -29,10 +34,13 @@ struct component { /* optional */ char *name; - write_callback write; read_callback read; + write_callback write; swap_callback swap; + snoop_callback snoop; + ctrl_callback ctrl; + irq_callback irq; clock_callback clock; @@ -42,69 +50,57 @@ struct component { destroy_callback destroy; }; -static inline stat write(struct component *component, uintptr_t addr, - size_t size, void *buf) +static inline stat write(struct component *component, struct packet *pkt) { + assert(packet_type(pkt) == PACKET_WRITE); if (!component->write) { + /* printf formatted asserts would maybe be preferable? */ error( "tried writing %p:%" PRIuPTR " but it doesn't support writing", - component->name, addr); + component->name, packet_addr(pkt)); return ENOSUCH; } - return component->write(component, addr, size, buf); + packet_set_state(pkt, PACKET_SENT); + return component->write(component, pkt); } -static inline stat read(struct component *component, uintptr_t addr, - size_t size, void *buf) +static inline stat read(struct component *component, struct packet *pkt) { + assert(packet_type(pkt) == PACKET_READ); if (!component->read) { error( "tried reading %p:%" PRIuPTR " but it doesn't support reading", - component->name, addr); + component->name, packet_addr(pkt)); return ENOSUCH; } - return component->read(component, addr, size, buf); + packet_set_state(pkt, PACKET_SENT); + return component->read(component, pkt); } -static inline stat swap(struct component *component, uintptr_t addr, - size_t wsize, void *wbuf, size_t rsize, void *rbuf) +static inline stat swap(struct component *component, struct packet *pkt) { + assert(packet_type(pkt) == PACKET_SWAP); if (!component->swap) { error( "tried swapping %p:%" PRIuPTR " but it doesn't support swapping", - component->name, addr); + component->name, packet_addr(pkt)); return ENOSUCH; } - return component->swap(component, addr, wsize, wbuf, rsize, rbuf); + packet_set_state(pkt, PACKET_SENT); + return component->swap(component, pkt); } static inline void destroy(struct component *component) { + free(component->name); + if (component->destroy) component->destroy(component); else free(component); } -static inline stat write_u8(struct component *component, uintptr_t addr, - uint8_t c) -{ - return write(component, addr, sizeof(uint8_t), &c); -} - -static inline stat read_u8(struct component *component, uintptr_t addr, - uint8_t *c) -{ - return read(component, addr, sizeof(uint8_t), c); -} - -static inline stat swap_u8(struct component *component, uintptr_t addr, - uint8_t *c) -{ - return swap(component, addr, sizeof(uint8_t), c, sizeof(uint8_t), c); -} - #endif /* GRAN_COMPONENT_H */ diff --git a/include/gran/mem/simple_mem.h b/include/gran/mem/simple_mem.h index 8d6ce75..23bcacb 100644 --- a/include/gran/mem/simple_mem.h +++ b/include/gran/mem/simple_mem.h @@ -7,5 +7,6 @@ #include <gran/component.h> struct component *create_simple_mem(size_t size); +void init_simple_mem(struct component *mem, uintptr_t addr, size_t size, void *data); #endif /* GRAN_SIMPLE_MEM_H */ diff --git a/include/gran/packet.h b/include/gran/packet.h new file mode 100644 index 0000000..3c9dda9 --- /dev/null +++ b/include/gran/packet.h @@ -0,0 +1,38 @@ +#ifndef GRAN_PACKET_H +#define GRAN_PACKET_H + +#include <stdint.h> +#include <stddef.h> + +enum packet_state { + PACKET_INIT, + PACKET_FAILED, + PACKET_SENT, + PACKET_WAITING, + PACKET_DONE, +}; + +enum packet_type { + PACKET_READ, + PACKET_WRITE, + PACKET_SWAP, + PACKET_SNOOP, + PACKET_CTRL, +}; + +struct packet; + +struct packet *create_packet(enum packet_type type, uintptr_t addr, size_t size); +struct packet *create_packet_with(enum packet_type type, uintptr_t addr, size_t size, void *data); + +enum packet_type packet_type(struct packet *pkt); +enum packet_state packet_state(struct packet *pkt); +void packet_set_state(struct packet *pkt, enum packet_state state); + +size_t packet_size(struct packet *pkt); +uintptr_t packet_addr(struct packet *pkt); +void *packet_data(struct packet *pkt); + +void destroy_packet(struct packet *pkt); + +#endif /* GRAN_PACKET_H */ diff --git a/include/gran/snoop.h b/include/gran/snoop.h new file mode 100644 index 0000000..39c0e33 --- /dev/null +++ b/include/gran/snoop.h @@ -0,0 +1,20 @@ +#ifndef GRAN_SNOOP_H +#define GRAN_SNOOP_H + +#include <stdint.h> + +enum snoop_state { + SNOOP_UNANSWERED, + SNOOP_ANSWERED, +}; + +struct snoop; + +struct snoop *create_snoop(uintptr_t addr, size_t size); +void destroy_snoop(struct snoop *snoop); + +enum snoop_state snoop_state(struct snoop *snoop); +uintptr_t snoop_addr(struct snoop *snoop); +size_t snoop_size(struct snoop *snoop); + +#endif /* GRAN_SNOOP_H */ |
