2018-03-07 20:57:14 +08:00
|
|
|
/*
|
|
|
|
* SHARED BUFFER
|
|
|
|
*
|
2022-04-05 18:59:24 +08:00
|
|
|
* Copyright (C) 2017 Intel Corporation.
|
2018-03-07 20:57:14 +08:00
|
|
|
*
|
2018-05-26 01:49:13 +08:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-03-07 20:57:14 +08:00
|
|
|
*
|
|
|
|
* Li Fei <fei1.li@intel.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SHARED_BUFFER_H
|
|
|
|
#define SHARED_BUFFER_H
|
|
|
|
|
2018-07-03 11:51:27 +08:00
|
|
|
#define SBUF_MAGIC 0x5aa57aa71aa13aa3UL
|
2018-09-11 10:56:05 +08:00
|
|
|
#define SBUF_MAX_SIZE (1UL << 22U)
|
|
|
|
#define SBUF_HEAD_SIZE 64U
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
/* sbuf flags */
|
2018-09-11 10:56:05 +08:00
|
|
|
#define OVERRUN_CNT_EN (1U << 0U) /* whether overrun counting is enabled */
|
|
|
|
#define OVERWRITE_EN (1U << 1U) /* whether overwrite is enabled */
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* (sbuf) head + buf (store (ele_num - 1) elements at most)
|
|
|
|
* buffer empty: tail == head
|
|
|
|
* buffer full: (tail + ele_size) % size == head
|
|
|
|
*
|
|
|
|
* Base of memory for elements
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* ----------------------------------------------------------------------
|
|
|
|
* | struct shared_buf | raw data (ele_size)| ... | raw data (ele_size) |
|
|
|
|
* ----------------------------------------------------------------------
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* struct shared_buf *buf
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum {
|
2018-11-09 11:39:18 +08:00
|
|
|
ACRN_TRACE = 0U,
|
2018-03-07 20:57:14 +08:00
|
|
|
ACRN_HVLOG,
|
2018-10-24 00:05:53 +08:00
|
|
|
ACRN_SEP,
|
|
|
|
ACRN_SOCWATCH,
|
2018-03-07 20:57:14 +08:00
|
|
|
ACRN_SBUF_ID_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Make sure sizeof(struct shared_buf) == SBUF_HEAD_SIZE */
|
|
|
|
struct shared_buf {
|
|
|
|
uint64_t magic;
|
|
|
|
uint32_t ele_num; /* number of elements */
|
|
|
|
uint32_t ele_size; /* sizeof of elements */
|
|
|
|
uint32_t head; /* offset from base, to read */
|
|
|
|
uint32_t tail; /* offset from base, to write */
|
2018-11-09 11:39:18 +08:00
|
|
|
uint32_t flags;
|
|
|
|
uint32_t reserved;
|
2018-03-07 20:57:14 +08:00
|
|
|
uint32_t overrun_cnt; /* count of overrun */
|
|
|
|
uint32_t size; /* ele_num * ele_size */
|
|
|
|
uint32_t padding[6];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-10-09 15:21:35 +08:00
|
|
|
/**
|
|
|
|
*@pre sbuf != NULL
|
|
|
|
*@pre data != NULL
|
|
|
|
*/
|
|
|
|
uint32_t sbuf_put(struct shared_buf *sbuf, uint8_t *data);
|
2018-12-08 00:30:49 +08:00
|
|
|
int32_t sbuf_share_setup(uint16_t pcpu_id, uint32_t sbuf_id, uint64_t *hva);
|
2019-06-27 00:50:00 +08:00
|
|
|
void sbuf_reset(void);
|
2018-10-24 00:05:53 +08:00
|
|
|
uint32_t sbuf_next_ptr(uint32_t pos, uint32_t span, uint32_t scope);
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
#endif /* SHARED_BUFFER_H */
|