1 // helper functions to manage pci io/memory/prefetch memory region
3 // Copyright (C) 2009 Isaku Yamahata <yamahata at valinux co jp>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
11 #define PCI_REGION_DISABLED (-1)
13 void pci_region_init(struct pci_region *r, u32 first, u32 last)
18 r->cur_first = r->first;
21 // PCI_REGION_DISABLED represents that the region is in special state.
22 // its value is chosen such that cur_first can't be PCI_REGION_DISABLED
24 // NOTE: the area right below 4G is used for LAPIC, so such area can't
25 // be used for PCI memory.
26 u32 pci_region_disable(struct pci_region *r)
28 return r->cur_first = PCI_REGION_DISABLED;
31 static int pci_region_disabled(const struct pci_region *r)
33 return r->cur_first == PCI_REGION_DISABLED;
36 static u32 pci_region_alloc_align(struct pci_region *r, u32 size, u32 align)
38 if (pci_region_disabled(r)) {
42 u32 s = ALIGN(r->cur_first, align);
43 if (s > r->last || s < r->cur_first) {
47 if (e < s || e - 1 > r->last) {
54 u32 pci_region_alloc(struct pci_region *r, u32 size)
56 return pci_region_alloc_align(r, size, size);
59 u32 pci_region_align(struct pci_region *r, u32 align)
61 return pci_region_alloc_align(r, 0, align);
64 void pci_region_revert(struct pci_region *r, u32 addr)
69 u32 pci_region_addr(const struct pci_region *r)
74 u32 pci_region_size(const struct pci_region *r)
76 return r->last - r->first + 1;