Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  Old AMBA scanning Interface provided for backwards compability
0005  *
0006  *  COPYRIGHT (c) 2011
0007  *  Aeroflex Gaisler
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions
0011  * are met:
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions and the following disclaimer.
0014  * 2. Redistributions in binary form must reproduce the above copyright
0015  *    notice, this list of conditions and the following disclaimer in the
0016  *    documentation and/or other materials provided with the distribution.
0017  *
0018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0028  * POSSIBILITY OF SUCH DAMAGE.
0029  */
0030 
0031 #include <grlib/ambapp.h>
0032 
0033 struct ambapp_dev_find_match_arg {
0034   int      index;
0035   int      count;
0036   int      type;
0037   void      *dev;
0038 };
0039 
0040 /* AMBA PP find routines */
0041 static int ambapp_dev_find_match(struct ambapp_dev *dev, int index, void *arg)
0042 {
0043   struct ambapp_dev_find_match_arg *p = arg;
0044 
0045   if (p->index == 0) {
0046     /* Found controller, stop */
0047     if (p->type == DEV_APB_SLV) {
0048       *(struct ambapp_apb_info *)p->dev = *DEV_TO_APB(dev);
0049       p->dev = ((struct ambapp_apb_info *)p->dev)+1;
0050     } else {
0051       *(struct ambapp_ahb_info *)p->dev = *DEV_TO_AHB(dev);
0052       p->dev = ((struct ambapp_ahb_info *)p->dev)+1;
0053     }
0054     p->count--;
0055     if (p->count < 1)
0056       return 1;
0057   } else {
0058     p->index--;
0059   }
0060   return 0;
0061 }
0062 
0063 int ambapp_find_apbslvs_next(struct ambapp_bus *abus, int vendor, int device, struct ambapp_apb_info *dev, int index, int maxno)
0064 {
0065   struct ambapp_dev_find_match_arg arg;
0066 
0067   arg.index = index;
0068   arg.count = maxno;
0069   arg.type = DEV_APB_SLV; /* APB */
0070   arg.dev = dev;
0071 
0072   ambapp_for_each(abus, (OPTIONS_ALL|OPTIONS_APB_SLVS), vendor, device,
0073                   ambapp_dev_find_match, &arg);
0074 
0075   return maxno - arg.count;
0076 }
0077 
0078 int ambapp_find_apbslv(struct ambapp_bus *abus, int vendor, int device, struct ambapp_apb_info *dev)
0079 {
0080   return ambapp_find_apbslvs_next(abus, vendor, device, dev, 0, 1);
0081 }
0082 
0083 int ambapp_find_apbslv_next(struct ambapp_bus *abus, int vendor, int device, struct ambapp_apb_info *dev, int index)
0084 {
0085   return ambapp_find_apbslvs_next(abus, vendor, device, dev, index, 1);
0086 }
0087 
0088 int ambapp_find_apbslvs(struct ambapp_bus *abus, int vendor, int device, struct ambapp_apb_info *dev, int maxno)
0089 {
0090   return ambapp_find_apbslvs_next(abus, vendor, device, dev, 0, maxno);
0091 }
0092 
0093 int ambapp_get_number_apbslv_devices(struct ambapp_bus *abus, int vendor, int device)
0094 {
0095   return ambapp_dev_count(abus, (OPTIONS_ALL|OPTIONS_APB_SLVS), vendor, device);
0096 }
0097 
0098 int ambapp_find_ahbslvs_next(struct ambapp_bus *abus, int vendor, int device, struct ambapp_ahb_info *dev, int index, int maxno)
0099 {
0100   struct ambapp_dev_find_match_arg arg;
0101 
0102   arg.index = index;
0103   arg.count = maxno;
0104   arg.type = DEV_AHB_SLV; /* AHB SLV */
0105   arg.dev = dev;
0106 
0107   ambapp_for_each(abus, (OPTIONS_ALL|OPTIONS_AHB_SLVS), vendor, device,
0108                   ambapp_dev_find_match, &arg);
0109 
0110   return maxno - arg.count;
0111 }
0112 
0113 int ambapp_find_ahbslv_next(struct ambapp_bus *abus, int vendor, int device, struct ambapp_ahb_info *dev, int index)
0114 {
0115   return ambapp_find_ahbslvs_next(abus, vendor, device, dev, index, 1);
0116 }
0117 
0118 int ambapp_find_ahbslv(struct ambapp_bus *abus, int vendor, int device, struct ambapp_ahb_info *dev)
0119 {
0120   return ambapp_find_ahbslvs_next(abus, vendor, device, dev, 0, 1);
0121 }
0122 
0123 int ambapp_find_ahbslvs(struct ambapp_bus *abus, int vendor, int device, struct ambapp_ahb_info *dev, int maxno)
0124 {
0125   return ambapp_find_ahbslvs_next(abus, vendor, device, dev, 0, maxno);
0126 }
0127 
0128 int ambapp_get_number_ahbslv_devices(struct ambapp_bus *abus, int vendor, int device)
0129 {
0130   return ambapp_dev_count(abus, (OPTIONS_ALL|OPTIONS_AHB_SLVS), vendor, device);
0131 }