Subversion Repositories HelenOS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4300 trochtova 1
/*
2
 *  The PCI Library
3
 *
4
 *  Copyright (c) 1997--2005 Martin Mares <mj@ucw.cz>
5
 *
6
 *  May 8, 2006 - Modified and ported to HelenOS by Jakub Jermar.
7
 *
8
 *  Can be freely distributed and used under the terms of the GNU GPL.
9
 */
10
 
11
#ifndef _PCI_LIB_H
12
#define _PCI_LIB_H
13
 
14
#include "header.h"
15
#include "types.h"
16
 
17
#define PCI_LIB_VERSION 0x020200
18
 
19
/*
20
 *  PCI Access Structure
21
 */
22
 
23
struct pci_methods;
24
 
25
enum pci_access_type {
26
    /* Known access methods, remember to update access.c as well */
27
    PCI_ACCESS_I386_TYPE1,  /* i386 ports, type 1 (params: none) */
28
    PCI_ACCESS_I386_TYPE2,  /* i386 ports, type 2 (params: none) */
29
    PCI_ACCESS_US2,
30
    PCI_ACCESS_MAX
31
};
32
 
33
struct pci_access {
34
    /* Options you can change: */
35
    unsigned int method;    /* Access method */
36
    char *method_params[PCI_ACCESS_MAX];    /* Parameters for the methods */
37
    int writeable;      /* Open in read/write mode */
38
    int buscentric;     /* Bus-centric view of the world */
39
    int numeric_ids;    /* Don't resolve device IDs to names */
40
    int debugging;      /* Turn on debugging messages */
41
 
42
    /* Functions you can override: */
43
    void (*error) (char *msg, ...); /* Write error message and quit */
44
    void (*warning) (char *msg, ...);   /* Write a warning message */
45
    void (*debug) (char *msg, ...); /* Write a debugging message */
46
 
47
    struct pci_dev *devices;    /* Devices found on this bus */
48
 
49
    /* Fields used internally: */
50
    struct pci_methods *methods;
51
    struct id_entry **id_hash;  /* names.c */
52
    struct id_bucket *current_id_bucket;
53
};
54
 
55
/* Initialize PCI access */
56
struct pci_access *pci_alloc(void);
57
void pci_init(struct pci_access *);
58
void pci_cleanup(struct pci_access *);
59
 
60
/* Scanning of devices */
61
void pci_scan_bus(struct pci_access *acc);
62
struct pci_dev *pci_get_dev(struct pci_access *acc, int domain, int bus, int dev, int func);    /* Raw access to specified device */
63
void pci_free_dev(struct pci_dev *);
64
 
65
/*
66
 *  Devices
67
 */
68
 
69
struct pci_dev {
70
    struct pci_dev *next;   /* Next device in the chain */
71
    u16 domain;     /* PCI domain (host bridge) */
72
    u8 bus, dev, func;  /* Bus inside domain, device and function */
73
 
74
    /* These fields are set by pci_fill_info() */
75
    int known_fields;   /* Set of info fields already known */
76
    u16 vendor_id, device_id;   /* Identity of the device */
77
    int irq;        /* IRQ number */
78
    pciaddr_t base_addr[6]; /* Base addresses */
79
    pciaddr_t size[6];  /* Region sizes */
80
    pciaddr_t rom_base_addr;    /* Expansion ROM base address */
81
    pciaddr_t rom_size; /* Expansion ROM size */
82
 
83
    /* Fields used internally: */
84
    struct pci_access *access;
85
    struct pci_methods *methods;
86
    u8 *cache;      /* Cached config registers */
87
    int cache_len;
88
    int hdrtype;        /* Cached low 7 bits of header type, -1 if unknown */
89
    void *aux;      /* Auxillary data */
90
};
91
 
92
#define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3)
93
#define PCI_ADDR_MEM_MASK (~(pciaddr_t) 0xf)
94
 
95
u8 pci_read_byte(struct pci_dev *, int pos);    /* Access to configuration space */
96
u16 pci_read_word(struct pci_dev *, int pos);
97
u32 pci_read_long(struct pci_dev *, int pos);
98
int pci_read_block(struct pci_dev *, int pos, u8 * buf, int len);
99
int pci_write_byte(struct pci_dev *, int pos, u8 data);
100
int pci_write_word(struct pci_dev *, int pos, u16 data);
101
int pci_write_long(struct pci_dev *, int pos, u32 data);
102
int pci_write_block(struct pci_dev *, int pos, u8 * buf, int len);
103
 
104
int pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */
105
 
106
#define PCI_FILL_IDENT      1
107
#define PCI_FILL_IRQ        2
108
#define PCI_FILL_BASES      4
109
#define PCI_FILL_ROM_BASE   8
110
#define PCI_FILL_SIZES      16
111
#define PCI_FILL_RESCAN     0x10000
112
 
113
void pci_setup_cache(struct pci_dev *, u8 * cache, int len);
114
 
115
/*
116
 *  Conversion of PCI ID's to names (according to the pci.ids file)
117
 *
118
 *  Call pci_lookup_name() to identify different types of ID's:
119
 *
120
 *  VENDOR              (vendorID) -> vendor
121
 *  DEVICE              (vendorID, deviceID) -> device
122
 *  VENDOR | DEVICE         (vendorID, deviceID) -> combined vendor and device
123
 *  SUBSYSTEM | VENDOR      (subvendorID) -> subsystem vendor
124
 *  SUBSYSTEM | DEVICE      (vendorID, deviceID, subvendorID, subdevID) -> subsystem device
125
 *  SUBSYSTEM | VENDOR | DEVICE (vendorID, deviceID, subvendorID, subdevID) -> combined subsystem v+d
126
 *  SUBSYSTEM | ...         (-1, -1, subvendorID, subdevID) -> generic subsystem
127
 *  CLASS               (classID) -> class
128
 *  PROGIF              (classID, progif) -> programming interface
129
 */
130
 
131
char *pci_lookup_name(struct pci_access *a, char *buf, int size, int flags,
132
              ...);
133
 
134
int pci_load_name_list(struct pci_access *a);   /* Called automatically by pci_lookup_*() when needed; returns success */
135
void pci_free_name_list(struct pci_access *a);  /* Called automatically by pci_cleanup() */
136
 
137
enum pci_lookup_mode {
138
    PCI_LOOKUP_VENDOR = 1/* Vendor name (args: vendorID) */
139
    PCI_LOOKUP_DEVICE = 2/* Device name (args: vendorID, deviceID) */
140
    PCI_LOOKUP_CLASS = 4,   /* Device class (args: classID) */
141
    PCI_LOOKUP_SUBSYSTEM = 8,
142
    PCI_LOOKUP_PROGIF = 16, /* Programming interface (args: classID, prog_if) */
143
    PCI_LOOKUP_NUMERIC = 0x10000,   /* Want only formatted numbers; default if access->numeric_ids is set */
144
    PCI_LOOKUP_NO_NUMBERS = 0x20000 /* Return NULL if not found in the database; default is to print numerically */
145
};
146
 
147
#endif