RTEMS 6.1-rc1
memscrub.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/* MEMSCRUB driver interface
4 *
5 * COPYRIGHT (c) 2017.
6 * Cobham Gaisler AB.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef __MEMSCRUB_H__
31#define __MEMSCRUB_H__
32
33#include <stdint.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39#define MEMSCRUB_ERR_OK 0
40#define MEMSCRUB_ERR_EINVAL -1
41#define MEMSCRUB_ERR_ERROR -2
42
43extern void memscrub_register_drv(void);
44
45/*
46 * MEMORYSCRUBBER CONFIG register fields
47 */
48#define CONFIG_DELAY_BIT 8
49#define CONFIG_IRQD_BIT 7
50#define CONFIG_SERA_BIT 5
51#define CONFIG_LOOP_BIT 4
52#define CONFIG_MODE_BIT 2
53#define CONFIG_ES_BIT 1
54#define CONFIG_SCEN_BIT 0
55
56#define CONFIG_DELAY (0xff << CONFIG_DELAY_BIT)
57#define CONFIG_IRQD (0x1 << CONFIG_IRQD_BIT)
58#define CONFIG_SERA (0x1 << CONFIG_SERA_BIT)
59#define CONFIG_LOOP (0x1 << CONFIG_LOOP_BIT)
60#define CONFIG_MODE (0x3 << CONFIG_MODE_BIT)
61#define CONFIG_ES (0x1 << CONFIG_ES_BIT)
62#define CONFIG_SCEN (0x1 << CONFIG_SCEN_BIT)
63#define CONFIG_MODE_SCRUB (0x0 << CONFIG_MODE_BIT)
64#define CONFIG_MODE_REGEN (0x1 << CONFIG_MODE_BIT)
65#define CONFIG_MODE_INIT (0x2 << CONFIG_MODE_BIT)
66
67#define MEMSCRUB_OPTIONS_INTERRUPTDONE_ENABLE CONFIG_IRQD
68#define MEMSCRUB_OPTIONS_INTERRUPTDONE_DISABLE 0
69#define MEMSCRUB_OPTIONS_EXTERNALSTART_ENABLE CONFIG_ES
70#define MEMSCRUB_OPTIONS_EXTERNALSTART_DISABLE 0
71#define MEMSCRUB_OPTIONS_LOOPMODE_ENABLE CONFIG_LOOP
72#define MEMSCRUB_OPTIONS_LOOPMODE_DISABLE 0
73#define MEMSCRUB_OPTIONS_SECONDARY_MEMRANGE_ENABLE CONFIG_SERA
74#define MEMSCRUB_OPTIONS_SECONDARY_MEMRANGE_DISABLE 0
75
76/* Scrubbing modes */
77extern int memscrub_init_start(uint32_t value, uint8_t delay, int options);
78extern int memscrub_scrub_start(uint8_t delay, int options);
79extern int memscrub_regen_start(uint8_t delay, int options);
80extern int memscrub_stop(void);
81extern int memscrub_active(void);
82
83/* Set/get memory ranges */
84extern int memscrub_range_set(uint32_t start, uint32_t end);
85extern int memscrub_range_get(uint32_t * start, uint32_t * end);
86extern int memscrub_secondary_range_set(uint32_t start, uint32_t end);
87extern int memscrub_secondary_range_get(uint32_t * start, uint32_t * end);
88
89/* Interrupts */
90/* MEMSCRUB Interrupts */
91/* Function Interrupt-Code ISR callback prototype.
92 * arg - Custom arg provided by user
93 * access - AHB Access that failed
94 * ahbstatus - AHB status register of the MEMSCRUB core
95 * status - status register of the MEMSCRUB core
96 */
97typedef void (*memscrub_isr_t)(void *arg, uint32_t ahbaccess,
98 uint32_t ahbstatus, uint32_t scrubstatus);
99extern int memscrub_isr_register(memscrub_isr_t isr, void * data);
100extern int memscrub_isr_unregister(void);
101
102extern int memscrub_error_status(uint32_t *ahbaccess, uint32_t *ahbstatus,
103 uint32_t *scrubstatus);
104
105/* Set the different error thresholds. */
106
107/*
108 * MEMORYSCRUBBER AHBS register fields
109 */
110#define AHBS_CECNT_BIT 22
111#define AHBS_UECNT_BIT 14
112#define AHBS_DONE_BIT 13
113#define AHBS_SEC_BIT 11
114#define AHBS_SBC_BIT 10
115#define AHBS_CE_BIT 9
116#define AHBS_NE_BIT 8
117#define AHBS_HW_BIT 7
118#define AHBS_HM_BIT 3
119#define AHBS_HS_BIT 0
120
121#define AHBS_CECNT (0x3ff << AHBS_CECNT_BIT)
122#define AHBS_UECNT (0xff << AHBS_UECNT_BIT)
123#define AHBS_DONE (1 << AHBS_DONE_BIT)
124#define AHBS_SEC (1 << AHBS_SEC_BIT)
125#define AHBS_SBC (1 << AHBS_SBC_BIT)
126#define AHBS_CE (1 << AHBS_CE_BIT)
127#define AHBS_NE (1 << AHBS_NE_BIT)
128#define AHBS_HW (1 << AHBS_HW_BIT)
129#define AHBS_HM (0xf << AHBS_HM_BIT)
130#define AHBS_HS (0x7 << AHBS_HS_BIT)
131
132/*
133 * MEMORYSCRUBBER STAT register fields
134 */
135#define STAT_RUNCOUNT_BIT 22
136#define STAT_BLKCOUNT_BIT 14
137#define STAT_DONE_BIT 13
138#define STAT_BURSTLEN_BIT 1
139#define STAT_ACTIVE_BIT 0
140
141#define STAT_RUNCOUNT (0x3ff << STAT_RUNCOUNT_BIT)
142#define STAT_BLKCOUNT (0xff << STAT_BLKCOUNT_BIT)
143#define STAT_DONE (0x1 << STAT_DONE_BIT)
144#define STAT_BURSTLEN (0xf << STAT_BURSTLEN_BIT)
145#define STAT_ACTIVE (0x1 << STAT_ACTIVE_BIT)
146
147/*
148 * MEMORYSCRUBBER AHBERC register fields
149 */
150#define AHBERC_CECNTT_BIT 22
151#define AHBERC_UECNTT_BIT 14
152#define AHBERC_CECTE_BIT 1
153#define AHBERC_UECTE_BIT 0
154
155#define AHBERC_CECNTT (0x3ff << AHBERC_CECNTT_BIT)
156#define AHBERC_UECNTT (0xff << AHBERC_UECNTT_BIT)
157#define AHBERC_CECTE (0x1 << AHBERC_CECTE_BIT)
158#define AHBERC_UECTE (0x1 << AHBERC_UECTE_BIT)
159
160/*
161 * MEMORYSCRUBBER ETHRES register fields
162 */
163#define ETHRES_RECT_BIT 22
164#define ETHRES_BECT_BIT 14
165#define ETHRES_RECTE_BIT 1
166#define ETHRES_BECTE_BIT 0
167
168#define ETHRES_RECT (0x3ff << ETHRES_RECT_BIT)
169#define ETHRES_BECT (0xff << ETHRES_BECT_BIT)
170#define ETHRES_RECTE (0x1 << ETHRES_RECTE_BIT)
171#define ETHRES_BECTE (0x1 << ETHRES_BECTE_BIT)
172
173#define MEMSCRUB_OPTIONS_AHBERROR_CORTHRES_ENABLE AHBERC_CECTE
174#define MEMSCRUB_OPTIONS_AHBERROR_CORTHRES_DISABLE 0
175#define MEMSCRUB_OPTIONS_AHBERROR_UNCORTHRES_ENABLE AHBERC_UECTE
176#define MEMSCRUB_OPTIONS_AHBERROR_UNCORTHRES_DISABLE 0
177#define MEMSCRUB_OPTIONS_SCRUBERROR_RUNTHRES_ENABLE ETHRES_RECTE
178#define MEMSCRUB_OPTIONS_SCRUBERROR_RUNTHRES_DISABLE 0
179#define MEMSCRUB_OPTIONS_SCRUBERROR_BLOCKTHRES_ENABLE ETHRES_BECTE
180#define MEMSCRUB_OPTIONS_SCRUBERROR_BLOCKTHRES_DISABLE 0
181extern int memscrub_ahberror_setup(int uethres, int cethres, int options);
182extern int memscrub_scruberror_setup(int blkthres, int runthres,
183 int options);
184
185extern int memscrub_scrub_position(uint32_t * position);
186
187#ifdef __cplusplus
188}
189#endif
190
191#endif