1fcacb5c1SSuzuki K Poulose /* SPDX-License-Identifier: GPL-2.0 */
2fcacb5c1SSuzuki K Poulose /*
3fcacb5c1SSuzuki K Poulose * Copyright (C) 2018 Arm Limited. All rights reserved.
4fcacb5c1SSuzuki K Poulose *
5fcacb5c1SSuzuki K Poulose * Author: Suzuki K Poulose <suzuki.poulose@arm.com>
6fcacb5c1SSuzuki K Poulose */
7fcacb5c1SSuzuki K Poulose
8fcacb5c1SSuzuki K Poulose #ifndef _CORESIGHT_CATU_H
9fcacb5c1SSuzuki K Poulose #define _CORESIGHT_CATU_H
10fcacb5c1SSuzuki K Poulose
11fcacb5c1SSuzuki K Poulose #include "coresight-priv.h"
12fcacb5c1SSuzuki K Poulose
13fcacb5c1SSuzuki K Poulose /* Register offset from base */
14fcacb5c1SSuzuki K Poulose #define CATU_CONTROL 0x000
15fcacb5c1SSuzuki K Poulose #define CATU_MODE 0x004
16fcacb5c1SSuzuki K Poulose #define CATU_AXICTRL 0x008
17fcacb5c1SSuzuki K Poulose #define CATU_IRQEN 0x00c
18fcacb5c1SSuzuki K Poulose #define CATU_SLADDRLO 0x020
19fcacb5c1SSuzuki K Poulose #define CATU_SLADDRHI 0x024
20fcacb5c1SSuzuki K Poulose #define CATU_INADDRLO 0x028
21fcacb5c1SSuzuki K Poulose #define CATU_INADDRHI 0x02c
22fcacb5c1SSuzuki K Poulose #define CATU_STATUS 0x100
23fcacb5c1SSuzuki K Poulose #define CATU_DEVARCH 0xfbc
24fcacb5c1SSuzuki K Poulose
25fcacb5c1SSuzuki K Poulose #define CATU_CONTROL_ENABLE 0
26fcacb5c1SSuzuki K Poulose
27fcacb5c1SSuzuki K Poulose #define CATU_MODE_PASS_THROUGH 0U
28fcacb5c1SSuzuki K Poulose #define CATU_MODE_TRANSLATE 1U
29fcacb5c1SSuzuki K Poulose
30434d611cSSuzuki K Poulose #define CATU_AXICTRL_ARCACHE_SHIFT 4
31434d611cSSuzuki K Poulose #define CATU_AXICTRL_ARCACHE_MASK 0xf
32434d611cSSuzuki K Poulose #define CATU_AXICTRL_ARPROT_MASK 0x3
33434d611cSSuzuki K Poulose #define CATU_AXICTRL_ARCACHE(arcache) \
34434d611cSSuzuki K Poulose (((arcache) & CATU_AXICTRL_ARCACHE_MASK) << CATU_AXICTRL_ARCACHE_SHIFT)
35434d611cSSuzuki K Poulose
36434d611cSSuzuki K Poulose #define CATU_AXICTRL_VAL(arcache, arprot) \
37434d611cSSuzuki K Poulose (CATU_AXICTRL_ARCACHE(arcache) | ((arprot) & CATU_AXICTRL_ARPROT_MASK))
38434d611cSSuzuki K Poulose
39434d611cSSuzuki K Poulose #define AXI3_AxCACHE_WB_READ_ALLOC 0x7
40434d611cSSuzuki K Poulose /*
41434d611cSSuzuki K Poulose * AXI - ARPROT bits:
42434d611cSSuzuki K Poulose * See AMBA AXI & ACE Protocol specification (ARM IHI 0022E)
43434d611cSSuzuki K Poulose * sectionA4.7 Access Permissions.
44434d611cSSuzuki K Poulose *
45434d611cSSuzuki K Poulose * Bit 0: 0 - Unprivileged access, 1 - Privileged access
46434d611cSSuzuki K Poulose * Bit 1: 0 - Secure access, 1 - Non-secure access.
47434d611cSSuzuki K Poulose * Bit 2: 0 - Data access, 1 - instruction access.
48434d611cSSuzuki K Poulose *
49434d611cSSuzuki K Poulose * CATU AXICTRL:ARPROT[2] is res0 as we always access data.
50434d611cSSuzuki K Poulose */
51434d611cSSuzuki K Poulose #define CATU_OS_ARPROT 0x2
52434d611cSSuzuki K Poulose
53434d611cSSuzuki K Poulose #define CATU_OS_AXICTRL \
54434d611cSSuzuki K Poulose CATU_AXICTRL_VAL(AXI3_AxCACHE_WB_READ_ALLOC, CATU_OS_ARPROT)
55434d611cSSuzuki K Poulose
56fcacb5c1SSuzuki K Poulose #define CATU_STATUS_READY 8
57fcacb5c1SSuzuki K Poulose #define CATU_STATUS_ADRERR 0
58fcacb5c1SSuzuki K Poulose #define CATU_STATUS_AXIERR 4
59fcacb5c1SSuzuki K Poulose
60fcacb5c1SSuzuki K Poulose #define CATU_IRQEN_ON 0x1
61fcacb5c1SSuzuki K Poulose #define CATU_IRQEN_OFF 0x0
62fcacb5c1SSuzuki K Poulose
63fcacb5c1SSuzuki K Poulose struct catu_drvdata {
64fcacb5c1SSuzuki K Poulose void __iomem *base;
65fcacb5c1SSuzuki K Poulose struct coresight_device *csdev;
66fcacb5c1SSuzuki K Poulose int irq;
67fcacb5c1SSuzuki K Poulose };
68fcacb5c1SSuzuki K Poulose
69fcacb5c1SSuzuki K Poulose #define CATU_REG32(name, offset) \
70fcacb5c1SSuzuki K Poulose static inline u32 \
71fcacb5c1SSuzuki K Poulose catu_read_##name(struct catu_drvdata *drvdata) \
72fcacb5c1SSuzuki K Poulose { \
73*0a98181fSJames Clark return csdev_access_relaxed_read32(&drvdata->csdev->access, offset); \
74fcacb5c1SSuzuki K Poulose } \
75fcacb5c1SSuzuki K Poulose static inline void \
76fcacb5c1SSuzuki K Poulose catu_write_##name(struct catu_drvdata *drvdata, u32 val) \
77fcacb5c1SSuzuki K Poulose { \
78*0a98181fSJames Clark csdev_access_relaxed_write32(&drvdata->csdev->access, val, offset); \
79fcacb5c1SSuzuki K Poulose }
80fcacb5c1SSuzuki K Poulose
81fcacb5c1SSuzuki K Poulose #define CATU_REG_PAIR(name, lo_off, hi_off) \
82fcacb5c1SSuzuki K Poulose static inline u64 \
83fcacb5c1SSuzuki K Poulose catu_read_##name(struct catu_drvdata *drvdata) \
84fcacb5c1SSuzuki K Poulose { \
85*0a98181fSJames Clark return csdev_access_relaxed_read_pair(&drvdata->csdev->access, lo_off, hi_off); \
86fcacb5c1SSuzuki K Poulose } \
87fcacb5c1SSuzuki K Poulose static inline void \
88fcacb5c1SSuzuki K Poulose catu_write_##name(struct catu_drvdata *drvdata, u64 val) \
89fcacb5c1SSuzuki K Poulose { \
90*0a98181fSJames Clark csdev_access_relaxed_write_pair(&drvdata->csdev->access, val, lo_off, hi_off); \
91fcacb5c1SSuzuki K Poulose }
92fcacb5c1SSuzuki K Poulose
93fcacb5c1SSuzuki K Poulose CATU_REG32(control, CATU_CONTROL);
94fcacb5c1SSuzuki K Poulose CATU_REG32(mode, CATU_MODE);
95434d611cSSuzuki K Poulose CATU_REG32(irqen, CATU_IRQEN);
96434d611cSSuzuki K Poulose CATU_REG32(axictrl, CATU_AXICTRL);
CATU_REG_PAIR(sladdr,CATU_SLADDRLO,CATU_SLADDRHI)97fcacb5c1SSuzuki K Poulose CATU_REG_PAIR(sladdr, CATU_SLADDRLO, CATU_SLADDRHI)
98fcacb5c1SSuzuki K Poulose CATU_REG_PAIR(inaddr, CATU_INADDRLO, CATU_INADDRHI)
99fcacb5c1SSuzuki K Poulose
100fcacb5c1SSuzuki K Poulose static inline bool coresight_is_catu_device(struct coresight_device *csdev)
101fcacb5c1SSuzuki K Poulose {
102fcacb5c1SSuzuki K Poulose if (!IS_ENABLED(CONFIG_CORESIGHT_CATU))
103fcacb5c1SSuzuki K Poulose return false;
104fcacb5c1SSuzuki K Poulose if (csdev->type != CORESIGHT_DEV_TYPE_HELPER)
105fcacb5c1SSuzuki K Poulose return false;
106fcacb5c1SSuzuki K Poulose if (csdev->subtype.helper_subtype != CORESIGHT_DEV_SUBTYPE_HELPER_CATU)
107fcacb5c1SSuzuki K Poulose return false;
108fcacb5c1SSuzuki K Poulose return true;
109fcacb5c1SSuzuki K Poulose }
110fcacb5c1SSuzuki K Poulose
111fcacb5c1SSuzuki K Poulose #endif
112