1 // SPDX-License-Identifier: GPL-2.0
3 * system.c - a driver for reserving pnp system resources
5 * Some code is based on pnpbios_core.c
6 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
7 * (c) Copyright 2007 Hewlett-Packard Development Company, L.P.
8 * Bjorn Helgaas <bjorn.helgaas@hp.com>
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 */
26 static void reserve_range(struct pnp_dev
*dev
, struct resource
*r
, int port
)
29 const char *pnpid
= dev_name(&dev
->dev
);
30 resource_size_t start
= r
->start
, end
= r
->end
;
33 regionid
= kmalloc(16, GFP_KERNEL
);
37 snprintf(regionid
, 16, "pnp %s", pnpid
);
39 res
= request_region(start
, end
- start
+ 1, regionid
);
41 res
= request_mem_region(start
, end
- start
+ 1, regionid
);
43 res
->flags
&= ~IORESOURCE_BUSY
;
48 * Failures at this point are usually harmless. pci quirks for
49 * example do reserve stuff they know about too, so we may well
50 * have double reservations.
52 dev_info(&dev
->dev
, "%pR %s reserved\n", r
,
53 res
? "has been" : "could not be");
56 static void reserve_resources_of_dev(struct pnp_dev
*dev
)
61 for (i
= 0; (res
= pnp_get_resource(dev
, IORESOURCE_IO
, i
)); i
++) {
62 if (res
->flags
& IORESOURCE_DISABLED
)
65 continue; /* disabled */
66 if (res
->start
< 0x100)
68 * Below 0x100 is only standard PC hardware
69 * (pics, kbd, timer, dma, ...)
70 * We should not get resource conflicts there,
71 * and the kernel reserves these anyway
72 * (see arch/i386/kernel/setup.c).
76 if (res
->end
< res
->start
)
77 continue; /* invalid */
79 reserve_range(dev
, res
, 1);
82 for (i
= 0; (res
= pnp_get_resource(dev
, IORESOURCE_MEM
, i
)); i
++) {
83 if (res
->flags
& IORESOURCE_DISABLED
)
86 reserve_range(dev
, res
, 0);
90 static int system_pnp_probe(struct pnp_dev
*dev
,
91 const struct pnp_device_id
*dev_id
)
93 reserve_resources_of_dev(dev
);
97 static struct pnp_driver system_pnp_driver
= {
99 .id_table
= pnp_dev_table
,
100 .flags
= PNP_DRIVER_RES_DO_NOT_CHANGE
,
101 .probe
= system_pnp_probe
,
104 static int __init
pnp_system_init(void)
106 return pnp_register_driver(&system_pnp_driver
);
110 * Reserve motherboard resources after PCI claim BARs,
111 * but before PCI assign resources for uninitialized PCI devices
113 fs_initcall(pnp_system_init
);