1 | /* |
---|
2 | * Old AMBA scanning Interface provided for backwards compability |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 2011 |
---|
5 | * Aeroflex Gaisler |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.org/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #include <grlib/ambapp.h> |
---|
13 | |
---|
14 | struct ambapp_dev_find_match_arg { |
---|
15 | int index; |
---|
16 | int count; |
---|
17 | int type; |
---|
18 | void *dev; |
---|
19 | }; |
---|
20 | |
---|
21 | /* AMBA PP find routines */ |
---|
22 | static int ambapp_dev_find_match(struct ambapp_dev *dev, int index, void *arg) |
---|
23 | { |
---|
24 | struct ambapp_dev_find_match_arg *p = arg; |
---|
25 | |
---|
26 | if (p->index == 0) { |
---|
27 | /* Found controller, stop */ |
---|
28 | if (p->type == DEV_APB_SLV) { |
---|
29 | *(struct ambapp_apb_info *)p->dev = *DEV_TO_APB(dev); |
---|
30 | p->dev = ((struct ambapp_apb_info *)p->dev)+1; |
---|
31 | } else { |
---|
32 | *(struct ambapp_ahb_info *)p->dev = *DEV_TO_AHB(dev); |
---|
33 | p->dev = ((struct ambapp_ahb_info *)p->dev)+1; |
---|
34 | } |
---|
35 | p->count--; |
---|
36 | if (p->count < 1) |
---|
37 | return 1; |
---|
38 | } else { |
---|
39 | p->index--; |
---|
40 | } |
---|
41 | return 0; |
---|
42 | } |
---|
43 | |
---|
44 | int ambapp_find_apbslvs_next(struct ambapp_bus *abus, int vendor, int device, struct ambapp_apb_info *dev, int index, int maxno) |
---|
45 | { |
---|
46 | struct ambapp_dev_find_match_arg arg; |
---|
47 | |
---|
48 | arg.index = index; |
---|
49 | arg.count = maxno; |
---|
50 | arg.type = DEV_APB_SLV; /* APB */ |
---|
51 | arg.dev = dev; |
---|
52 | |
---|
53 | ambapp_for_each(abus, (OPTIONS_ALL|OPTIONS_APB_SLVS), vendor, device, |
---|
54 | ambapp_dev_find_match, &arg); |
---|
55 | |
---|
56 | return maxno - arg.count; |
---|
57 | } |
---|
58 | |
---|
59 | int ambapp_find_apbslv(struct ambapp_bus *abus, int vendor, int device, struct ambapp_apb_info *dev) |
---|
60 | { |
---|
61 | return ambapp_find_apbslvs_next(abus, vendor, device, dev, 0, 1); |
---|
62 | } |
---|
63 | |
---|
64 | int ambapp_find_apbslv_next(struct ambapp_bus *abus, int vendor, int device, struct ambapp_apb_info *dev, int index) |
---|
65 | { |
---|
66 | return ambapp_find_apbslvs_next(abus, vendor, device, dev, index, 1); |
---|
67 | } |
---|
68 | |
---|
69 | int ambapp_find_apbslvs(struct ambapp_bus *abus, int vendor, int device, struct ambapp_apb_info *dev, int maxno) |
---|
70 | { |
---|
71 | return ambapp_find_apbslvs_next(abus, vendor, device, dev, 0, maxno); |
---|
72 | } |
---|
73 | |
---|
74 | int ambapp_get_number_apbslv_devices(struct ambapp_bus *abus, int vendor, int device) |
---|
75 | { |
---|
76 | return ambapp_dev_count(abus, (OPTIONS_ALL|OPTIONS_APB_SLVS), vendor, device); |
---|
77 | } |
---|
78 | |
---|
79 | int ambapp_find_ahbslvs_next(struct ambapp_bus *abus, int vendor, int device, struct ambapp_ahb_info *dev, int index, int maxno) |
---|
80 | { |
---|
81 | struct ambapp_dev_find_match_arg arg; |
---|
82 | |
---|
83 | arg.index = index; |
---|
84 | arg.count = maxno; |
---|
85 | arg.type = DEV_AHB_SLV; /* AHB SLV */ |
---|
86 | arg.dev = dev; |
---|
87 | |
---|
88 | ambapp_for_each(abus, (OPTIONS_ALL|OPTIONS_AHB_SLVS), vendor, device, |
---|
89 | ambapp_dev_find_match, &arg); |
---|
90 | |
---|
91 | return maxno - arg.count; |
---|
92 | } |
---|
93 | |
---|
94 | int ambapp_find_ahbslv_next(struct ambapp_bus *abus, int vendor, int device, struct ambapp_ahb_info *dev, int index) |
---|
95 | { |
---|
96 | return ambapp_find_ahbslvs_next(abus, vendor, device, dev, index, 1); |
---|
97 | } |
---|
98 | |
---|
99 | int ambapp_find_ahbslv(struct ambapp_bus *abus, int vendor, int device, struct ambapp_ahb_info *dev) |
---|
100 | { |
---|
101 | return ambapp_find_ahbslvs_next(abus, vendor, device, dev, 0, 1); |
---|
102 | } |
---|
103 | |
---|
104 | int ambapp_find_ahbslvs(struct ambapp_bus *abus, int vendor, int device, struct ambapp_ahb_info *dev, int maxno) |
---|
105 | { |
---|
106 | return ambapp_find_ahbslvs_next(abus, vendor, device, dev, 0, maxno); |
---|
107 | } |
---|
108 | |
---|
109 | int ambapp_get_number_ahbslv_devices(struct ambapp_bus *abus, int vendor, int device) |
---|
110 | { |
---|
111 | return ambapp_dev_count(abus, (OPTIONS_ALL|OPTIONS_AHB_SLVS), vendor, device); |
---|
112 | } |
---|