intel/skylake: Implement native Cache-as-RAM (CAR)
[coreboot.git] / src / include / device / resource.h
blob768c86d46a6e1c57a81b8977d21785a049634145
1 #ifndef DEVICE_RESOURCE_H
2 #define DEVICE_RESOURCE_H
4 #include <stdint.h>
5 #include <stddef.h>
7 #define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */
9 #define IORESOURCE_IO 0x00000100 /* Resource type */
10 #define IORESOURCE_MEM 0x00000200
11 #define IORESOURCE_IRQ 0x00000400
12 #define IORESOURCE_DRQ 0x00000800
14 #define IORESOURCE_TYPE_MASK (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_IRQ | IORESOURCE_DRQ)
16 #define IORESOURCE_PREFETCH 0x00001000 /* No side effects */
17 #define IORESOURCE_READONLY 0x00002000
18 #define IORESOURCE_CACHEABLE 0x00004000
19 #define IORESOURCE_RANGELENGTH 0x00008000
20 #define IORESOURCE_SHADOWABLE 0x00010000
21 #define IORESOURCE_BUS_HAS_VGA 0x00020000
22 #define IORESOURCE_SUBTRACTIVE 0x00040000 /* This resource filters all of the unclaimed transactions
23 * to the bus below.
25 #define IORESOURCE_BRIDGE 0x00080000 /* The IO resource has a bus below it. */
26 #define IORESOURCE_RESERVE 0x10000000 /* The resource needs to be reserved in the coreboot table */
27 #define IORESOURCE_STORED 0x20000000 /* The IO resource assignment has been stored in the device */
28 #define IORESOURCE_ASSIGNED 0x40000000 /* An IO resource that has been assigned a value */
29 #define IORESOURCE_FIXED 0x80000000 /* An IO resource the allocator must not change */
31 /* PCI specific resource bits (IORESOURCE_BITS) */
32 #define IORESOURCE_PCI64 (1<<0) /* 64bit long pci resource */
33 #define IORESOURCE_PCI_BRIDGE (1<<1) /* A bridge pci resource */
35 typedef u64 resource_t;
36 struct resource {
37 resource_t base; /* Base address of the resource */
38 resource_t size; /* Size of the resource */
39 resource_t limit; /* Largest valid value base + size -1 */
40 ROMSTAGE_CONST struct resource* next; /* Next resource in the list */
41 unsigned long flags; /* Descriptions of the kind of resource */
42 unsigned long index; /* Bus specific per device resource id */
43 unsigned char align; /* Required alignment (log 2) of the resource */
44 unsigned char gran; /* Granularity (log 2) of the resource */
45 /* Alignment must be >= the granularity of the resource */
48 /* Macros to generate index values for resources */
49 #define IOINDEX_SUBTRACTIVE(IDX,LINK) (0x10000000 + ((IDX) << 8) + LINK)
50 #define IOINDEX_SUBTRACTIVE_LINK(IDX) (IDX & 0xff)
52 #define IOINDEX(IDX,LINK) (((LINK) << 16) + IDX)
53 #define IOINDEX_LINK(IDX) (( IDX & 0xf0000) >> 16)
54 #define IOINDEX_IDX(IDX) (IDX & 0xffff)
56 /* Generic resource helper functions */
57 struct device;
58 struct bus;
59 extern void compact_resources(struct device * dev);
60 extern struct resource *probe_resource(struct device *dev, unsigned index);
61 extern struct resource *new_resource(struct device * dev, unsigned index);
62 extern struct resource *find_resource(struct device * dev, unsigned index);
63 extern resource_t resource_end(struct resource *resource);
64 extern resource_t resource_max(struct resource *resource);
65 extern void report_resource_stored(struct device * dev, struct resource *resource, const char *comment);
67 typedef void (*resource_search_t)(void *gp, struct device *dev, struct resource *res);
68 extern void search_bus_resources(struct bus *bus,
69 unsigned long type_mask, unsigned long type,
70 resource_search_t search, void *gp);
72 extern void search_global_resources(
73 unsigned long type_mask, unsigned long type,
74 resource_search_t search, void *gp);
76 #define RESOURCE_TYPE_MAX 20
77 extern const char *resource_type(struct resource *resource);
79 static inline void *res2mmio(struct resource *res, unsigned long offset,
80 unsigned long mask)
82 return (void *)(uintptr_t)((res->base + offset) & ~mask);
85 #endif /* DEVICE_RESOURCE_H */