Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:06

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  LEON3 GRLIB AMBA Plug & Play bus driver.
0004  *
0005  *  COPYRIGHT (c) 2008.
0006  *  Cobham Gaisler AB.
0007  *
0008  *  This is driver is a wrapper for the general AMBA Plug & Play bus
0009  *  driver. This is the root bus driver for GRLIB systems.
0010  *
0011  * Redistribution and use in source and binary forms, with or without
0012  * modification, are permitted provided that the following conditions
0013  * are met:
0014  * 1. Redistributions of source code must retain the above copyright
0015  *    notice, this list of conditions and the following disclaimer.
0016  * 2. Redistributions in binary form must reproduce the above copyright
0017  *    notice, this list of conditions and the following disclaimer in the
0018  *    documentation and/or other materials provided with the distribution.
0019  *
0020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0023  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0024  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0025  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0026  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0029  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0030  * POSSIBILITY OF SUCH DAMAGE.
0031  */
0032 
0033 #include <stdlib.h>
0034 #include <stdio.h>
0035 #include <string.h>
0036 #include <stdint.h>
0037 #include <libcpu/access.h>
0038 
0039 #include <grlib/ambapp_bus.h>
0040 #include <grlib/ambapp_bus_grlib.h>
0041 #include <grlib/genirq.h>
0042 
0043 #include <bsp.h>
0044 #include <bsp/irq-generic.h>
0045 
0046 #include <grlib/grlib_impl.h>
0047 
0048 #define DBG(args...)
0049 /*#define DBG(args...) printk(args)*/
0050 
0051 static int ambapp_grlib_int_register(
0052     struct drvmgr_dev *dev,
0053     int irq,
0054     const char *info,
0055     drvmgr_isr isr,
0056     void *arg);
0057 static int ambapp_grlib_int_unregister(
0058     struct drvmgr_dev *dev,
0059     int irq,
0060     drvmgr_isr isr,
0061     void *arg);
0062 static int ambapp_grlib_int_clear(
0063     struct drvmgr_dev *dev,
0064     int irq);
0065 static int ambapp_grlib_int_mask(
0066     struct drvmgr_dev *dev,
0067     int irq);
0068 static int ambapp_grlib_int_unmask(
0069     struct drvmgr_dev *dev,
0070     int irq);
0071 #ifdef RTEMS_SMP
0072 static int ambapp_grlib_int_set_affinity(
0073     struct drvmgr_dev *dev,
0074     int irq,
0075     const Processor_mask *cpus);
0076 #endif
0077 static int ambapp_grlib_get_params(
0078     struct drvmgr_dev *dev,
0079     struct drvmgr_bus_params *params);
0080 
0081 static int ambapp_grlib_init1(struct drvmgr_dev *dev);
0082 static int ambapp_grlib_init2(struct drvmgr_dev *dev);
0083 static int ambapp_grlib_remove(struct drvmgr_dev *dev);
0084 
0085 /* READ/WRITE access to SpaceWire target over RMAP */
0086 static void *ambapp_grlib_rw_arg(struct drvmgr_dev *dev);
0087 
0088 static struct ambapp_ops ambapp_grlib_ops = {
0089     .int_register = ambapp_grlib_int_register,
0090     .int_unregister = ambapp_grlib_int_unregister,
0091     .int_clear = ambapp_grlib_int_clear,
0092     .int_mask = ambapp_grlib_int_mask,
0093     .int_unmask = ambapp_grlib_int_unmask,
0094 #ifdef RTEMS_SMP
0095     .int_set_affinity = ambapp_grlib_int_set_affinity,
0096 #endif
0097     .get_params = ambapp_grlib_get_params
0098 };
0099 
0100 static void *ambapp_grlib_rw_arg(struct drvmgr_dev *dev)
0101 {
0102     return dev; /* No argument really needed, but for debug? */
0103 }
0104 
0105 static struct drvmgr_func ambapp_grlib_funcs[] =
0106 {
0107     DRVMGR_FUNC(AMBAPP_RW_ARG, ambapp_grlib_rw_arg),
0108 
0109     DRVMGR_FUNC(AMBAPP_R8,  _ld8),
0110     DRVMGR_FUNC(AMBAPP_R16, _ld16),
0111     DRVMGR_FUNC(AMBAPP_R32, _ld32),
0112     DRVMGR_FUNC(AMBAPP_R64, _ld64),
0113 
0114     DRVMGR_FUNC(AMBAPP_W8,  _st8),
0115     DRVMGR_FUNC(AMBAPP_W16, _st16),
0116     DRVMGR_FUNC(AMBAPP_W32, _st32),
0117     DRVMGR_FUNC(AMBAPP_W64, _st64),
0118 
0119     DRVMGR_FUNC(AMBAPP_RMEM, memcpy),
0120     DRVMGR_FUNC(AMBAPP_WMEM, memcpy),
0121 
0122     DRVMGR_FUNC_END,
0123 };
0124 
0125 static struct drvmgr_drv_ops ambapp_grlib_drv_ops = 
0126 {
0127     .init = {ambapp_grlib_init1, ambapp_grlib_init2, NULL, NULL},
0128     .remove = ambapp_grlib_remove,
0129     .info = NULL,
0130 };
0131 
0132 static struct drvmgr_drv ambapp_bus_drv_grlib = 
0133 {
0134     DRVMGR_OBJ_DRV,         /* Driver */
0135     NULL,               /* Next driver */
0136     NULL,               /* Device list */
0137     DRIVER_GRLIB_AMBAPP_ID,     /* Driver ID */
0138     "AMBAPP_GRLIB_DRV",     /* Driver Name */
0139     DRVMGR_BUS_TYPE_ROOT,       /* Bus Type */
0140     &ambapp_grlib_drv_ops,
0141     NULL,               /* Funcs */
0142     0,
0143     0,
0144 };
0145 
0146 static struct grlib_config *drv_mgr_grlib_config = NULL;
0147 
0148 void ambapp_grlib_register(void)
0149 {
0150     drvmgr_drv_register(&ambapp_bus_drv_grlib);
0151 }
0152 
0153 int ambapp_grlib_root_register(struct grlib_config *config)
0154 {
0155 
0156     /* Save the configuration for later */
0157     drv_mgr_grlib_config = config;
0158 
0159     /* Register root device driver */
0160     drvmgr_root_drv_register(&ambapp_bus_drv_grlib);
0161 
0162     return 0;
0163 }
0164 
0165 /* Function called from Driver Manager Initialization Stage 1 */
0166 static int ambapp_grlib_init1(struct drvmgr_dev *dev)
0167 {
0168     struct ambapp_config *config;
0169 
0170     dev->priv = NULL;
0171     dev->name = "GRLIB AMBA PnP";
0172 
0173     DBG("AMBAPP GRLIB: intializing\n");
0174 
0175     config = grlib_malloc(sizeof(*config));
0176     if ( !config )
0177         return RTEMS_NO_MEMORY;
0178 
0179     config->ops = &ambapp_grlib_ops;
0180     config->maps_up = DRVMGR_TRANSLATE_ONE2ONE;
0181     config->maps_down = DRVMGR_TRANSLATE_ONE2ONE;
0182     config->abus = drv_mgr_grlib_config->abus;
0183     config->resources = drv_mgr_grlib_config->resources;
0184     config->funcs = ambapp_grlib_funcs;
0185     config->bus_type = DRVMGR_BUS_TYPE_AMBAPP;
0186 
0187     /* Initialize the generic part of the AMBA Bus */
0188     return ambapp_bus_register(dev, config);
0189 }
0190 
0191 static int ambapp_grlib_init2(struct drvmgr_dev *dev)
0192 {
0193     return 0;
0194 }
0195 
0196 static int ambapp_grlib_remove(struct drvmgr_dev *dev)
0197 {
0198     return 0;
0199 }
0200 
0201 static int ambapp_grlib_int_register
0202     (
0203     struct drvmgr_dev *dev,
0204     int irq,
0205     const char *info,
0206     drvmgr_isr isr,
0207     void *arg
0208     )
0209 {
0210     return rtems_interrupt_handler_install(irq, info,
0211             RTEMS_INTERRUPT_SHARED, isr, arg);
0212 }
0213 
0214 static int ambapp_grlib_int_unregister
0215     (
0216     struct drvmgr_dev *dev,
0217     int irq,
0218     drvmgr_isr isr,
0219     void *arg
0220     )
0221 {
0222     return rtems_interrupt_handler_remove(irq, isr, arg);
0223 }
0224 
0225 static int ambapp_grlib_int_clear
0226     (
0227     struct drvmgr_dev *dev,
0228     int irq)
0229 {
0230     if (rtems_interrupt_clear(irq) != RTEMS_SUCCESSFUL) {
0231         return DRVMGR_FAIL;
0232     }
0233 
0234     return DRVMGR_OK;
0235 }
0236 
0237 static int ambapp_grlib_int_mask
0238     (
0239     struct drvmgr_dev *dev,
0240     int irq
0241     )
0242 {
0243     if (rtems_interrupt_vector_disable(irq) != RTEMS_SUCCESSFUL) {
0244         return DRVMGR_FAIL;
0245     }
0246 
0247     return DRVMGR_OK;
0248 }
0249 
0250 static int ambapp_grlib_int_unmask
0251     (
0252     struct drvmgr_dev *dev,
0253     int irq
0254     )
0255 {
0256     if (rtems_interrupt_vector_enable(irq) != RTEMS_SUCCESSFUL) {
0257         return DRVMGR_FAIL;
0258     }
0259 
0260     return DRVMGR_OK;
0261 }
0262 
0263 #ifdef RTEMS_SMP
0264 static int ambapp_grlib_int_set_affinity
0265     (
0266     struct drvmgr_dev *dev,
0267     int irq,
0268     const Processor_mask *cpus
0269     )
0270 {
0271     bsp_interrupt_set_affinity(irq, cpus);
0272     return DRVMGR_OK;
0273 }
0274 #endif
0275 
0276 static int ambapp_grlib_get_params(struct drvmgr_dev *dev, struct drvmgr_bus_params *params)
0277 {
0278     /* Leave params->freq_hz untouched for default */
0279     params->dev_prefix = "";
0280     return 0;
0281 }