Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * resource.c - Contains functions for registering and analyzing resource information |
| 3 | * |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 4 | * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright 2003 Adam Belay <ambx1@neo.rr.com> |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 6 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. |
| 7 | * Bjorn Helgaas <bjorn.helgaas@hp.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <asm/dma.h> |
| 16 | #include <asm/irq.h> |
| 17 | #include <linux/pci.h> |
| 18 | #include <linux/ioport.h> |
| 19 | #include <linux/init.h> |
| 20 | |
| 21 | #include <linux/pnp.h> |
| 22 | #include "base.h" |
| 23 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 24 | static int pnp_reserve_irq[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some IRQ */ |
| 25 | static int pnp_reserve_dma[8] = {[0 ... 7] = -1 }; /* reserve (don't use) some DMA */ |
| 26 | static int pnp_reserve_io[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some I/O region */ |
| 27 | static int pnp_reserve_mem[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some memory region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * option registration |
| 31 | */ |
| 32 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 33 | struct pnp_option *pnp_build_option(struct pnp_dev *dev, unsigned long type, |
| 34 | unsigned int option_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 36 | struct pnp_option *option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 38 | option = kzalloc(sizeof(struct pnp_option), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | if (!option) |
| 40 | return NULL; |
| 41 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 42 | option->flags = option_flags; |
| 43 | option->type = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 45 | list_add_tail(&option->list, &dev->options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | return option; |
| 47 | } |
| 48 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 49 | int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags, |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 50 | pnp_irq_mask_t *map, unsigned char flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 52 | struct pnp_option *option; |
| 53 | struct pnp_irq *irq; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 54 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 55 | option = pnp_build_option(dev, IORESOURCE_IRQ, option_flags); |
| 56 | if (!option) |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 57 | return -ENOMEM; |
| 58 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 59 | irq = &option->u.irq; |
Bjorn Helgaas | 2d29a7a | 2008-06-27 16:57:13 -0600 | [diff] [blame] | 60 | irq->map = *map; |
| 61 | irq->flags = flags; |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #ifdef CONFIG_PCI |
| 64 | { |
| 65 | int i; |
| 66 | |
| 67 | for (i = 0; i < 16; i++) |
Bjorn Helgaas | 2d29a7a | 2008-06-27 16:57:13 -0600 | [diff] [blame] | 68 | if (test_bit(i, irq->map.bits)) |
David Shaohua Li | c9c3e45 | 2005-04-01 00:07:31 -0500 | [diff] [blame] | 69 | pcibios_penalize_isa_irq(i, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | #endif |
Bjorn Helgaas | c1caf06 | 2008-04-28 16:34:04 -0600 | [diff] [blame] | 72 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 73 | dbg_pnp_show_option(dev, option); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | return 0; |
| 75 | } |
| 76 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 77 | int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags, |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 78 | unsigned char map, unsigned char flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 80 | struct pnp_option *option; |
| 81 | struct pnp_dma *dma; |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 82 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 83 | option = pnp_build_option(dev, IORESOURCE_DMA, option_flags); |
| 84 | if (!option) |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 85 | return -ENOMEM; |
| 86 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 87 | dma = &option->u.dma; |
Bjorn Helgaas | 2d29a7a | 2008-06-27 16:57:13 -0600 | [diff] [blame] | 88 | dma->map = map; |
| 89 | dma->flags = flags; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 90 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 91 | dbg_pnp_show_option(dev, option); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | return 0; |
| 93 | } |
| 94 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 95 | int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags, |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 96 | resource_size_t min, resource_size_t max, |
| 97 | resource_size_t align, resource_size_t size, |
| 98 | unsigned char flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 100 | struct pnp_option *option; |
| 101 | struct pnp_port *port; |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 102 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 103 | option = pnp_build_option(dev, IORESOURCE_IO, option_flags); |
| 104 | if (!option) |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 105 | return -ENOMEM; |
| 106 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 107 | port = &option->u.port; |
Bjorn Helgaas | 2d29a7a | 2008-06-27 16:57:13 -0600 | [diff] [blame] | 108 | port->min = min; |
| 109 | port->max = max; |
| 110 | port->align = align; |
| 111 | port->size = size; |
| 112 | port->flags = flags; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 113 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 114 | dbg_pnp_show_option(dev, option); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 118 | int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags, |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 119 | resource_size_t min, resource_size_t max, |
| 120 | resource_size_t align, resource_size_t size, |
| 121 | unsigned char flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 123 | struct pnp_option *option; |
| 124 | struct pnp_mem *mem; |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 125 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 126 | option = pnp_build_option(dev, IORESOURCE_MEM, option_flags); |
| 127 | if (!option) |
Bjorn Helgaas | c227536 | 2008-06-27 16:57:11 -0600 | [diff] [blame] | 128 | return -ENOMEM; |
| 129 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 130 | mem = &option->u.mem; |
Bjorn Helgaas | 2d29a7a | 2008-06-27 16:57:13 -0600 | [diff] [blame] | 131 | mem->min = min; |
| 132 | mem->max = max; |
| 133 | mem->align = align; |
| 134 | mem->size = size; |
| 135 | mem->flags = flags; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 136 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 137 | dbg_pnp_show_option(dev, option); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 141 | void pnp_free_options(struct pnp_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 143 | struct pnp_option *option, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 145 | list_for_each_entry_safe(option, tmp, &dev->options, list) { |
| 146 | list_del(&option->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | kfree(option); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* |
| 152 | * resource validity checking |
| 153 | */ |
| 154 | |
| 155 | #define length(start, end) (*(end) - *(start) + 1) |
| 156 | |
| 157 | /* Two ranges conflict if one doesn't end before the other starts */ |
| 158 | #define ranged_conflict(starta, enda, startb, endb) \ |
| 159 | !((*(enda) < *(startb)) || (*(endb) < *(starta))) |
| 160 | |
| 161 | #define cannot_compare(flags) \ |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 162 | ((flags) & IORESOURCE_DISABLED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 164 | int pnp_check_port(struct pnp_dev *dev, struct resource *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
Bjorn Helgaas | ecfa935 | 2008-04-28 16:34:17 -0600 | [diff] [blame] | 166 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | struct pnp_dev *tdev; |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 168 | struct resource *tres; |
Greg Kroah-Hartman | b60ba83 | 2006-06-12 17:07:07 -0700 | [diff] [blame] | 169 | resource_size_t *port, *end, *tport, *tend; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 170 | |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 171 | port = &res->start; |
| 172 | end = &res->end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
| 174 | /* if the resource doesn't exist, don't complain about it */ |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 175 | if (cannot_compare(res->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | return 1; |
| 177 | |
| 178 | /* check if the resource is already in use, skip if the |
| 179 | * device is active because it itself may be in use */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 180 | if (!dev->active) { |
| 181 | if (__check_region(&ioport_resource, *port, length(port, end))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | /* check if the resource is reserved */ |
Bjorn Helgaas | ecfa935 | 2008-04-28 16:34:17 -0600 | [diff] [blame] | 186 | for (i = 0; i < 8; i++) { |
| 187 | int rport = pnp_reserve_io[i << 1]; |
| 188 | int rend = pnp_reserve_io[(i << 1) + 1] + rport - 1; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 189 | if (ranged_conflict(port, end, &rport, &rend)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | /* check for internal conflicts */ |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 194 | for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) { |
| 195 | if (tres != res && tres->flags & IORESOURCE_IO) { |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 196 | tport = &tres->start; |
| 197 | tend = &tres->end; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 198 | if (ranged_conflict(port, end, tport, tend)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | return 0; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /* check for conflicts with other pnp devices */ |
| 204 | pnp_for_each_dev(tdev) { |
| 205 | if (tdev == dev) |
| 206 | continue; |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 207 | for (i = 0; |
| 208 | (tres = pnp_get_resource(tdev, IORESOURCE_IO, i)); |
| 209 | i++) { |
| 210 | if (tres->flags & IORESOURCE_IO) { |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 211 | if (cannot_compare(tres->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | continue; |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 213 | tport = &tres->start; |
| 214 | tend = &tres->end; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 215 | if (ranged_conflict(port, end, tport, tend)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | return 0; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | return 1; |
| 222 | } |
| 223 | |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 224 | int pnp_check_mem(struct pnp_dev *dev, struct resource *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
Bjorn Helgaas | ecfa935 | 2008-04-28 16:34:17 -0600 | [diff] [blame] | 226 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | struct pnp_dev *tdev; |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 228 | struct resource *tres; |
Greg Kroah-Hartman | b60ba83 | 2006-06-12 17:07:07 -0700 | [diff] [blame] | 229 | resource_size_t *addr, *end, *taddr, *tend; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 230 | |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 231 | addr = &res->start; |
| 232 | end = &res->end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | /* if the resource doesn't exist, don't complain about it */ |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 235 | if (cannot_compare(res->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | return 1; |
| 237 | |
| 238 | /* check if the resource is already in use, skip if the |
| 239 | * device is active because it itself may be in use */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 240 | if (!dev->active) { |
| 241 | if (check_mem_region(*addr, length(addr, end))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | /* check if the resource is reserved */ |
Bjorn Helgaas | ecfa935 | 2008-04-28 16:34:17 -0600 | [diff] [blame] | 246 | for (i = 0; i < 8; i++) { |
| 247 | int raddr = pnp_reserve_mem[i << 1]; |
| 248 | int rend = pnp_reserve_mem[(i << 1) + 1] + raddr - 1; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 249 | if (ranged_conflict(addr, end, &raddr, &rend)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | /* check for internal conflicts */ |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 254 | for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) { |
| 255 | if (tres != res && tres->flags & IORESOURCE_MEM) { |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 256 | taddr = &tres->start; |
| 257 | tend = &tres->end; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 258 | if (ranged_conflict(addr, end, taddr, tend)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /* check for conflicts with other pnp devices */ |
| 264 | pnp_for_each_dev(tdev) { |
| 265 | if (tdev == dev) |
| 266 | continue; |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 267 | for (i = 0; |
| 268 | (tres = pnp_get_resource(tdev, IORESOURCE_MEM, i)); |
| 269 | i++) { |
| 270 | if (tres->flags & IORESOURCE_MEM) { |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 271 | if (cannot_compare(tres->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | continue; |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 273 | taddr = &tres->start; |
| 274 | tend = &tres->end; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 275 | if (ranged_conflict(addr, end, taddr, tend)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | return 0; |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | return 1; |
| 282 | } |
| 283 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 284 | static irqreturn_t pnp_test_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { |
| 286 | return IRQ_HANDLED; |
| 287 | } |
| 288 | |
Bjorn Helgaas | 84684c7 | 2008-06-27 16:57:18 -0600 | [diff] [blame] | 289 | #ifdef CONFIG_PCI |
| 290 | static int pci_dev_uses_irq(struct pnp_dev *pnp, struct pci_dev *pci, |
| 291 | unsigned int irq) |
| 292 | { |
| 293 | u32 class; |
| 294 | u8 progif; |
| 295 | |
| 296 | if (pci->irq == irq) { |
Bjorn Helgaas | 2f53432 | 2008-08-19 16:53:47 -0600 | [diff] [blame] | 297 | pnp_dbg(&pnp->dev, " device %s using irq %d\n", |
Bjorn Helgaas | 84684c7 | 2008-06-27 16:57:18 -0600 | [diff] [blame] | 298 | pci_name(pci), irq); |
| 299 | return 1; |
| 300 | } |
| 301 | |
| 302 | /* |
| 303 | * See pci_setup_device() and ata_pci_sff_activate_host() for |
| 304 | * similar IDE legacy detection. |
| 305 | */ |
| 306 | pci_read_config_dword(pci, PCI_CLASS_REVISION, &class); |
| 307 | class >>= 8; /* discard revision ID */ |
| 308 | progif = class & 0xff; |
| 309 | class >>= 8; |
| 310 | |
| 311 | if (class == PCI_CLASS_STORAGE_IDE) { |
| 312 | /* |
| 313 | * Unless both channels are native-PCI mode only, |
| 314 | * treat the compatibility IRQs as busy. |
| 315 | */ |
| 316 | if ((progif & 0x5) != 0x5) |
| 317 | if (pci_get_legacy_ide_irq(pci, 0) == irq || |
| 318 | pci_get_legacy_ide_irq(pci, 1) == irq) { |
Bjorn Helgaas | 2f53432 | 2008-08-19 16:53:47 -0600 | [diff] [blame] | 319 | pnp_dbg(&pnp->dev, " legacy IDE device %s " |
Bjorn Helgaas | 84684c7 | 2008-06-27 16:57:18 -0600 | [diff] [blame] | 320 | "using irq %d\n", pci_name(pci), irq); |
| 321 | return 1; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | #endif |
| 328 | |
| 329 | static int pci_uses_irq(struct pnp_dev *pnp, unsigned int irq) |
| 330 | { |
| 331 | #ifdef CONFIG_PCI |
| 332 | struct pci_dev *pci = NULL; |
| 333 | |
| 334 | for_each_pci_dev(pci) { |
| 335 | if (pci_dev_uses_irq(pnp, pci, irq)) { |
| 336 | pci_dev_put(pci); |
| 337 | return 1; |
| 338 | } |
| 339 | } |
| 340 | #endif |
| 341 | return 0; |
| 342 | } |
| 343 | |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 344 | int pnp_check_irq(struct pnp_dev *dev, struct resource *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { |
Bjorn Helgaas | ecfa935 | 2008-04-28 16:34:17 -0600 | [diff] [blame] | 346 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | struct pnp_dev *tdev; |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 348 | struct resource *tres; |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 349 | resource_size_t *irq; |
| 350 | |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 351 | irq = &res->start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | /* if the resource doesn't exist, don't complain about it */ |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 354 | if (cannot_compare(res->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | return 1; |
| 356 | |
| 357 | /* check if the resource is valid */ |
| 358 | if (*irq < 0 || *irq > 15) |
| 359 | return 0; |
| 360 | |
| 361 | /* check if the resource is reserved */ |
Bjorn Helgaas | ecfa935 | 2008-04-28 16:34:17 -0600 | [diff] [blame] | 362 | for (i = 0; i < 16; i++) { |
| 363 | if (pnp_reserve_irq[i] == *irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | /* check for internal conflicts */ |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 368 | for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) { |
| 369 | if (tres != res && tres->flags & IORESOURCE_IRQ) { |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 370 | if (tres->start == *irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | return 0; |
| 372 | } |
| 373 | } |
| 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | /* check if the resource is being used by a pci device */ |
Bjorn Helgaas | 84684c7 | 2008-06-27 16:57:18 -0600 | [diff] [blame] | 376 | if (pci_uses_irq(dev, *irq)) |
| 377 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
| 379 | /* check if the resource is already in use, skip if the |
| 380 | * device is active because it itself may be in use */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 381 | if (!dev->active) { |
Andrew Morton | 0cadaf4 | 2006-07-01 04:36:37 -0700 | [diff] [blame] | 382 | if (request_irq(*irq, pnp_test_handler, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 383 | IRQF_DISABLED | IRQF_PROBE_SHARED, "pnp", NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | return 0; |
| 385 | free_irq(*irq, NULL); |
| 386 | } |
| 387 | |
| 388 | /* check for conflicts with other pnp devices */ |
| 389 | pnp_for_each_dev(tdev) { |
| 390 | if (tdev == dev) |
| 391 | continue; |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 392 | for (i = 0; |
| 393 | (tres = pnp_get_resource(tdev, IORESOURCE_IRQ, i)); |
| 394 | i++) { |
| 395 | if (tres->flags & IORESOURCE_IRQ) { |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 396 | if (cannot_compare(tres->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | continue; |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 398 | if (tres->start == *irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | return 1; |
| 405 | } |
| 406 | |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 407 | int pnp_check_dma(struct pnp_dev *dev, struct resource *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { |
| 409 | #ifndef CONFIG_IA64 |
Bjorn Helgaas | ecfa935 | 2008-04-28 16:34:17 -0600 | [diff] [blame] | 410 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | struct pnp_dev *tdev; |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 412 | struct resource *tres; |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 413 | resource_size_t *dma; |
| 414 | |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 415 | dma = &res->start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | /* if the resource doesn't exist, don't complain about it */ |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 418 | if (cannot_compare(res->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | return 1; |
| 420 | |
| 421 | /* check if the resource is valid */ |
| 422 | if (*dma < 0 || *dma == 4 || *dma > 7) |
| 423 | return 0; |
| 424 | |
| 425 | /* check if the resource is reserved */ |
Bjorn Helgaas | ecfa935 | 2008-04-28 16:34:17 -0600 | [diff] [blame] | 426 | for (i = 0; i < 8; i++) { |
| 427 | if (pnp_reserve_dma[i] == *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | /* check for internal conflicts */ |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 432 | for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) { |
| 433 | if (tres != res && tres->flags & IORESOURCE_DMA) { |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 434 | if (tres->start == *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | return 0; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | /* check if the resource is already in use, skip if the |
| 440 | * device is active because it itself may be in use */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 441 | if (!dev->active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | if (request_dma(*dma, "pnp")) |
| 443 | return 0; |
| 444 | free_dma(*dma); |
| 445 | } |
| 446 | |
| 447 | /* check for conflicts with other pnp devices */ |
| 448 | pnp_for_each_dev(tdev) { |
| 449 | if (tdev == dev) |
| 450 | continue; |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 451 | for (i = 0; |
| 452 | (tres = pnp_get_resource(tdev, IORESOURCE_DMA, i)); |
| 453 | i++) { |
| 454 | if (tres->flags & IORESOURCE_DMA) { |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 455 | if (cannot_compare(tres->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | continue; |
Bjorn Helgaas | 30c016a | 2008-04-28 16:34:19 -0600 | [diff] [blame] | 457 | if (tres->start == *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | return 0; |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | return 1; |
| 464 | #else |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 465 | /* IA64 does not have legacy DMA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | return 0; |
| 467 | #endif |
| 468 | } |
| 469 | |
Rene Herman | b563cf5 | 2008-10-15 22:03:58 -0700 | [diff] [blame] | 470 | unsigned long pnp_resource_type(struct resource *res) |
Bjorn Helgaas | 940e98d | 2008-06-27 16:56:54 -0600 | [diff] [blame] | 471 | { |
| 472 | return res->flags & (IORESOURCE_IO | IORESOURCE_MEM | |
| 473 | IORESOURCE_IRQ | IORESOURCE_DMA); |
| 474 | } |
| 475 | |
Bjorn Helgaas | 0a977f1 | 2008-04-28 16:34:31 -0600 | [diff] [blame] | 476 | struct resource *pnp_get_resource(struct pnp_dev *dev, |
Rene Herman | b563cf5 | 2008-10-15 22:03:58 -0700 | [diff] [blame] | 477 | unsigned long type, unsigned int num) |
Bjorn Helgaas | 0a977f1 | 2008-04-28 16:34:31 -0600 | [diff] [blame] | 478 | { |
| 479 | struct pnp_resource *pnp_res; |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 480 | struct resource *res; |
Bjorn Helgaas | 0a977f1 | 2008-04-28 16:34:31 -0600 | [diff] [blame] | 481 | |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 482 | list_for_each_entry(pnp_res, &dev->resources, list) { |
| 483 | res = &pnp_res->res; |
| 484 | if (pnp_resource_type(res) == type && num-- == 0) |
| 485 | return res; |
| 486 | } |
Bjorn Helgaas | 0a977f1 | 2008-04-28 16:34:31 -0600 | [diff] [blame] | 487 | return NULL; |
| 488 | } |
Bjorn Helgaas | b90eca0 | 2008-04-28 16:34:14 -0600 | [diff] [blame] | 489 | EXPORT_SYMBOL(pnp_get_resource); |
| 490 | |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 491 | static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev) |
Bjorn Helgaas | a50b6d7 | 2008-04-28 16:34:33 -0600 | [diff] [blame] | 492 | { |
| 493 | struct pnp_resource *pnp_res; |
Bjorn Helgaas | a50b6d7 | 2008-04-28 16:34:33 -0600 | [diff] [blame] | 494 | |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 495 | pnp_res = kzalloc(sizeof(struct pnp_resource), GFP_KERNEL); |
| 496 | if (!pnp_res) |
| 497 | return NULL; |
| 498 | |
| 499 | list_add_tail(&pnp_res->list, &dev->resources); |
| 500 | return pnp_res; |
Bjorn Helgaas | a50b6d7 | 2008-04-28 16:34:33 -0600 | [diff] [blame] | 501 | } |
| 502 | |
Bjorn Helgaas | dbddd03 | 2008-04-28 16:34:34 -0600 | [diff] [blame] | 503 | struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, |
| 504 | int flags) |
| 505 | { |
| 506 | struct pnp_resource *pnp_res; |
| 507 | struct resource *res; |
Bjorn Helgaas | dbddd03 | 2008-04-28 16:34:34 -0600 | [diff] [blame] | 508 | |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 509 | pnp_res = pnp_new_resource(dev); |
Bjorn Helgaas | dbddd03 | 2008-04-28 16:34:34 -0600 | [diff] [blame] | 510 | if (!pnp_res) { |
Bjorn Helgaas | 25d39c3 | 2008-06-27 16:56:59 -0600 | [diff] [blame] | 511 | dev_err(&dev->dev, "can't add resource for IRQ %d\n", irq); |
Bjorn Helgaas | dbddd03 | 2008-04-28 16:34:34 -0600 | [diff] [blame] | 512 | return NULL; |
| 513 | } |
| 514 | |
| 515 | res = &pnp_res->res; |
| 516 | res->flags = IORESOURCE_IRQ | flags; |
| 517 | res->start = irq; |
| 518 | res->end = irq; |
| 519 | |
Bjorn Helgaas | c7dabef | 2009-10-27 13:26:47 -0600 | [diff] [blame] | 520 | pnp_dbg(&dev->dev, " add %pr\n", res); |
Bjorn Helgaas | dbddd03 | 2008-04-28 16:34:34 -0600 | [diff] [blame] | 521 | return pnp_res; |
| 522 | } |
| 523 | |
Bjorn Helgaas | dc16f5f | 2008-04-28 16:34:35 -0600 | [diff] [blame] | 524 | struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma, |
| 525 | int flags) |
| 526 | { |
| 527 | struct pnp_resource *pnp_res; |
| 528 | struct resource *res; |
Bjorn Helgaas | dc16f5f | 2008-04-28 16:34:35 -0600 | [diff] [blame] | 529 | |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 530 | pnp_res = pnp_new_resource(dev); |
Bjorn Helgaas | dc16f5f | 2008-04-28 16:34:35 -0600 | [diff] [blame] | 531 | if (!pnp_res) { |
Bjorn Helgaas | 25d39c3 | 2008-06-27 16:56:59 -0600 | [diff] [blame] | 532 | dev_err(&dev->dev, "can't add resource for DMA %d\n", dma); |
Bjorn Helgaas | dc16f5f | 2008-04-28 16:34:35 -0600 | [diff] [blame] | 533 | return NULL; |
| 534 | } |
| 535 | |
| 536 | res = &pnp_res->res; |
| 537 | res->flags = IORESOURCE_DMA | flags; |
| 538 | res->start = dma; |
| 539 | res->end = dma; |
| 540 | |
Bjorn Helgaas | c7dabef | 2009-10-27 13:26:47 -0600 | [diff] [blame] | 541 | pnp_dbg(&dev->dev, " add %pr\n", res); |
Bjorn Helgaas | dc16f5f | 2008-04-28 16:34:35 -0600 | [diff] [blame] | 542 | return pnp_res; |
| 543 | } |
| 544 | |
Bjorn Helgaas | cc8c2e3 | 2008-04-28 16:34:36 -0600 | [diff] [blame] | 545 | struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev, |
| 546 | resource_size_t start, |
| 547 | resource_size_t end, int flags) |
| 548 | { |
| 549 | struct pnp_resource *pnp_res; |
| 550 | struct resource *res; |
Bjorn Helgaas | cc8c2e3 | 2008-04-28 16:34:36 -0600 | [diff] [blame] | 551 | |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 552 | pnp_res = pnp_new_resource(dev); |
Bjorn Helgaas | cc8c2e3 | 2008-04-28 16:34:36 -0600 | [diff] [blame] | 553 | if (!pnp_res) { |
Bjorn Helgaas | 25d39c3 | 2008-06-27 16:56:59 -0600 | [diff] [blame] | 554 | dev_err(&dev->dev, "can't add resource for IO %#llx-%#llx\n", |
| 555 | (unsigned long long) start, |
| 556 | (unsigned long long) end); |
Bjorn Helgaas | cc8c2e3 | 2008-04-28 16:34:36 -0600 | [diff] [blame] | 557 | return NULL; |
| 558 | } |
| 559 | |
| 560 | res = &pnp_res->res; |
| 561 | res->flags = IORESOURCE_IO | flags; |
| 562 | res->start = start; |
| 563 | res->end = end; |
| 564 | |
Bjorn Helgaas | c7dabef | 2009-10-27 13:26:47 -0600 | [diff] [blame] | 565 | pnp_dbg(&dev->dev, " add %pr\n", res); |
Bjorn Helgaas | cc8c2e3 | 2008-04-28 16:34:36 -0600 | [diff] [blame] | 566 | return pnp_res; |
| 567 | } |
| 568 | |
Bjorn Helgaas | d6180f3 | 2008-04-28 16:34:37 -0600 | [diff] [blame] | 569 | struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev, |
| 570 | resource_size_t start, |
| 571 | resource_size_t end, int flags) |
| 572 | { |
| 573 | struct pnp_resource *pnp_res; |
| 574 | struct resource *res; |
Bjorn Helgaas | d6180f3 | 2008-04-28 16:34:37 -0600 | [diff] [blame] | 575 | |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 576 | pnp_res = pnp_new_resource(dev); |
Bjorn Helgaas | d6180f3 | 2008-04-28 16:34:37 -0600 | [diff] [blame] | 577 | if (!pnp_res) { |
Bjorn Helgaas | 25d39c3 | 2008-06-27 16:56:59 -0600 | [diff] [blame] | 578 | dev_err(&dev->dev, "can't add resource for MEM %#llx-%#llx\n", |
| 579 | (unsigned long long) start, |
| 580 | (unsigned long long) end); |
Bjorn Helgaas | d6180f3 | 2008-04-28 16:34:37 -0600 | [diff] [blame] | 581 | return NULL; |
| 582 | } |
| 583 | |
| 584 | res = &pnp_res->res; |
| 585 | res->flags = IORESOURCE_MEM | flags; |
| 586 | res->start = start; |
| 587 | res->end = end; |
| 588 | |
Bjorn Helgaas | c7dabef | 2009-10-27 13:26:47 -0600 | [diff] [blame] | 589 | pnp_dbg(&dev->dev, " add %pr\n", res); |
Bjorn Helgaas | d6180f3 | 2008-04-28 16:34:37 -0600 | [diff] [blame] | 590 | return pnp_res; |
| 591 | } |
| 592 | |
Bjorn Helgaas | 57fd51a | 2008-06-27 16:57:01 -0600 | [diff] [blame] | 593 | /* |
| 594 | * Determine whether the specified resource is a possible configuration |
| 595 | * for this device. |
| 596 | */ |
| 597 | int pnp_possible_config(struct pnp_dev *dev, int type, resource_size_t start, |
| 598 | resource_size_t size) |
| 599 | { |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 600 | struct pnp_option *option; |
| 601 | struct pnp_port *port; |
| 602 | struct pnp_mem *mem; |
| 603 | struct pnp_irq *irq; |
| 604 | struct pnp_dma *dma; |
Bjorn Helgaas | 57fd51a | 2008-06-27 16:57:01 -0600 | [diff] [blame] | 605 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 606 | list_for_each_entry(option, &dev->options, list) { |
| 607 | if (option->type != type) |
| 608 | continue; |
| 609 | |
| 610 | switch (option->type) { |
| 611 | case IORESOURCE_IO: |
| 612 | port = &option->u.port; |
| 613 | if (port->min == start && port->size == size) |
| 614 | return 1; |
| 615 | break; |
| 616 | case IORESOURCE_MEM: |
| 617 | mem = &option->u.mem; |
| 618 | if (mem->min == start && mem->size == size) |
| 619 | return 1; |
| 620 | break; |
| 621 | case IORESOURCE_IRQ: |
| 622 | irq = &option->u.irq; |
| 623 | if (start < PNP_IRQ_NR && |
| 624 | test_bit(start, irq->map.bits)) |
| 625 | return 1; |
| 626 | break; |
| 627 | case IORESOURCE_DMA: |
| 628 | dma = &option->u.dma; |
| 629 | if (dma->map & (1 << start)) |
| 630 | return 1; |
| 631 | break; |
| 632 | } |
| 633 | } |
Bjorn Helgaas | 57fd51a | 2008-06-27 16:57:01 -0600 | [diff] [blame] | 634 | |
| 635 | return 0; |
| 636 | } |
| 637 | EXPORT_SYMBOL(pnp_possible_config); |
| 638 | |
Bjorn Helgaas | 1b8e696 | 2009-06-05 14:37:23 +0000 | [diff] [blame] | 639 | int pnp_range_reserved(resource_size_t start, resource_size_t end) |
| 640 | { |
| 641 | struct pnp_dev *dev; |
| 642 | struct pnp_resource *pnp_res; |
| 643 | resource_size_t *dev_start, *dev_end; |
| 644 | |
| 645 | pnp_for_each_dev(dev) { |
| 646 | list_for_each_entry(pnp_res, &dev->resources, list) { |
| 647 | dev_start = &pnp_res->res.start; |
| 648 | dev_end = &pnp_res->res.end; |
| 649 | if (ranged_conflict(&start, &end, dev_start, dev_end)) |
| 650 | return 1; |
| 651 | } |
| 652 | } |
| 653 | return 0; |
| 654 | } |
| 655 | EXPORT_SYMBOL(pnp_range_reserved); |
| 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | /* format is: pnp_reserve_irq=irq1[,irq2] .... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | static int __init pnp_setup_reserve_irq(char *str) |
| 659 | { |
| 660 | int i; |
| 661 | |
| 662 | for (i = 0; i < 16; i++) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 663 | if (get_option(&str, &pnp_reserve_irq[i]) != 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | break; |
| 665 | return 1; |
| 666 | } |
| 667 | |
| 668 | __setup("pnp_reserve_irq=", pnp_setup_reserve_irq); |
| 669 | |
| 670 | /* format is: pnp_reserve_dma=dma1[,dma2] .... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | static int __init pnp_setup_reserve_dma(char *str) |
| 672 | { |
| 673 | int i; |
| 674 | |
| 675 | for (i = 0; i < 8; i++) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 676 | if (get_option(&str, &pnp_reserve_dma[i]) != 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | break; |
| 678 | return 1; |
| 679 | } |
| 680 | |
| 681 | __setup("pnp_reserve_dma=", pnp_setup_reserve_dma); |
| 682 | |
| 683 | /* format is: pnp_reserve_io=io1,size1[,io2,size2] .... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | static int __init pnp_setup_reserve_io(char *str) |
| 685 | { |
| 686 | int i; |
| 687 | |
| 688 | for (i = 0; i < 16; i++) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 689 | if (get_option(&str, &pnp_reserve_io[i]) != 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | break; |
| 691 | return 1; |
| 692 | } |
| 693 | |
| 694 | __setup("pnp_reserve_io=", pnp_setup_reserve_io); |
| 695 | |
| 696 | /* format is: pnp_reserve_mem=mem1,size1[,mem2,size2] .... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | static int __init pnp_setup_reserve_mem(char *str) |
| 698 | { |
| 699 | int i; |
| 700 | |
| 701 | for (i = 0; i < 16; i++) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 702 | if (get_option(&str, &pnp_reserve_mem[i]) != 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | break; |
| 704 | return 1; |
| 705 | } |
| 706 | |
| 707 | __setup("pnp_reserve_mem=", pnp_setup_reserve_mem); |