| 1 |
/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */ |
| 2 |
/* |
| 3 |
* Siemens System Memory Buffer driver. |
| 4 |
* Copyright(c) 2022, HiSilicon Limited. |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef _ULTRASOC_SMB_H |
| 8 |
#define _ULTRASOC_SMB_H |
| 9 |
|
| 10 |
#include <linux/bitfield.h> |
| 11 |
#include <linux/miscdevice.h> |
| 12 |
#include <linux/spinlock.h> |
| 13 |
|
| 14 |
/* Offset of SMB global registers */ |
| 15 |
#define SMB_GLB_CFG_REG 0x00 |
| 16 |
#define SMB_GLB_EN_REG 0x04 |
| 17 |
#define SMB_GLB_INT_REG 0x08 |
| 18 |
|
| 19 |
/* Offset of SMB logical buffer registers */ |
| 20 |
#define SMB_LB_CFG_LO_REG 0x40 |
| 21 |
#define SMB_LB_CFG_HI_REG 0x44 |
| 22 |
#define SMB_LB_INT_CTRL_REG 0x48 |
| 23 |
#define SMB_LB_INT_STS_REG 0x4c |
| 24 |
#define SMB_LB_RD_ADDR_REG 0x5c |
| 25 |
#define SMB_LB_WR_ADDR_REG 0x60 |
| 26 |
#define SMB_LB_PURGE_REG 0x64 |
| 27 |
|
| 28 |
/* Set global config register */ |
| 29 |
#define SMB_GLB_CFG_BURST_LEN_MSK GENMASK(11, 4) |
| 30 |
#define SMB_GLB_CFG_IDLE_PRD_MSK GENMASK(15, 12) |
| 31 |
#define SMB_GLB_CFG_MEM_WR_MSK GENMASK(21, 16) |
| 32 |
#define SMB_GLB_CFG_MEM_RD_MSK GENMASK(27, 22) |
| 33 |
#define SMB_GLB_CFG_DEFAULT (FIELD_PREP(SMB_GLB_CFG_BURST_LEN_MSK, 0xf) | \ |
| 34 |
FIELD_PREP(SMB_GLB_CFG_IDLE_PRD_MSK, 0xf) | \ |
| 35 |
FIELD_PREP(SMB_GLB_CFG_MEM_WR_MSK, 0x3) | \ |
| 36 |
FIELD_PREP(SMB_GLB_CFG_MEM_RD_MSK, 0x1b)) |
| 37 |
|
| 38 |
#define SMB_GLB_EN_HW_ENABLE BIT(0) |
| 39 |
|
| 40 |
/* Set global interrupt control register */ |
| 41 |
#define SMB_GLB_INT_EN BIT(0) |
| 42 |
#define SMB_GLB_INT_PULSE BIT(1) /* Interrupt type: 1 - Pulse */ |
| 43 |
#define SMB_GLB_INT_ACT_H BIT(2) /* Interrupt polarity: 1 - Active high */ |
| 44 |
#define SMB_GLB_INT_CFG (SMB_GLB_INT_EN | SMB_GLB_INT_PULSE | \ |
| 45 |
SMB_GLB_INT_ACT_H) |
| 46 |
|
| 47 |
/* Set logical buffer config register lower 32 bits */ |
| 48 |
#define SMB_LB_CFG_LO_EN BIT(0) |
| 49 |
#define SMB_LB_CFG_LO_SINGLE_END BIT(1) |
| 50 |
#define SMB_LB_CFG_LO_INIT BIT(8) |
| 51 |
#define SMB_LB_CFG_LO_CONT BIT(11) |
| 52 |
#define SMB_LB_CFG_LO_FLOW_MSK GENMASK(19, 16) |
| 53 |
#define SMB_LB_CFG_LO_DEFAULT (SMB_LB_CFG_LO_EN | SMB_LB_CFG_LO_SINGLE_END | \ |
| 54 |
SMB_LB_CFG_LO_INIT | SMB_LB_CFG_LO_CONT | \ |
| 55 |
FIELD_PREP(SMB_LB_CFG_LO_FLOW_MSK, 0xf)) |
| 56 |
|
| 57 |
/* Set logical buffer config register upper 32 bits */ |
| 58 |
#define SMB_LB_CFG_HI_RANGE_UP_MSK GENMASK(15, 8) |
| 59 |
#define SMB_LB_CFG_HI_DEFAULT FIELD_PREP(SMB_LB_CFG_HI_RANGE_UP_MSK, 0xff) |
| 60 |
|
| 61 |
/* |
| 62 |
* Set logical buffer interrupt control register. |
| 63 |
* The register control the validity of both real-time events and |
| 64 |
* interrupts. When logical buffer status changes causes to issue |
| 65 |
* an interrupt at the same time as it issues a real-time event. |
| 66 |
* Real-time events are used in SMB driver, which needs to get the buffer |
| 67 |
* status. Interrupts are used in debugger mode. |
| 68 |
* SMB_LB_INT_CTRL_BUF_NOTE_MASK control which events flags or interrupts |
| 69 |
* are valid. |
| 70 |
*/ |
| 71 |
#define SMB_LB_INT_CTRL_EN BIT(0) |
| 72 |
#define SMB_LB_INT_CTRL_BUF_NOTE_MSK GENMASK(11, 8) |
| 73 |
#define SMB_LB_INT_CTRL_CFG (SMB_LB_INT_CTRL_EN | \ |
| 74 |
FIELD_PREP(SMB_LB_INT_CTRL_BUF_NOTE_MSK, 0xf)) |
| 75 |
|
| 76 |
/* Set logical buffer interrupt status register */ |
| 77 |
#define SMB_LB_INT_STS_NOT_EMPTY_MSK BIT(0) |
| 78 |
#define SMB_LB_INT_STS_BUF_RESET_MSK GENMASK(3, 0) |
| 79 |
#define SMB_LB_INT_STS_RESET FIELD_PREP(SMB_LB_INT_STS_BUF_RESET_MSK, 0xf) |
| 80 |
|
| 81 |
#define SMB_LB_PURGE_PURGED BIT(0) |
| 82 |
|
| 83 |
#define SMB_REG_ADDR_RES 0 |
| 84 |
#define SMB_BUF_ADDR_RES 1 |
| 85 |
#define SMB_BUF_ADDR_LO_MSK GENMASK(31, 0) |
| 86 |
|
| 87 |
/** |
| 88 |
* struct smb_data_buffer - Details of the buffer used by SMB |
| 89 |
* @buf_base: Memory mapped base address of SMB. |
| 90 |
* @buf_hw_base: SMB buffer start Physical base address, only used 32bits. |
| 91 |
* @buf_size: Size of the buffer. |
| 92 |
* @data_size: Size of the available trace data for SMB. |
| 93 |
* @buf_rdptr: Current read position (index) within the buffer. |
| 94 |
*/ |
| 95 |
struct smb_data_buffer { |
| 96 |
void *buf_base; |
| 97 |
u32 buf_hw_base; |
| 98 |
unsigned long buf_size; |
| 99 |
unsigned long data_size; |
| 100 |
unsigned long buf_rdptr; |
| 101 |
}; |
| 102 |
|
| 103 |
/** |
| 104 |
* struct smb_drv_data - specifics associated to an SMB component |
| 105 |
* @base: Memory mapped base address for SMB component. |
| 106 |
* @csdev: Component vitals needed by the framework. |
| 107 |
* @sdb: Data buffer for SMB. |
| 108 |
* @miscdev: Specifics to handle "/dev/xyz.smb" entry. |
| 109 |
* @spinlock: Control data access to one at a time. |
| 110 |
* @reading: Synchronise user space access to SMB buffer. |
| 111 |
* @pid: Process ID of the process being monitored by the |
| 112 |
* session that is using this component. |
| 113 |
*/ |
| 114 |
struct smb_drv_data { |
| 115 |
void __iomem *base; |
| 116 |
struct coresight_device *csdev; |
| 117 |
struct smb_data_buffer sdb; |
| 118 |
struct miscdevice miscdev; |
| 119 |
raw_spinlock_t spinlock; |
| 120 |
bool reading; |
| 121 |
pid_t pid; |
| 122 |
}; |
| 123 |
|
| 124 |
#endif |