File indexing completed on 2025-05-11 08:23:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #ifndef __AMBAPP_H__
0035 #define __AMBAPP_H__
0036
0037 #include <stddef.h>
0038
0039
0040 #include "ambapp_ids.h"
0041
0042 #ifdef __cplusplus
0043 extern "C" {
0044 #endif
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 #define AHB_BUS_MAX 6
0058
0059 #define AMBAPP_FLAG_FFACT_DIR 0x100
0060 #define AMBAPP_FLAG_FFACT 0x0f0
0061 #define AMBAPP_FLAG_MBUS 0x00c
0062 #define AMBAPP_FLAG_SBUS 0x003
0063
0064
0065 #define DEV_TO_APB(adev) ((struct ambapp_apb_info *)((adev)->devinfo))
0066 #define DEV_TO_AHB(adev) ((struct ambapp_ahb_info *)((adev)->devinfo))
0067 #define DEV_TO_COMMON(adev) (((adev)->devinfo))
0068
0069 struct ambapp_common_info {
0070 unsigned char irq;
0071 unsigned char ver;
0072 unsigned char ahbidx;
0073 };
0074
0075 struct ambapp_apb_info {
0076 struct ambapp_common_info common;
0077
0078
0079 unsigned int start;
0080 unsigned int mask;
0081 };
0082
0083 struct ambapp_ahb_info {
0084 struct ambapp_common_info common;
0085
0086
0087 unsigned int start[4];
0088 unsigned int mask[4];
0089 char type[4];
0090
0091 unsigned int custom[3];
0092 };
0093
0094 struct ambapp_dev {
0095 struct ambapp_dev *next;
0096 struct ambapp_dev *prev;
0097
0098 struct ambapp_dev *children;
0099 void *owner;
0100 unsigned char dev_type;
0101 unsigned char vendor;
0102 unsigned short device;
0103
0104
0105 struct ambapp_common_info devinfo[0];
0106 };
0107
0108
0109 struct ambapp_core {
0110 char irq;
0111 unsigned char vendor;
0112 unsigned short device;
0113 int index;
0114 struct ambapp_ahb_info *ahb_mst;
0115 struct ambapp_ahb_info *ahb_slv;
0116 struct ambapp_apb_info *apb_slv;
0117 };
0118
0119 struct ambapp_ahb_bus {
0120 unsigned int ioarea;
0121 unsigned int freq_hz;
0122 struct ambapp_dev *bridge;
0123 struct ambapp_dev *dev;
0124 };
0125
0126 struct ambapp_mmap {
0127 unsigned int size;
0128 unsigned int local_adr;
0129 unsigned int remote_adr;
0130 };
0131
0132
0133 struct ambapp_bus {
0134 struct ambapp_dev *root;
0135 struct ambapp_mmap *mmaps;
0136 struct ambapp_ahb_bus ahbs[AHB_BUS_MAX];
0137 };
0138
0139
0140
0141
0142
0143
0144 typedef int (*ambapp_func_t)(struct ambapp_dev *dev, int index, void *arg);
0145
0146 #define DEV_IS_FREE(dev) (dev->owner == NULL)
0147 #define DEV_IS_ALLOCATED(dev) (dev->owner != NULL)
0148
0149
0150 #define OPTIONS_AHB_MSTS 0x00000001
0151 #define OPTIONS_AHB_SLVS 0x00000002
0152 #define OPTIONS_APB_SLVS 0x00000004
0153 #define OPTIONS_ALL_DEVS (OPTIONS_AHB_MSTS|OPTIONS_AHB_SLVS|OPTIONS_APB_SLVS)
0154
0155 #define OPTIONS_FREE 0x00000010
0156 #define OPTIONS_ALLOCATED 0x00000020
0157 #define OPTIONS_ALL (OPTIONS_FREE|OPTIONS_ALLOCATED)
0158
0159
0160 #define OPTIONS_DEPTH_FIRST 0x00000100
0161
0162 #define DEV_AHB_NONE 0
0163 #define DEV_AHB_MST 1
0164 #define DEV_AHB_SLV 2
0165 #define DEV_APB_SLV 3
0166
0167
0168 struct ambapp_pnp_ahb {
0169 const unsigned int id;
0170 const unsigned int custom[3];
0171 const unsigned int mbar[4];
0172 };
0173
0174 struct ambapp_pnp_apb {
0175 const unsigned int id;
0176 const unsigned int iobar;
0177 };
0178
0179 #define ambapp_pnp_vendor(id) (((id) >> 24) & 0xff)
0180 #define ambapp_pnp_device(id) (((id) >> 12) & 0xfff)
0181 #define ambapp_pnp_ver(id) (((id)>>5) & 0x1f)
0182 #define ambapp_pnp_irq(id) ((id) & 0x1f)
0183
0184 #define ambapp_pnp_start(mbar) (((mbar) & 0xfff00000) & (((mbar) & 0xfff0) << 16))
0185 #define ambapp_pnp_mbar_mask(mbar) (((mbar)>>4) & 0xfff)
0186 #define ambapp_pnp_mbar_type(mbar) ((mbar) & 0xf)
0187
0188 #define ambapp_pnp_apb_start(iobar, base) ((base) | ((((iobar) & 0xfff00000)>>12) & (((iobar) & 0xfff0)<<4)) )
0189 #define ambapp_pnp_apb_mask(iobar) ((~(ambapp_pnp_mbar_mask(iobar)<<8) & 0x000fffff) + 1)
0190
0191 #define AMBA_TYPE_AHBIO_ADDR(addr,base_ioarea) ((unsigned int)(base_ioarea) | ((addr) >> 12))
0192
0193 #define AMBA_TYPE_APBIO 0x1
0194 #define AMBA_TYPE_MEM 0x2
0195 #define AMBA_TYPE_AHBIO 0x3
0196
0197
0198 typedef void *(*ambapp_memcpy_t)(
0199 void *dest,
0200 const void *src,
0201 int n,
0202 struct ambapp_bus *abus
0203 );
0204
0205 struct ambapp_context {
0206 ambapp_memcpy_t copy_from_device;
0207 void *(*alloc)(size_t);
0208 };
0209
0210
0211
0212
0213 extern struct ambapp_bus *ambapp_plb(void);
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228 extern int ambapp_scan(
0229 struct ambapp_bus *abus,
0230 unsigned int ioarea,
0231 const struct ambapp_context *ctx,
0232 struct ambapp_mmap *mmaps
0233 );
0234
0235
0236
0237
0238 extern void ambapp_freq_init(
0239 struct ambapp_bus *abus,
0240 struct ambapp_dev *dev,
0241 unsigned int freq);
0242
0243
0244 extern unsigned int ambapp_freq_get(
0245 struct ambapp_bus *abus,
0246 struct ambapp_dev *dev);
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274 extern int ambapp_for_each(
0275 struct ambapp_bus *abus,
0276 unsigned int options,
0277 int vendor,
0278 int device,
0279 ambapp_func_t func,
0280 void *arg);
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291 extern int ambapp_find_by_idx(struct ambapp_dev *dev, int index, void *pcount);
0292
0293
0294
0295
0296 extern int ambapp_dev_count(struct ambapp_bus *abus, unsigned int options,
0297 int vendor, int device);
0298
0299
0300 extern void ambapp_print(struct ambapp_bus *abus, int show_depth);
0301
0302
0303
0304
0305 extern int ambapp_alloc_dev(struct ambapp_dev *dev, void *owner);
0306
0307
0308 extern void ambapp_free_dev(struct ambapp_dev *dev);
0309
0310
0311 extern struct ambapp_dev *ambapp_find_parent(struct ambapp_dev *dev);
0312
0313
0314 extern int ambapp_depth(struct ambapp_dev *dev);
0315
0316
0317 extern char *ambapp_device_id2str(int vendor, int id);
0318
0319
0320 extern char *ambapp_vendor_id2str(int vendor);
0321
0322
0323
0324
0325 extern int ambapp_vendev_id2str(int vendor, int id, char *buf);
0326
0327
0328
0329 extern int ambapp_find_apbslv(
0330 struct ambapp_bus *abus,
0331 int vendor,
0332 int device,
0333 struct ambapp_apb_info *dev);
0334
0335 extern int ambapp_find_apbslv_next(
0336 struct ambapp_bus *abus,
0337 int vendor,
0338 int device,
0339 struct ambapp_apb_info *dev,
0340 int index);
0341
0342 extern int ambapp_find_apbslvs_next(
0343 struct ambapp_bus *abus,
0344 int vendor,
0345 int device,
0346 struct ambapp_apb_info *dev,
0347 int index,
0348 int maxno);
0349
0350 extern int ambapp_find_apbslvs(
0351 struct ambapp_bus *abus,
0352 int vendor,
0353 int device,
0354 struct ambapp_apb_info *dev,
0355 int maxno);
0356
0357 extern int ambapp_find_ahbslv(
0358 struct ambapp_bus *abus,
0359 int vendor,
0360 int device,
0361 struct ambapp_ahb_info *dev);
0362
0363 extern int ambapp_find_ahbslv_next(
0364 struct ambapp_bus *abus,
0365 int vendor,
0366 int device,
0367 struct ambapp_ahb_info *dev,
0368 int index);
0369
0370 extern int ambapp_find_ahbslvs_next(
0371 struct ambapp_bus *abus,
0372 int vendor,
0373 int device,
0374 struct ambapp_ahb_info *dev,
0375 int index,
0376 int maxno);
0377
0378 extern int ambapp_find_ahbslvs(
0379 struct ambapp_bus *abus,
0380 int vendor,
0381 int device,
0382 struct ambapp_ahb_info *dev,
0383 int maxno);
0384
0385
0386 extern int ambapp_get_number_ahbslv_devices(
0387 struct ambapp_bus *abus,
0388 int vendor,
0389 int device);
0390
0391 extern int ambapp_get_number_apbslv_devices(
0392 struct ambapp_bus *abus,
0393 int vendor,
0394 int device);
0395
0396 #ifdef __cplusplus
0397 }
0398 #endif
0399
0400
0401
0402 #endif