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> |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 5 | #include <stddef.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 6 | |
| 7 | #define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */ |
| 8 | |
| 9 | #define IORESOURCE_IO 0x00000100 /* Resource type */ |
| 10 | #define IORESOURCE_MEM 0x00000200 |
| 11 | #define IORESOURCE_IRQ 0x00000400 |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 12 | #define IORESOURCE_DRQ 0x00000800 |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 13 | |
| 14 | #define IORESOURCE_PREFETCH 0x00001000 /* No side effects */ |
| 15 | #define IORESOURCE_READONLY 0x00002000 |
| 16 | #define IORESOURCE_CACHEABLE 0x00004000 |
| 17 | #define IORESOURCE_RANGELENGTH 0x00008000 |
| 18 | #define IORESOURCE_SHADOWABLE 0x00010000 |
| 19 | #define IORESOURCE_BUS_HAS_VGA 0x00020000 |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 20 | #define IORESOURCE_SUBTRACTIVE 0x00040000 /* This resource filters all of the unclaimed transactions |
| 21 | * to the bus below. |
| 22 | */ |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 23 | #define IORESOURCE_BRIDGE 0x00080000 /* The IO resource has a bus below it. */ |
Kyösti Mälkki | 0b08515 | 2012-07-11 23:14:49 +0300 | [diff] [blame] | 24 | #define IORESOURCE_UMA_FB 0x00100000 /* UMA framebuffer */ |
Kyösti Mälkki | 1ec5e74 | 2012-07-26 23:51:20 +0300 | [diff] [blame] | 25 | #define IORESOURCE_IGNORE_MTRR 0x00200000 /* The resource does not affect MTRR setup. */ |
Kyösti Mälkki | 0b08515 | 2012-07-11 23:14:49 +0300 | [diff] [blame] | 26 | |
Stefan Reinauer | d6b4f1c | 2010-09-23 18:29:40 +0000 | [diff] [blame] | 27 | #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] | 28 | #define IORESOURCE_STORED 0x20000000 /* The IO resource assignment has been stored in the device */ |
| 29 | #define IORESOURCE_ASSIGNED 0x40000000 /* An IO resource that has been assigned a value */ |
| 30 | #define IORESOURCE_FIXED 0x80000000 /* An IO resource the allocator must not change */ |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 31 | |
Kyösti Mälkki | d2245bb | 2012-08-27 09:09:23 +0300 | [diff] [blame^] | 32 | /* PCI specific resource bits (IORESOURCE_BITS) */ |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 33 | #define IORESOURCE_PCI64 (1<<0) /* 64bit long pci resource */ |
| 34 | #define IORESOURCE_PCI_BRIDGE (1<<1) /* A bridge pci resource */ |
| 35 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 36 | typedef u64 resource_t; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 37 | struct resource { |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 38 | resource_t base; /* Base address of the resource */ |
| 39 | resource_t size; /* Size of the resource */ |
| 40 | resource_t limit; /* Largest valid value base + size -1 */ |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 41 | ROMSTAGE_CONST struct resource* next; /* Next resource in the list */ |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 42 | unsigned long flags; /* Descriptions of the kind of resource */ |
| 43 | unsigned long index; /* Bus specific per device resource id */ |
Li-Ta Lo | e3c79ed | 2004-03-19 00:08:48 +0000 | [diff] [blame] | 44 | unsigned char align; /* Required alignment (log 2) of the resource */ |
| 45 | unsigned char gran; /* Granularity (log 2) of the resource */ |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 46 | /* Alignment must be >= the granularity of the resource */ |
| 47 | }; |
| 48 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 49 | /* Macros to generate index values for resources */ |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 50 | #define IOINDEX_SUBTRACTIVE(IDX,LINK) (0x10000000 + ((IDX) << 8) + LINK) |
| 51 | #define IOINDEX_SUBTRACTIVE_LINK(IDX) (IDX & 0xff) |
| 52 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 53 | #define IOINDEX(IDX,LINK) (((LINK) << 16) + IDX) |
| 54 | #define IOINDEX_LINK(IDX) (( IDX & 0xf0000) >> 16) |
| 55 | #define IOINDEX_IDX(IDX) (IDX & 0xffff) |
| 56 | |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 57 | /* Generic resource helper functions */ |
| 58 | struct device; |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 59 | struct bus; |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 60 | extern void compact_resources(struct device * dev); |
| 61 | extern struct resource *probe_resource(struct device *dev, unsigned index); |
| 62 | extern struct resource *new_resource(struct device * dev, unsigned index); |
| 63 | extern struct resource *find_resource(struct device * dev, unsigned index); |
| 64 | extern resource_t resource_end(struct resource *resource); |
| 65 | extern resource_t resource_max(struct resource *resource); |
| 66 | extern void report_resource_stored(struct device * dev, struct resource *resource, const char *comment); |
| 67 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 68 | typedef void (*resource_search_t)(void *gp, struct device *dev, struct resource *res); |
| 69 | extern void search_bus_resources(struct bus *bus, |
| 70 | unsigned long type_mask, unsigned long type, |
| 71 | resource_search_t search, void *gp); |
| 72 | |
| 73 | extern void search_global_resources( |
| 74 | unsigned long type_mask, unsigned long type, |
| 75 | resource_search_t search, void *gp); |
| 76 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 77 | #define RESOURCE_TYPE_MAX 20 |
| 78 | extern const char *resource_type(struct resource *resource); |
| 79 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 80 | #endif /* DEVICE_RESOURCE_H */ |