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