2 * system.c - a driver for reserving pnp system resources
4 * Some code is based on pnpbios_core.c
5 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
6 * (c) Copyright 2007 Hewlett-Packard Development Company, L.P.
7 * Bjorn Helgaas <bjorn.helgaas@hp.com>
10 #include <linux/acpi.h>
11 #include <linux/pnp.h>
12 #include <linux/device.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
15 #include <linux/kernel.h>
16 #include <linux/ioport.h>
18 static const struct pnp_device_id pnp_dev_table
[] = {
19 /* General ID for reserving resources */
21 /* memory controller */
27 static bool __reserve_range(u64 start
, unsigned int length
, bool io
, char *desc
)
29 u8 space_id
= io
? ACPI_ADR_SPACE_SYSTEM_IO
: ACPI_ADR_SPACE_SYSTEM_MEMORY
;
30 return !acpi_reserve_region(start
, length
, space_id
, IORESOURCE_BUSY
, desc
);
33 static bool __reserve_range(u64 start
, unsigned int length
, bool io
, char *desc
)
37 res
= io
? request_region(start
, length
, desc
) :
38 request_mem_region(start
, length
, desc
);
40 res
->flags
&= ~IORESOURCE_BUSY
;
47 static void reserve_range(struct pnp_dev
*dev
, struct resource
*r
, int port
)
50 const char *pnpid
= dev_name(&dev
->dev
);
51 resource_size_t start
= r
->start
, end
= r
->end
;
54 regionid
= kmalloc(16, GFP_KERNEL
);
58 snprintf(regionid
, 16, "pnp %s", pnpid
);
59 reserved
= __reserve_range(start
, end
- start
+ 1, !!port
, regionid
);
64 * Failures at this point are usually harmless. pci quirks for
65 * example do reserve stuff they know about too, so we may well
66 * have double reservations.
68 dev_info(&dev
->dev
, "%pR %s reserved\n", r
,
69 reserved
? "has been" : "could not be");
72 static void reserve_resources_of_dev(struct pnp_dev
*dev
)
77 for (i
= 0; (res
= pnp_get_resource(dev
, IORESOURCE_IO
, i
)); i
++) {
78 if (res
->flags
& IORESOURCE_DISABLED
)
81 continue; /* disabled */
82 if (res
->start
< 0x100)
84 * Below 0x100 is only standard PC hardware
85 * (pics, kbd, timer, dma, ...)
86 * We should not get resource conflicts there,
87 * and the kernel reserves these anyway
88 * (see arch/i386/kernel/setup.c).
92 if (res
->end
< res
->start
)
93 continue; /* invalid */
95 reserve_range(dev
, res
, 1);
98 for (i
= 0; (res
= pnp_get_resource(dev
, IORESOURCE_MEM
, i
)); i
++) {
99 if (res
->flags
& IORESOURCE_DISABLED
)
102 reserve_range(dev
, res
, 0);
106 static int system_pnp_probe(struct pnp_dev
*dev
,
107 const struct pnp_device_id
*dev_id
)
109 reserve_resources_of_dev(dev
);
113 static struct pnp_driver system_pnp_driver
= {
115 .id_table
= pnp_dev_table
,
116 .flags
= PNP_DRIVER_RES_DO_NOT_CHANGE
,
117 .probe
= system_pnp_probe
,
120 static int __init
pnp_system_init(void)
122 return pnp_register_driver(&system_pnp_driver
);
126 * Reserve motherboard resources after PCI claim BARs,
127 * but before PCI assign resources for uninitialized PCI devices
129 fs_initcall(pnp_system_init
);