blob: 21e5dfc5c89436778fe5ec550b9faf31c5ea892a [file] [log] [blame]
Eric Biederman5899fd82003-04-24 06:25:08 +00001#ifndef DEVICE_H
2#define DEVICE_H
3
Eric Biederman9bdb4602003-09-01 23:17:58 +00004#include <stdint.h>
Eric Biederman5899fd82003-04-24 06:25:08 +00005#include <device/resource.h>
6
7struct device;
Eric Biederman7a5416a2003-06-12 19:23:51 +00008typedef struct device * device_t;
9
Eric Biederman5899fd82003-04-24 06:25:08 +000010struct device_operations {
Eric Biederman7a5416a2003-06-12 19:23:51 +000011 void (*read_resources)(device_t dev);
12 void (*set_resources)(device_t dev);
13 void (*init)(device_t dev);
14 unsigned int (*scan_bus)(device_t bus, unsigned int max);
Eric Biederman4086d162003-07-17 03:26:03 +000015 void (*enable)(device_t dev);
Eric Biederman5899fd82003-04-24 06:25:08 +000016};
17
18
19#define MAX_RESOURCES 6
20/*
Eric Biederman2c018fb2003-07-21 20:13:45 +000021 * There is one device structure for each slot-number/function-number
Eric Biederman5899fd82003-04-24 06:25:08 +000022 * combination:
23 */
24
25struct device {
Eric Biederman7a5416a2003-06-12 19:23:51 +000026 device_t bus; /* bus this device is on */
27 device_t children; /* devices behind this bridge */
28 device_t sibling; /* next device on this bus */
29 device_t next; /* chain of all devices */
Eric Biederman5899fd82003-04-24 06:25:08 +000030
31 unsigned int devfn; /* encoded device & function index */
32 unsigned short vendor;
33 unsigned short device;
34 unsigned int class; /* 3 bytes: (base,sub,prog-if) */
35 unsigned int hdr_type; /* PCI header type */
Eric Biederman4086d162003-07-17 03:26:03 +000036 unsigned int enable : 1; /* set if we should enable the device */
Eric Biederman5899fd82003-04-24 06:25:08 +000037
38 unsigned char secondary; /* secondary bus number */
39 unsigned char subordinate; /* max subordinate bus number */
40 uint8_t command;
41 /*
42 * In theory, the irq level can be read from configuration
43 * space and all would be fine. However, old PCI chips don't
44 * support these registers and return 0 instead. For example,
45 * the Vision864-P rev 0 chip can uses INTA, but returns 0 in
46 * the interrupt line and pin registers. pci_init()
47 * initializes this field with the value at PCI_INTERRUPT_LINE
48 * and it is the job of pcibios_fixup() to change it if
49 * necessary. The field must not be 0 unless the device
50 * cannot generate interrupts at all.
51 */
52 unsigned int irq; /* irq generated by this device */
53
54 /* Base registers for this device, can be adjusted by
55 * pcibios_fixup() as necessary.
56 */
57 struct resource resource[MAX_RESOURCES];
58 unsigned int resources;
59 unsigned long rom_address;
60 struct device_operations *ops;
Eric Biederman5899fd82003-04-24 06:25:08 +000061};
62
63extern struct device dev_root; /* root bus */
64extern struct device *all_devices; /* list of all devices */
65
66
67/* Generic device interface functions */
68extern void dev_enumerate(void);
69extern void dev_configure(void);
70extern void dev_enable(void);
71extern void dev_initialize(void);
72
73/* Generic device helper functions */
Eric Biederman7a5416a2003-06-12 19:23:51 +000074void append_device(device_t dev);
75void compute_allocate_resource(device_t bus, struct resource *bridge,
Eric Biederman5899fd82003-04-24 06:25:08 +000076 unsigned long type_mask, unsigned long type);
Eric Biederman7a5416a2003-06-12 19:23:51 +000077void assign_resources(device_t bus);
Eric Biederman5899fd82003-04-24 06:25:08 +000078void enumerate_static_device(void);
Eric Biederman5899fd82003-04-24 06:25:08 +000079
80/* Helper functions */
Eric Biederman7a5416a2003-06-12 19:23:51 +000081device_t dev_find_device (unsigned int vendor, unsigned int device, device_t from);
82device_t dev_find_class (unsigned int class, device_t from);
83device_t dev_find_slot (unsigned int bus, unsigned int devfn);
Eric Biederman5899fd82003-04-24 06:25:08 +000084
85/* Rounding for boundaries.
86 * Due to some chip bugs, go ahead and roung IO to 16
87 */
88#define DEVICE_IO_ALIGN 16
89#define DEVICE_MEM_ALIGN 4096
90
91
92#endif /* DEVICE_H */