Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1 | #ifndef DEVICE_RESOURCE_H |
| 2 | #define DEVICE_RESOURCE_H |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 3 | |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 4 | #include <stdint.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 5 | |
| 6 | #define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */ |
| 7 | |
| 8 | #define IORESOURCE_IO 0x00000100 /* Resource type */ |
| 9 | #define IORESOURCE_MEM 0x00000200 |
| 10 | #define IORESOURCE_IRQ 0x00000400 |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 11 | #define IORESOURCE_DRQ 0x00000800 |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 12 | |
| 13 | #define IORESOURCE_PREFETCH 0x00001000 /* No side effects */ |
| 14 | #define IORESOURCE_READONLY 0x00002000 |
| 15 | #define IORESOURCE_CACHEABLE 0x00004000 |
| 16 | #define IORESOURCE_RANGELENGTH 0x00008000 |
| 17 | #define IORESOURCE_SHADOWABLE 0x00010000 |
| 18 | #define IORESOURCE_BUS_HAS_VGA 0x00020000 |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 19 | #define IORESOURCE_SUBTRACTIVE 0x00040000 /* This resource filters all of the unclaimed transactions |
| 20 | * to the bus below. |
| 21 | */ |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 22 | #define IORESOURCE_BRIDGE 0x00080000 /* The IO resource has a bus below it. */ |
Stefan Reinauer | d6b4f1c | 2010-09-23 18:29:40 +0000 | [diff] [blame^] | 23 | #define IORESOURCE_RESERVE 0x10000000 /* The resource needs to be reserved in the coreboot table */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 24 | #define IORESOURCE_STORED 0x20000000 /* The IO resource assignment has been stored in the device */ |
| 25 | #define IORESOURCE_ASSIGNED 0x40000000 /* An IO resource that has been assigned a value */ |
| 26 | #define IORESOURCE_FIXED 0x80000000 /* An IO resource the allocator must not change */ |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 27 | |
| 28 | /* PCI specific resource bits */ |
| 29 | #define IORESOURCE_PCI64 (1<<0) /* 64bit long pci resource */ |
| 30 | #define IORESOURCE_PCI_BRIDGE (1<<1) /* A bridge pci resource */ |
| 31 | |
| 32 | /* ISA PnP IRQ specific bits (IORESOURCE_BITS) */ |
| 33 | #define IORESOURCE_IRQ_HIGHEDGE (1<<0) |
| 34 | #define IORESOURCE_IRQ_LOWEDGE (1<<1) |
| 35 | #define IORESOURCE_IRQ_HIGHLEVEL (1<<2) |
| 36 | #define IORESOURCE_IRQ_LOWLEVEL (1<<3) |
| 37 | |
| 38 | /* ISA PnP DMA specific bits (IORESOURCE_BITS) */ |
| 39 | #define IORESOURCE_DMA_TYPE_MASK (3<<0) |
| 40 | #define IORESOURCE_DMA_8BIT (0<<0) |
| 41 | #define IORESOURCE_DMA_8AND16BIT (1<<0) |
| 42 | #define IORESOURCE_DMA_16BIT (2<<0) |
| 43 | |
| 44 | #define IORESOURCE_DMA_MASTER (1<<2) |
| 45 | #define IORESOURCE_DMA_BYTE (1<<3) |
| 46 | #define IORESOURCE_DMA_WORD (1<<4) |
| 47 | |
| 48 | #define IORESOURCE_DMA_SPEED_MASK (3<<6) |
| 49 | #define IORESOURCE_DMA_COMPATIBLE (0<<6) |
| 50 | #define IORESOURCE_DMA_TYPEA (1<<6) |
| 51 | #define IORESOURCE_DMA_TYPEB (2<<6) |
| 52 | #define IORESOURCE_DMA_TYPEF (3<<6) |
| 53 | |
| 54 | |
| 55 | /* ISA PnP memory I/O specific bits (IORESOURCE_BITS) */ |
| 56 | #define IORESOURCE_MEM_WRITEABLE (1<<0) /* dup: IORESOURCE_READONLY */ |
| 57 | #define IORESOURCE_MEM_CACHEABLE (1<<1) /* dup: IORESOURCE_CACHEABLE */ |
| 58 | #define IORESOURCE_MEM_RANGELENGTH (1<<2) /* dup: IORESOURCE_RANGELENGTH */ |
| 59 | #define IORESOURCE_MEM_TYPE_MASK (3<<3) |
| 60 | #define IORESOURCE_MEM_8BIT (0<<3) |
| 61 | #define IORESOURCE_MEM_16BIT (1<<3) |
| 62 | #define IORESOURCE_MEM_8AND16BIT (2<<3) |
| 63 | #define IORESOURCE_MEM_SHADOWABLE (1<<5) /* dup: IORESOURCE_SHADOWABLE */ |
| 64 | #define IORESOURCE_MEM_EXPANSIONROM (1<<6) |
| 65 | |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 66 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 67 | typedef u64 resource_t; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 68 | struct resource { |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 69 | resource_t base; /* Base address of the resource */ |
| 70 | resource_t size; /* Size of the resource */ |
| 71 | resource_t limit; /* Largest valid value base + size -1 */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 72 | struct resource* next; /* Next resource in the list */ |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 73 | unsigned long flags; /* Descriptions of the kind of resource */ |
| 74 | unsigned long index; /* Bus specific per device resource id */ |
Li-Ta Lo | e3c79ed | 2004-03-19 00:08:48 +0000 | [diff] [blame] | 75 | unsigned char align; /* Required alignment (log 2) of the resource */ |
| 76 | unsigned char gran; /* Granularity (log 2) of the resource */ |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 77 | /* Alignment must be >= the granularity of the resource */ |
| 78 | }; |
| 79 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 80 | /* Macros to generate index values for resources */ |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 81 | #define IOINDEX_SUBTRACTIVE(IDX,LINK) (0x10000000 + ((IDX) << 8) + LINK) |
| 82 | #define IOINDEX_SUBTRACTIVE_LINK(IDX) (IDX & 0xff) |
| 83 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 84 | #define IOINDEX(IDX,LINK) (((LINK) << 16) + IDX) |
| 85 | #define IOINDEX_LINK(IDX) (( IDX & 0xf0000) >> 16) |
| 86 | #define IOINDEX_IDX(IDX) (IDX & 0xffff) |
| 87 | |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 88 | /* Generic resource helper functions */ |
| 89 | struct device; |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 90 | struct bus; |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 91 | extern void compact_resources(struct device * dev); |
| 92 | extern struct resource *probe_resource(struct device *dev, unsigned index); |
| 93 | extern struct resource *new_resource(struct device * dev, unsigned index); |
| 94 | extern struct resource *find_resource(struct device * dev, unsigned index); |
| 95 | extern resource_t resource_end(struct resource *resource); |
| 96 | extern resource_t resource_max(struct resource *resource); |
| 97 | extern void report_resource_stored(struct device * dev, struct resource *resource, const char *comment); |
| 98 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 99 | typedef void (*resource_search_t)(void *gp, struct device *dev, struct resource *res); |
| 100 | extern void search_bus_resources(struct bus *bus, |
| 101 | unsigned long type_mask, unsigned long type, |
| 102 | resource_search_t search, void *gp); |
| 103 | |
| 104 | extern void search_global_resources( |
| 105 | unsigned long type_mask, unsigned long type, |
| 106 | resource_search_t search, void *gp); |
| 107 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 108 | #define RESOURCE_TYPE_MAX 20 |
| 109 | extern const char *resource_type(struct resource *resource); |
| 110 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 111 | #endif /* DEVICE_RESOURCE_H */ |