source: rtems/c/src/lib/libbsp/sparc/shared/drvmgr/ambapp_bus_leon2.c @ b2ed712

5
Last change on this file since b2ed712 was b2ed712, checked in by Sebastian Huber <sebastian.huber@…>, on 08/25/17 at 08:58:58

Include missing <string.h>

Update #2133.

  • Property mode set to 100644
File size: 6.3 KB
Line 
1/*  LEON2 GRLIB AMBA Plug & Play bus driver.
2 *
3 *  COPYRIGHT (c) 2008.
4 *  Cobham Gaisler AB.
5 *
6 *  This is driver is a wrapper for the general AMBA Plug & Play bus
7 *  driver. This is a bus driver for LEON2-GRLIB systems providing a
8 *  AMBA Plug & Play bus, the parent bus must be a LEON2 hardcoded
9 *  Bus. All IRQs must be routed to this bus driver in order for IRQs
10 *  to work. The PnP information is used to extract IRQs and base
11 *  register addresses.
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#include <bsp.h>
19
20#ifdef LEON2
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <libcpu/access.h>
25#include <drvmgr/drvmgr.h>
26#include <drvmgr/ambapp_bus.h>
27#include <drvmgr/leon2_amba_bus.h>
28
29#define DBG(args...)
30
31int ambapp_leon2_int_register(
32        struct drvmgr_dev *dev,
33        int index,
34        const char *info,
35        drvmgr_isr isr,
36        void *arg);
37int ambapp_leon2_int_unregister(
38        struct drvmgr_dev *dev,
39        int index,
40        drvmgr_isr isr,
41        void *arg);
42int ambapp_leon2_int_clear(
43        struct drvmgr_dev *dev,
44        int index);
45int ambapp_leon2_int_mask(
46        struct drvmgr_dev *dev,
47        int irq);
48int ambapp_leon2_int_unmask(
49        struct drvmgr_dev *dev,
50        int irq);
51int ambapp_leon2_get_params(
52        struct drvmgr_dev *dev,
53        struct drvmgr_bus_params *params);
54
55int ambapp_leon2_init1(struct drvmgr_dev *dev);
56int ambapp_leon2_init2(struct drvmgr_dev *dev);
57int ambapp_leon2_remove(struct drvmgr_dev *dev);
58void ambapp_leon2_register(void);
59
60/* READ/WRITE access to SpaceWire target over RMAP */
61void *ambapp_leon2_rw_arg(struct drvmgr_dev *dev);
62
63struct ambappl2_priv {
64        struct ambapp_bus abus;
65        struct ambapp_config config;
66};
67
68struct ambapp_ops ambapp_leon2_ops = {
69        .int_register = ambapp_leon2_int_register,
70        .int_unregister = ambapp_leon2_int_unregister,
71        .int_clear = ambapp_leon2_int_clear,
72        .int_mask = ambapp_leon2_int_mask,
73        .int_unmask = ambapp_leon2_int_unmask,
74        .get_params = ambapp_leon2_get_params
75};
76
77struct drvmgr_func ambapp_leon2_funcs[] = {
78        DRVMGR_FUNC(AMBAPP_RW_ARG, ambapp_leon2_rw_arg),
79
80        DRVMGR_FUNC(AMBAPP_R8,  _ld8),
81        DRVMGR_FUNC(AMBAPP_R16, _ld16),
82        DRVMGR_FUNC(AMBAPP_R32, _ld32),
83        DRVMGR_FUNC(AMBAPP_R64, _ld64),
84
85        DRVMGR_FUNC(AMBAPP_W8,  _st8),
86        DRVMGR_FUNC(AMBAPP_W16, _st16),
87        DRVMGR_FUNC(AMBAPP_W32, _st32),
88        DRVMGR_FUNC(AMBAPP_W64, _st64),
89
90        DRVMGR_FUNC(AMBAPP_RMEM, memcpy),
91        DRVMGR_FUNC(AMBAPP_WMEM, memcpy),
92
93        DRVMGR_FUNC_END
94};
95
96struct drvmgr_drv_ops ambapp_ops = {
97        .init = {ambapp_leon2_init1, ambapp_leon2_init2, NULL, NULL},
98        .remove = ambapp_leon2_remove,
99        .info = NULL,
100};
101
102struct leon2_amba_dev_id ambapp_leon2_ids[] = {
103        {LEON2_AMBA_AMBAPP_ID},
104        {0}
105};
106
107struct leon2_amba_drv_info ambapp_bus_drv_leon2 = {
108        {
109                DRVMGR_OBJ_DRV,                 /* Driver */
110                NULL,                           /* Next driver */
111                NULL,                           /* Device list */
112                DRIVER_LEON2_AMBA_AMBAPP,       /* Driver ID */
113                "AMBAPP_LEON2_DRV",             /* Driver Name */
114                DRVMGR_BUS_TYPE_LEON2_AMBA,     /* Bus Type */
115                &ambapp_ops,
116                NULL,                           /* Funcs */
117                0,
118                sizeof(struct ambappl2_priv),   /* Let DrvMgr allocate priv */
119        },
120        &ambapp_leon2_ids[0]
121};
122
123void ambapp_leon2_register(void)
124{
125        drvmgr_drv_register(&ambapp_bus_drv_leon2.general);
126}
127
128/* Function called from a hard configuration */
129int ambapp_leon2_init1(struct drvmgr_dev *dev)
130{
131        union drvmgr_key_value *value;
132        struct ambappl2_priv *priv = dev->priv;
133        struct leon2_amba_dev_info *devinfo;
134        struct ambapp_config *config;
135        unsigned int ioarea;
136        unsigned int freq_hz;
137        LEON_Register_Map *regs;
138
139        dev->name = "LEON2 AMBA PnP";
140
141        if (!priv)
142                return DRVMGR_NOMEM;
143
144        config = &priv->config;
145        config->abus = &priv->abus;
146        config->ops = &ambapp_leon2_ops;
147        config->maps_up = DRVMGR_TRANSLATE_ONE2ONE;
148        config->maps_down = DRVMGR_TRANSLATE_ONE2ONE;
149        config->funcs = ambapp_leon2_funcs;
150        config->bus_type = DRVMGR_BUS_TYPE_LEON2_AMBA;
151
152        /* Get AMBA PnP Area from REG0 */
153        devinfo = (struct leon2_amba_dev_info *)dev->businfo;
154        ioarea = devinfo->reg_base;
155
156        /* Scan AMBA PnP Bus. ABUS has already been cleared with memset() */
157        ambapp_scan(&priv->abus, ioarea, NULL, NULL);
158
159        /* Try to get Configuration from resource configuration */
160
161        value = drvmgr_dev_key_get(dev, "busFreq", DRVMGR_KT_INT);
162        if (value) {
163                /* Set frequency of AMBA bus if specified by user. The frequency
164                 * must be for AHB bus which IOAREA matches (AHB bus 0).
165                 */
166                freq_hz = value->i;
167        } else {
168                /* Get Bus/LEON2 Frequency from timer prescaler,
169                 * the hardcoded address is used to get to timer
170                 */
171                regs = (LEON_Register_Map *) 0x80000000;
172                freq_hz = (regs->Scaler_Reload + 1) * 1000 * 1000;
173        }
174        /* Note that this can be overrided by a driver on the AMBA PnP bus.*/
175        ambapp_freq_init(&priv->abus, NULL, freq_hz);
176
177        value = drvmgr_dev_key_get(dev, "drvRes", DRVMGR_KT_POINTER);
178        if (!value) {
179                DBG("ambapp_leon2_init1: Failed getting resource drvRes\n");
180                config->resources = NULL;
181        } else {
182                DBG("ambapp_leon2_init1: drvRes: 0x%08x\n", (unsigned int)value->ptr);
183                config->resources = (struct drvmgr_bus_res *)value->ptr;
184        }
185
186        /* Initialize the AMBA Bus */
187        return ambapp_bus_register(dev, config);
188}
189
190int ambapp_leon2_init2(struct drvmgr_dev *dev)
191{
192        return 0;
193}
194
195int ambapp_leon2_remove(struct drvmgr_dev *dev)
196{
197        return 0;
198}
199
200void *ambapp_leon2_rw_arg(struct drvmgr_dev *dev)
201{
202        return dev; /* No argument really needed, by for debug */
203}
204
205int ambapp_leon2_int_register
206        (
207        struct drvmgr_dev *dev,
208        int index,
209        const char *info,
210        drvmgr_isr isr,
211        void *arg
212        )
213{
214        /* Let LEON2 bus handle interrupt requests */
215        return drvmgr_interrupt_register(dev->parent->dev, index, info, isr, arg);
216}
217
218int ambapp_leon2_int_unregister
219        (
220        struct drvmgr_dev *dev,
221        int index,
222        drvmgr_isr isr,
223        void *arg
224        )
225{
226        /* Let LEON2 bus handle interrupt requests */
227        return drvmgr_interrupt_unregister(dev->parent->dev, index, isr, arg);
228}
229
230int ambapp_leon2_int_clear
231        (
232        struct drvmgr_dev *dev,
233        int index
234        )
235{
236        /* Let LEON2 bus handle interrupt requests */
237        return drvmgr_interrupt_clear(dev->parent->dev, index);
238}
239
240int ambapp_leon2_int_mask
241        (
242        struct drvmgr_dev *dev,
243        int index
244        )
245{
246        /* Let LEON2 bus handle interrupt requests */
247        return drvmgr_interrupt_mask(dev->parent->dev, index);
248}
249
250int ambapp_leon2_int_unmask
251        (
252        struct drvmgr_dev *dev,
253        int index
254        )
255{
256        /* Let LEON2 bus handle interrupt requests */
257        return drvmgr_interrupt_unmask(dev->parent->dev, index);
258}
259
260int ambapp_leon2_get_params(struct drvmgr_dev *dev, struct drvmgr_bus_params *params)
261{
262        params->dev_prefix = "";
263        return 0;
264}
265
266#endif
Note: See TracBrowser for help on using the repository browser.