udebug-proto.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include "udebug.h"
  21. struct udebug_hdr {
  22. uint32_t ring_size;
  23. uint32_t data_size;
  24. uint32_t format;
  25. uint32_t sub_format;
  26. uintptr_t flags[8 / sizeof(uintptr_t)];
  27. uintptr_t notify;
  28. uint32_t head_hi;
  29. uint32_t head;
  30. uint32_t data_head;
  31. uint32_t data_used;
  32. };
  33. enum udebug_client_msg_type {
  34. CL_MSG_RING_ADD,
  35. CL_MSG_RING_REMOVE,
  36. CL_MSG_RING_NOTIFY,
  37. CL_MSG_GET_HANDLE,
  38. CL_MSG_RING_GET,
  39. CL_MSG_ERROR,
  40. };
  41. struct udebug_client_msg {
  42. uint8_t type;
  43. uint8_t _pad[3];
  44. uint32_t id;
  45. union {
  46. struct {
  47. uint32_t ring_size, data_size;
  48. };
  49. uint32_t notify_mask;
  50. };
  51. } __attribute__((packed, aligned(4)));
  52. static inline struct udebug_ptr *
  53. udebug_ring_ptr(struct udebug_hdr *hdr, uint32_t idx)
  54. {
  55. struct udebug_ptr *ring = (struct udebug_ptr *)&hdr[1];
  56. return &ring[idx & (hdr->ring_size - 1)];
  57. }
  58. static inline void *udebug_buf_ptr(struct udebug_buf *buf, uint32_t ofs)
  59. {
  60. return buf->data + (ofs & (buf->data_size - 1));
  61. }
  62. #endif