File indexing completed on 2025-01-29 10:21:38
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
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 #ifndef PCIACCESS_H
0058 #define PCIACCESS_H
0059
0060 #include <inttypes.h>
0061
0062 #if (__GNUC__ >= 3) || (__SUNPRO_C >= 0x5130)
0063 #define __deprecated __attribute__((deprecated))
0064 #else
0065 #define __deprecated
0066 #endif
0067
0068 typedef uint64_t pciaddr_t;
0069
0070 struct pci_device;
0071 struct pci_device_iterator;
0072 struct pci_id_match;
0073 struct pci_slot_match;
0074
0075 #ifdef __cplusplus
0076 extern "C" {
0077 #endif
0078
0079 int pci_device_has_kernel_driver(struct pci_device *dev);
0080
0081 int pci_device_is_boot_vga(struct pci_device *dev);
0082
0083 int pci_device_read_rom(struct pci_device *dev, void *buffer);
0084
0085 int __deprecated pci_device_map_region(struct pci_device *dev,
0086 unsigned region, int write_enable);
0087
0088 int __deprecated pci_device_unmap_region(struct pci_device *dev,
0089 unsigned region);
0090
0091 int pci_device_map_range(struct pci_device *dev, pciaddr_t base,
0092 pciaddr_t size, unsigned map_flags, void **addr);
0093
0094 int pci_device_unmap_range(struct pci_device *dev, void *memory,
0095 pciaddr_t size);
0096
0097 int __deprecated pci_device_map_memory_range(struct pci_device *dev,
0098 pciaddr_t base, pciaddr_t size, int write_enable, void **addr);
0099
0100 int __deprecated pci_device_unmap_memory_range(struct pci_device *dev,
0101 void *memory, pciaddr_t size);
0102
0103 int pci_device_probe(struct pci_device *dev);
0104
0105 const struct pci_agp_info *pci_device_get_agp_info(struct pci_device *dev);
0106
0107 const struct pci_bridge_info *pci_device_get_bridge_info(
0108 struct pci_device *dev);
0109
0110 const struct pci_pcmcia_bridge_info *pci_device_get_pcmcia_bridge_info(
0111 struct pci_device *dev);
0112
0113 int pci_device_get_bridge_buses(struct pci_device *dev, int *primary_bus,
0114 int *secondary_bus, int *subordinate_bus);
0115
0116 int pci_system_init(void);
0117
0118 void pci_system_init_dev_mem(int fd);
0119
0120 void pci_system_cleanup(void);
0121
0122 struct pci_device_iterator *pci_slot_match_iterator_create(
0123 const struct pci_slot_match *match);
0124
0125 struct pci_device_iterator *pci_id_match_iterator_create(
0126 const struct pci_id_match *match);
0127
0128 void pci_iterator_destroy(struct pci_device_iterator *iter);
0129
0130 struct pci_device *pci_device_next(struct pci_device_iterator *iter);
0131
0132 struct pci_device *pci_device_find_by_slot(uint32_t domain, uint32_t bus,
0133 uint32_t dev, uint32_t func);
0134
0135 struct pci_device *pci_device_get_parent_bridge(struct pci_device *dev);
0136
0137 void pci_get_strings(const struct pci_id_match *m,
0138 const char **device_name, const char **vendor_name,
0139 const char **subdevice_name, const char **subvendor_name);
0140 const char *pci_device_get_device_name(const struct pci_device *dev);
0141 const char *pci_device_get_subdevice_name(const struct pci_device *dev);
0142 const char *pci_device_get_vendor_name(const struct pci_device *dev);
0143 const char *pci_device_get_subvendor_name(const struct pci_device *dev);
0144
0145 void pci_device_enable(struct pci_device *dev);
0146 void pci_device_disable(struct pci_device *dev);
0147
0148 int pci_device_cfg_read (struct pci_device *dev, void *data,
0149 pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_read);
0150 int pci_device_cfg_read_u8 (struct pci_device *dev, uint8_t *data,
0151 pciaddr_t offset);
0152 int pci_device_cfg_read_u16(struct pci_device *dev, uint16_t *data,
0153 pciaddr_t offset);
0154 int pci_device_cfg_read_u32(struct pci_device *dev, uint32_t *data,
0155 pciaddr_t offset);
0156
0157 int pci_device_cfg_write (struct pci_device *dev, const void *data,
0158 pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_written);
0159 int pci_device_cfg_write_u8 (struct pci_device *dev, uint8_t data,
0160 pciaddr_t offset);
0161 int pci_device_cfg_write_u16(struct pci_device *dev, uint16_t data,
0162 pciaddr_t offset);
0163 int pci_device_cfg_write_u32(struct pci_device *dev, uint32_t data,
0164 pciaddr_t offset);
0165 int pci_device_cfg_write_bits(struct pci_device *dev, uint32_t mask,
0166 uint32_t data, pciaddr_t offset);
0167
0168 #ifdef __cplusplus
0169 }
0170 #endif
0171
0172
0173
0174
0175
0176 #define PCI_DEV_MAP_FLAG_WRITABLE (1U<<0)
0177 #define PCI_DEV_MAP_FLAG_WRITE_COMBINE (1U<<1)
0178 #define PCI_DEV_MAP_FLAG_CACHABLE (1U<<2)
0179
0180
0181
0182 #define PCI_MATCH_ANY (~0U)
0183
0184
0185
0186
0187
0188
0189 #define PCI_ID_COMPARE(a, b) \
0190 (((a) == PCI_MATCH_ANY) || ((a) == (b)))
0191
0192
0193
0194 struct pci_id_match {
0195
0196
0197
0198
0199
0200
0201
0202
0203 uint32_t vendor_id;
0204 uint32_t device_id;
0205 uint32_t subvendor_id;
0206 uint32_t subdevice_id;
0207
0208
0209
0210
0211
0212
0213
0214
0215 uint32_t device_class;
0216 uint32_t device_class_mask;
0217
0218
0219 intptr_t match_data;
0220 };
0221
0222
0223
0224
0225 struct pci_slot_match {
0226
0227
0228
0229
0230
0231
0232
0233
0234 uint32_t domain;
0235 uint32_t bus;
0236 uint32_t dev;
0237 uint32_t func;
0238
0239
0240 intptr_t match_data;
0241 };
0242
0243
0244
0245
0246 struct pci_mem_region {
0247
0248
0249
0250
0251
0252
0253
0254
0255 void *memory;
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269 pciaddr_t bus_addr;
0270
0271
0272
0273
0274
0275
0276
0277
0278 pciaddr_t base_addr;
0279
0280
0281
0282
0283
0284 pciaddr_t size;
0285
0286
0287
0288
0289
0290 unsigned is_IO:1;
0291
0292
0293
0294
0295
0296
0297
0298 unsigned is_prefetchable:1;
0299
0300
0301
0302
0303
0304
0305
0306
0307 unsigned is_64:1;
0308 };
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320 struct pci_device {
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332 uint16_t domain_16;
0333 uint8_t bus;
0334 uint8_t dev;
0335 uint8_t func;
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345 uint16_t vendor_id;
0346 uint16_t device_id;
0347 uint16_t subvendor_id;
0348 uint16_t subdevice_id;
0349
0350
0351
0352
0353
0354
0355
0356 uint32_t device_class;
0357
0358
0359
0360
0361
0362 uint8_t revision;
0363
0364
0365
0366
0367
0368 struct pci_mem_region regions[6];
0369
0370
0371
0372
0373
0374 pciaddr_t rom_size;
0375
0376
0377
0378
0379
0380
0381 int irq;
0382
0383
0384
0385
0386
0387
0388
0389
0390 intptr_t user_data;
0391
0392
0393
0394
0395 int vgaarb_rsrc;
0396
0397
0398
0399
0400
0401 uint32_t domain;
0402 };
0403
0404
0405
0406
0407
0408
0409
0410 struct pci_agp_info {
0411
0412
0413
0414
0415
0416 unsigned config_offset;
0417
0418
0419
0420
0421
0422
0423 uint8_t major_version;
0424 uint8_t minor_version;
0425
0426
0427
0428
0429
0430
0431
0432 uint8_t rates;
0433
0434 unsigned int fast_writes:1;
0435 unsigned int addr64:1;
0436 unsigned int htrans:1;
0437 unsigned int gart64:1;
0438 unsigned int coherent:1;
0439 unsigned int sideband:1;
0440 unsigned int isochronus:1;
0441
0442 uint8_t async_req_size;
0443 uint8_t calibration_cycle_timing;
0444 uint8_t max_requests;
0445 };
0446
0447
0448
0449
0450
0451
0452 struct pci_bridge_info {
0453 uint8_t primary_bus;
0454 uint8_t secondary_bus;
0455 uint8_t subordinate_bus;
0456 uint8_t secondary_latency_timer;
0457
0458 uint8_t io_type;
0459 uint8_t mem_type;
0460 uint8_t prefetch_mem_type;
0461
0462 uint16_t secondary_status;
0463 uint16_t bridge_control;
0464
0465 uint32_t io_base;
0466 uint32_t io_limit;
0467
0468 uint32_t mem_base;
0469 uint32_t mem_limit;
0470
0471 uint64_t prefetch_mem_base;
0472 uint64_t prefetch_mem_limit;
0473 };
0474
0475
0476
0477
0478
0479
0480 struct pci_pcmcia_bridge_info {
0481 uint8_t primary_bus;
0482 uint8_t card_bus;
0483 uint8_t subordinate_bus;
0484 uint8_t cardbus_latency_timer;
0485
0486 uint16_t secondary_status;
0487 uint16_t bridge_control;
0488
0489 struct {
0490 uint32_t base;
0491 uint32_t limit;
0492 } io[2];
0493
0494 struct {
0495 uint32_t base;
0496 uint32_t limit;
0497 } mem[2];
0498
0499 };
0500
0501
0502
0503
0504
0505
0506
0507 #define VGA_ARB_RSRC_NONE 0x00
0508 #define VGA_ARB_RSRC_LEGACY_IO 0x01
0509 #define VGA_ARB_RSRC_LEGACY_MEM 0x02
0510
0511 #define VGA_ARB_RSRC_NORMAL_IO 0x04
0512 #define VGA_ARB_RSRC_NORMAL_MEM 0x08
0513
0514 int pci_device_vgaarb_init (void);
0515 void pci_device_vgaarb_fini (void);
0516 int pci_device_vgaarb_set_target (struct pci_device *dev);
0517
0518 int pci_device_vgaarb_decodes (int new_vga_rsrc);
0519 int pci_device_vgaarb_lock (void);
0520 int pci_device_vgaarb_trylock (void);
0521 int pci_device_vgaarb_unlock (void);
0522
0523 int pci_device_vgaarb_get_info (struct pci_device *dev, int *vga_count, int *rsrc_decodes);
0524
0525
0526
0527
0528
0529 struct pci_io_handle;
0530
0531 struct pci_io_handle *pci_device_open_io(struct pci_device *dev, pciaddr_t base,
0532 pciaddr_t size);
0533 struct pci_io_handle *pci_legacy_open_io(struct pci_device *dev, pciaddr_t base,
0534 pciaddr_t size);
0535 void pci_device_close_io(struct pci_device *dev, struct pci_io_handle *handle);
0536 uint32_t pci_io_read32(struct pci_io_handle *handle, uint32_t reg);
0537 uint16_t pci_io_read16(struct pci_io_handle *handle, uint32_t reg);
0538 uint8_t pci_io_read8(struct pci_io_handle *handle, uint32_t reg);
0539 void pci_io_write32(struct pci_io_handle *handle, uint32_t reg, uint32_t data);
0540 void pci_io_write16(struct pci_io_handle *handle, uint32_t reg, uint16_t data);
0541 void pci_io_write8(struct pci_io_handle *handle, uint32_t reg, uint8_t data);
0542
0543
0544
0545
0546
0547 int pci_device_map_legacy(struct pci_device *dev, pciaddr_t base,
0548 pciaddr_t size, unsigned map_flags, void **addr);
0549 int pci_device_unmap_legacy(struct pci_device *dev, void *addr, pciaddr_t size);
0550
0551 #endif