blob: d794fb21e7a322da370ee70da98162ee566c92e4 [file] [log] [blame]
Myles Watson29cc9ed2009-07-02 18:56:24 +00001#ifndef DEVICE_RESOURCE_H
2#define DEVICE_RESOURCE_H
Eric Biederman5899fd82003-04-24 06:25:08 +00003
Eric Biederman992cd002004-10-14 21:10:23 +00004#include <stdint.h>
Stefan Reinauer57879c92012-07-31 16:47:25 -07005#include <stddef.h>
Eric Biederman5899fd82003-04-24 06:25:08 +00006
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 Biedermane9a271e32003-09-02 03:36:25 +000012#define IORESOURCE_DRQ 0x00000800
Eric Biederman5899fd82003-04-24 06:25:08 +000013
Lee Leahy6a566d72017-03-07 17:45:12 -080014#define IORESOURCE_TYPE_MASK (IORESOURCE_IO | IORESOURCE_MEM \
15 | IORESOURCE_IRQ | IORESOURCE_DRQ)
Kyösti Mälkkifdc0a902015-03-26 20:04:38 +020016
Eric Biederman5899fd82003-04-24 06:25:08 +000017#define IORESOURCE_PREFETCH 0x00001000 /* No side effects */
18#define IORESOURCE_READONLY 0x00002000
19#define IORESOURCE_CACHEABLE 0x00004000
20#define IORESOURCE_RANGELENGTH 0x00008000
21#define IORESOURCE_SHADOWABLE 0x00010000
22#define IORESOURCE_BUS_HAS_VGA 0x00020000
Lee Leahy6a566d72017-03-07 17:45:12 -080023/* This resource filters all of the unclaimed transactions to the bus below. */
24#define IORESOURCE_SUBTRACTIVE 0x00040000
25/* The IO resource has a bus below it. */
26#define IORESOURCE_BRIDGE 0x00080000
27/* The resource needs to be reserved in the coreboot table */
28#define IORESOURCE_RESERVE 0x10000000
29/* The IO resource assignment has been stored in the device */
30#define IORESOURCE_STORED 0x20000000
31/* An IO resource that has been assigned a value */
32#define IORESOURCE_ASSIGNED 0x40000000
33/* An IO resource the allocator must not change */
34#define IORESOURCE_FIXED 0x80000000
Eric Biederman5899fd82003-04-24 06:25:08 +000035
Kyösti Mälkkid2245bb2012-08-27 09:09:23 +030036/* PCI specific resource bits (IORESOURCE_BITS) */
Eric Biederman5899fd82003-04-24 06:25:08 +000037#define IORESOURCE_PCI64 (1<<0) /* 64bit long pci resource */
38#define IORESOURCE_PCI_BRIDGE (1<<1) /* A bridge pci resource */
39
Myles Watson29cc9ed2009-07-02 18:56:24 +000040typedef u64 resource_t;
Eric Biederman5899fd82003-04-24 06:25:08 +000041struct resource {
Eric Biederman992cd002004-10-14 21:10:23 +000042 resource_t base; /* Base address of the resource */
43 resource_t size; /* Size of the resource */
44 resource_t limit; /* Largest valid value base + size -1 */
Lee Leahy6d71a432017-03-07 15:24:16 -080045 ROMSTAGE_CONST struct resource *next; /* Next resource in the list */
Eric Biederman5899fd82003-04-24 06:25:08 +000046 unsigned long flags; /* Descriptions of the kind of resource */
47 unsigned long index; /* Bus specific per device resource id */
Li-Ta Loe3c79ed2004-03-19 00:08:48 +000048 unsigned char align; /* Required alignment (log 2) of the resource */
49 unsigned char gran; /* Granularity (log 2) of the resource */
Eric Biederman5899fd82003-04-24 06:25:08 +000050 /* Alignment must be >= the granularity of the resource */
51};
52
Myles Watson29cc9ed2009-07-02 18:56:24 +000053/* Macros to generate index values for resources */
Lee Leahyae3fd342017-03-07 12:55:23 -080054#define IOINDEX_SUBTRACTIVE(IDX, LINK) (0x10000000 + ((IDX) << 8) + LINK)
Eric Biederman992cd002004-10-14 21:10:23 +000055#define IOINDEX_SUBTRACTIVE_LINK(IDX) (IDX & 0xff)
56
Lee Leahyae3fd342017-03-07 12:55:23 -080057#define IOINDEX(IDX, LINK) (((LINK) << 16) + IDX)
Lee Leahy91d1e762017-03-07 14:31:19 -080058#define IOINDEX_LINK(IDX) ((IDX & 0xf0000) >> 16)
Myles Watson29cc9ed2009-07-02 18:56:24 +000059#define IOINDEX_IDX(IDX) (IDX & 0xffff)
60
Eric Biederman992cd002004-10-14 21:10:23 +000061/* Generic resource helper functions */
62struct device;
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +000063struct bus;
Lee Leahy6d71a432017-03-07 15:24:16 -080064extern void compact_resources(struct device *dev);
Lee Leahy0ca2a062017-03-06 18:01:04 -080065extern struct resource *probe_resource(struct device *dev, unsigned int index);
Lee Leahy6d71a432017-03-07 15:24:16 -080066extern struct resource *new_resource(struct device *dev, unsigned int index);
67extern struct resource *find_resource(struct device *dev, unsigned int index);
Eric Biederman992cd002004-10-14 21:10:23 +000068extern resource_t resource_end(struct resource *resource);
69extern resource_t resource_max(struct resource *resource);
Lee Leahy6a566d72017-03-07 17:45:12 -080070extern void report_resource_stored(struct device *dev,
71 struct resource *resource, const char *comment);
Eric Biederman992cd002004-10-14 21:10:23 +000072
Lee Leahy6a566d72017-03-07 17:45:12 -080073typedef void (*resource_search_t)(void *gp, struct device *dev,
74 struct resource *res);
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +000075extern void search_bus_resources(struct bus *bus,
76 unsigned long type_mask, unsigned long type,
77 resource_search_t search, void *gp);
78
79extern void search_global_resources(
80 unsigned long type_mask, unsigned long type,
81 resource_search_t search, void *gp);
82
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000083#define RESOURCE_TYPE_MAX 20
84extern const char *resource_type(struct resource *resource);
85
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080086static inline void *res2mmio(struct resource *res, unsigned long offset,
87 unsigned long mask)
88{
89 return (void *)(uintptr_t)((res->base + offset) & ~mask);
90}
91
Myles Watson29cc9ed2009-07-02 18:56:24 +000092#endif /* DEVICE_RESOURCE_H */