libubox
C utility functions for OpenWrt.
udebug-proto.h
Go to the documentation of this file.
1 /*
2  * udebug - debug ring buffer library
3  *
4  * Copyright (C) 2023 Felix Fietkau <nbd@nbd.name>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 #ifndef __UDEBUG_PROTO_H
19 #define __UDEBUG_PROTO_H
20 
21 #include "udebug.h"
22 
23 struct udebug_hdr {
24  uint32_t ring_size;
25  uint32_t data_size;
26 
27  uint32_t format;
28  uint32_t sub_format;
29 
30  uintptr_t flags[8 / sizeof(uintptr_t)];
31  uintptr_t notify;
32 
33  uint32_t head_hi;
34  uint32_t head;
35  uint32_t data_head;
36  uint32_t data_used;
37 };
38 
46 };
47 
49  uint8_t type;
50  uint8_t _pad[3];
51  uint32_t id;
52  union {
53  struct {
54  uint32_t ring_size, data_size;
55  };
56  uint32_t notify_mask;
57  };
58 } __attribute__((packed, aligned(4)));
59 
60 static inline struct udebug_ptr *
61 udebug_ring_ptr(struct udebug_hdr *hdr, uint32_t idx)
62 {
63  struct udebug_ptr *ring = (struct udebug_ptr *)&hdr[1];
64  return &ring[idx & (hdr->ring_size - 1)];
65 }
66 
67 static inline void *udebug_buf_ptr(struct udebug_buf *buf, uint32_t ofs)
68 {
69  return buf->data + (ofs & (buf->data_size - 1));
70 }
71 
72 #endif
void * data
Definition: udebug.h:79
size_t data_size
Definition: udebug.h:80
uint32_t ring_size
Definition: udebug-proto.h:54
uint32_t notify_mask
Definition: udebug-proto.h:56
uint8_t _pad[3]
Definition: udebug-proto.h:50
uint32_t data_size
Definition: udebug-proto.h:54
uintptr_t notify
Definition: udebug-proto.h:31
uint32_t head_hi
Definition: udebug-proto.h:33
uint32_t ring_size
Definition: udebug-proto.h:24
uintptr_t flags[8/sizeof(uintptr_t)]
Definition: udebug-proto.h:30
uint32_t data_head
Definition: udebug-proto.h:35
uint32_t data_used
Definition: udebug-proto.h:36
uint32_t sub_format
Definition: udebug-proto.h:28
uint32_t format
Definition: udebug-proto.h:27
uint32_t data_size
Definition: udebug-proto.h:25
uint32_t head
Definition: udebug-proto.h:34
udebug_client_msg_type
Definition: udebug-proto.h:39
@ CL_MSG_RING_ADD
Definition: udebug-proto.h:40
@ CL_MSG_RING_REMOVE
Definition: udebug-proto.h:41
@ CL_MSG_RING_NOTIFY
Definition: udebug-proto.h:42
@ CL_MSG_GET_HANDLE
Definition: udebug-proto.h:43
@ CL_MSG_RING_GET
Definition: udebug-proto.h:44
@ CL_MSG_ERROR
Definition: udebug-proto.h:45
static struct udebug_ptr * udebug_ring_ptr(struct udebug_hdr *hdr, uint32_t idx)
Definition: udebug-proto.h:61
struct udebug_client_msg __attribute__((packed, aligned(4)))
static void * udebug_buf_ptr(struct udebug_buf *buf, uint32_t ofs)
Definition: udebug-proto.h:67