blob: 1b2b0169dc05417411e190a37522ce6f5c1e35af [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>
Eric Biedermane9a271e32003-09-02 03:36:25 +00006#include <device/path.h>
Eric Biederman5899fd82003-04-24 06:25:08 +00007
8struct device;
Eric Biederman7a5416a2003-06-12 19:23:51 +00009typedef struct device * device_t;
10
Eric Biederman5899fd82003-04-24 06:25:08 +000011struct device_operations {
Eric Biederman7a5416a2003-06-12 19:23:51 +000012 void (*read_resources)(device_t dev);
13 void (*set_resources)(device_t dev);
Eric Biedermane9a271e32003-09-02 03:36:25 +000014 void (*enable_resources)(device_t dev);
Eric Biederman7a5416a2003-06-12 19:23:51 +000015 void (*init)(device_t dev);
16 unsigned int (*scan_bus)(device_t bus, unsigned int max);
Eric Biederman4086d162003-07-17 03:26:03 +000017 void (*enable)(device_t dev);
Eric Biederman5899fd82003-04-24 06:25:08 +000018};
19
20
Eric Biedermane9a271e32003-09-02 03:36:25 +000021struct bus {
22 device_t dev; /* This bridge device */
23 device_t children; /* devices behind this bridge */
24 unsigned bridge_ctrl; /* Bridge control register */
25 unsigned char link; /* The index of this link */
26 unsigned char secondary; /* secondary bus number */
27 unsigned char subordinate; /* max subordinate bus number */
28 unsigned char cap; /* PCi capability offset */
29};
30
Eric Biederman5899fd82003-04-24 06:25:08 +000031#define MAX_RESOURCES 6
Eric Biedermane9a271e32003-09-02 03:36:25 +000032#define MAX_LINKS 3
Eric Biederman5899fd82003-04-24 06:25:08 +000033/*
Eric Biederman2c018fb2003-07-21 20:13:45 +000034 * There is one device structure for each slot-number/function-number
Eric Biederman5899fd82003-04-24 06:25:08 +000035 * combination:
36 */
37
Eric Biederman83b991a2003-10-11 06:20:25 +000038struct chip;
Eric Biederman5899fd82003-04-24 06:25:08 +000039struct device {
Eric Biedermane9a271e32003-09-02 03:36:25 +000040 struct bus * bus; /* bus this device is on */
41 device_t sibling; /* next device on this bus */
42 device_t next; /* chain of all devices */
Eric Biederman5899fd82003-04-24 06:25:08 +000043
Eric Biedermane9a271e32003-09-02 03:36:25 +000044 struct device_path path;
Eric Biederman5899fd82003-04-24 06:25:08 +000045 unsigned short vendor;
46 unsigned short device;
47 unsigned int class; /* 3 bytes: (base,sub,prog-if) */
48 unsigned int hdr_type; /* PCI header type */
Eric Biederman4086d162003-07-17 03:26:03 +000049 unsigned int enable : 1; /* set if we should enable the device */
Eric Biederman5899fd82003-04-24 06:25:08 +000050
Eric Biederman5899fd82003-04-24 06:25:08 +000051 uint8_t command;
52 /*
53 * In theory, the irq level can be read from configuration
54 * space and all would be fine. However, old PCI chips don't
55 * support these registers and return 0 instead. For example,
56 * the Vision864-P rev 0 chip can uses INTA, but returns 0 in
57 * the interrupt line and pin registers. pci_init()
58 * initializes this field with the value at PCI_INTERRUPT_LINE
59 * and it is the job of pcibios_fixup() to change it if
60 * necessary. The field must not be 0 unless the device
61 * cannot generate interrupts at all.
62 */
63 unsigned int irq; /* irq generated by this device */
64
65 /* Base registers for this device, can be adjusted by
66 * pcibios_fixup() as necessary.
67 */
68 struct resource resource[MAX_RESOURCES];
69 unsigned int resources;
Eric Biedermane9a271e32003-09-02 03:36:25 +000070
71 struct bus link[MAX_LINKS];
72 unsigned int links;
73
Eric Biederman5899fd82003-04-24 06:25:08 +000074 unsigned long rom_address;
75 struct device_operations *ops;
Eric Biederman83b991a2003-10-11 06:20:25 +000076 struct chip *chip;
Eric Biederman5899fd82003-04-24 06:25:08 +000077};
78
79extern struct device dev_root; /* root bus */
80extern struct device *all_devices; /* list of all devices */
81
82
83/* Generic device interface functions */
Eric Biedermane9a271e32003-09-02 03:36:25 +000084extern device_t alloc_dev(struct bus *parent, struct device_path *path);
Eric Biederman5899fd82003-04-24 06:25:08 +000085extern void dev_enumerate(void);
86extern void dev_configure(void);
87extern void dev_enable(void);
88extern void dev_initialize(void);
89
90/* Generic device helper functions */
Eric Biedermane9a271e32003-09-02 03:36:25 +000091extern void compute_allocate_resource(struct bus *bus, struct resource *bridge,
Eric Biederman5899fd82003-04-24 06:25:08 +000092 unsigned long type_mask, unsigned long type);
Eric Biedermane9a271e32003-09-02 03:36:25 +000093extern void assign_resources(struct bus *bus);
94extern void enable_resources(struct device *dev);
95extern void enumerate_static_device(void);
96extern const char *dev_path(device_t dev);
Eric Biederman5899fd82003-04-24 06:25:08 +000097
98/* Helper functions */
Eric Biederman83b991a2003-10-11 06:20:25 +000099device_t alloc_find_dev(struct bus *parent, struct device_path *path);
Eric Biederman7a5416a2003-06-12 19:23:51 +0000100device_t dev_find_device (unsigned int vendor, unsigned int device, device_t from);
101device_t dev_find_class (unsigned int class, device_t from);
102device_t dev_find_slot (unsigned int bus, unsigned int devfn);
Eric Biederman5899fd82003-04-24 06:25:08 +0000103
104/* Rounding for boundaries.
105 * Due to some chip bugs, go ahead and roung IO to 16
106 */
107#define DEVICE_IO_ALIGN 16
108#define DEVICE_MEM_ALIGN 4096
109
Eric Biedermane9a271e32003-09-02 03:36:25 +0000110struct device_operations default_dev_ops_root;
111extern void root_dev_read_resources(device_t dev);
112extern void root_dev_set_resources(device_t dev);
113extern unsigned int walk_static_devices(device_t bus, unsigned int max);
114extern void enable_childrens_resources(device_t dev);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000115extern unsigned int root_dev_scan_pci_bus(device_t root, unsigned int max);
Eric Biederman5899fd82003-04-24 06:25:08 +0000116
117#endif /* DEVICE_H */