Lines Matching +full:dma +full:- +full:mem

1 // SPDX-License-Identifier: GPL-2.0
3 * resource.c - Contains functions for registering and analyzing resource information
7 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
17 #include <asm/dma.h>
27 static int pnp_reserve_irq[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some IRQ */
28 static int pnp_reserve_dma[8] = {[0 ... 7] = -1 }; /* reserve (don't use) some DMA */
29 static int pnp_reserve_io[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some I/O region */
30 static int pnp_reserve_mem[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some memory region */
45 option->flags = option_flags; in pnp_build_option()
46 option->type = type; in pnp_build_option()
48 list_add_tail(&option->list, &dev->options); in pnp_build_option()
60 return -ENOMEM; in pnp_register_irq_resource()
62 irq = &option->u.irq; in pnp_register_irq_resource()
63 irq->map = *map; in pnp_register_irq_resource()
64 irq->flags = flags; in pnp_register_irq_resource()
71 if (test_bit(i, irq->map.bits)) in pnp_register_irq_resource()
84 struct pnp_dma *dma; in pnp_register_dma_resource() local
88 return -ENOMEM; in pnp_register_dma_resource()
90 dma = &option->u.dma; in pnp_register_dma_resource()
91 dma->map = map; in pnp_register_dma_resource()
92 dma->flags = flags; in pnp_register_dma_resource()
108 return -ENOMEM; in pnp_register_port_resource()
110 port = &option->u.port; in pnp_register_port_resource()
111 port->min = min; in pnp_register_port_resource()
112 port->max = max; in pnp_register_port_resource()
113 port->align = align; in pnp_register_port_resource()
114 port->size = size; in pnp_register_port_resource()
115 port->flags = flags; in pnp_register_port_resource()
127 struct pnp_mem *mem; in pnp_register_mem_resource() local
131 return -ENOMEM; in pnp_register_mem_resource()
133 mem = &option->u.mem; in pnp_register_mem_resource()
134 mem->min = min; in pnp_register_mem_resource()
135 mem->max = max; in pnp_register_mem_resource()
136 mem->align = align; in pnp_register_mem_resource()
137 mem->size = size; in pnp_register_mem_resource()
138 mem->flags = flags; in pnp_register_mem_resource()
148 list_for_each_entry_safe(option, tmp, &dev->options, list) { in pnp_free_options()
149 list_del(&option->list); in pnp_free_options()
158 #define length(start, end) (*(end) - *(start) + 1)
174 port = &res->start; in pnp_check_port()
175 end = &res->end; in pnp_check_port()
178 if (cannot_compare(res->flags)) in pnp_check_port()
183 if (!dev->active) { in pnp_check_port()
192 int rend = pnp_reserve_io[(i << 1) + 1] + rport - 1; in pnp_check_port()
199 if (tres != res && tres->flags & IORESOURCE_IO) { in pnp_check_port()
200 tport = &tres->start; in pnp_check_port()
201 tend = &tres->end; in pnp_check_port()
214 if (tres->flags & IORESOURCE_IO) { in pnp_check_port()
215 if (cannot_compare(tres->flags)) in pnp_check_port()
217 if (tres->flags & IORESOURCE_WINDOW) in pnp_check_port()
219 tport = &tres->start; in pnp_check_port()
220 tend = &tres->end; in pnp_check_port()
237 addr = &res->start; in pnp_check_mem()
238 end = &res->end; in pnp_check_mem()
241 if (cannot_compare(res->flags)) in pnp_check_mem()
246 if (!dev->active) { in pnp_check_mem()
255 int rend = pnp_reserve_mem[(i << 1) + 1] + raddr - 1; in pnp_check_mem()
262 if (tres != res && tres->flags & IORESOURCE_MEM) { in pnp_check_mem()
263 taddr = &tres->start; in pnp_check_mem()
264 tend = &tres->end; in pnp_check_mem()
277 if (tres->flags & IORESOURCE_MEM) { in pnp_check_mem()
278 if (cannot_compare(tres->flags)) in pnp_check_mem()
280 if (tres->flags & IORESOURCE_WINDOW) in pnp_check_mem()
282 taddr = &tres->start; in pnp_check_mem()
283 tend = &tres->end; in pnp_check_mem()
305 if (pci->irq == irq) { in pci_dev_uses_irq()
306 pnp_dbg(&pnp->dev, " device %s using irq %d\n", in pci_dev_uses_irq()
322 * Unless both channels are native-PCI mode only, in pci_dev_uses_irq()
328 pnp_dbg(&pnp->dev, " legacy IDE device %s " in pci_dev_uses_irq()
360 irq = &res->start; in pnp_check_irq()
363 if (cannot_compare(res->flags)) in pnp_check_irq()
378 if (tres != res && tres->flags & IORESOURCE_IRQ) { in pnp_check_irq()
379 if (tres->start == *irq) in pnp_check_irq()
390 if (!dev->active) { in pnp_check_irq()
404 if (tres->flags & IORESOURCE_IRQ) { in pnp_check_irq()
405 if (cannot_compare(tres->flags)) in pnp_check_irq()
407 if (tres->start == *irq) in pnp_check_irq()
422 resource_size_t *dma; in pnp_check_dma() local
424 dma = &res->start; in pnp_check_dma()
427 if (cannot_compare(res->flags)) in pnp_check_dma()
431 if (*dma == 4 || *dma > 7) in pnp_check_dma()
436 if (pnp_reserve_dma[i] == *dma) in pnp_check_dma()
442 if (tres != res && tres->flags & IORESOURCE_DMA) { in pnp_check_dma()
443 if (tres->start == *dma) in pnp_check_dma()
450 if (!dev->active) { in pnp_check_dma()
451 if (request_dma(*dma, "pnp")) in pnp_check_dma()
453 free_dma(*dma); in pnp_check_dma()
463 if (tres->flags & IORESOURCE_DMA) { in pnp_check_dma()
464 if (cannot_compare(tres->flags)) in pnp_check_dma()
466 if (tres->start == *dma) in pnp_check_dma()
478 return res->flags & (IORESOURCE_IO | IORESOURCE_MEM | in pnp_resource_type()
489 list_for_each_entry(pnp_res, &dev->resources, list) { in pnp_get_resource()
490 res = &pnp_res->res; in pnp_get_resource()
491 if (pnp_resource_type(res) == type && num-- == 0) in pnp_get_resource()
506 list_add_tail(&pnp_res->list, &dev->resources); in pnp_new_resource()
517 dev_err(&dev->dev, "can't add resource %pR\n", res); in pnp_add_resource()
521 pnp_res->res = *res; in pnp_add_resource()
522 pnp_res->res.name = dev->name; in pnp_add_resource()
523 dev_dbg(&dev->dev, "%pR\n", res); in pnp_add_resource()
535 dev_err(&dev->dev, "can't add resource for IRQ %d\n", irq); in pnp_add_irq_resource()
539 res = &pnp_res->res; in pnp_add_irq_resource()
540 res->flags = IORESOURCE_IRQ | flags; in pnp_add_irq_resource()
541 res->start = irq; in pnp_add_irq_resource()
542 res->end = irq; in pnp_add_irq_resource()
544 dev_dbg(&dev->dev, "%pR\n", res); in pnp_add_irq_resource()
548 struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma, in pnp_add_dma_resource() argument
556 dev_err(&dev->dev, "can't add resource for DMA %d\n", dma); in pnp_add_dma_resource()
560 res = &pnp_res->res; in pnp_add_dma_resource()
561 res->flags = IORESOURCE_DMA | flags; in pnp_add_dma_resource()
562 res->start = dma; in pnp_add_dma_resource()
563 res->end = dma; in pnp_add_dma_resource()
565 dev_printk(KERN_DEBUG, &dev->dev, "%pR\n", res); in pnp_add_dma_resource()
578 dev_err(&dev->dev, "can't add resource for IO %#llx-%#llx\n", in pnp_add_io_resource()
584 res = &pnp_res->res; in pnp_add_io_resource()
585 res->flags = IORESOURCE_IO | flags; in pnp_add_io_resource()
586 res->start = start; in pnp_add_io_resource()
587 res->end = end; in pnp_add_io_resource()
589 dev_printk(KERN_DEBUG, &dev->dev, "%pR\n", res); in pnp_add_io_resource()
602 dev_err(&dev->dev, "can't add resource for MEM %#llx-%#llx\n", in pnp_add_mem_resource()
608 res = &pnp_res->res; in pnp_add_mem_resource()
609 res->flags = IORESOURCE_MEM | flags; in pnp_add_mem_resource()
610 res->start = start; in pnp_add_mem_resource()
611 res->end = end; in pnp_add_mem_resource()
613 dev_printk(KERN_DEBUG, &dev->dev, "%pR\n", res); in pnp_add_mem_resource()
626 dev_err(&dev->dev, "can't add resource for BUS %#llx-%#llx\n", in pnp_add_bus_resource()
632 res = &pnp_res->res; in pnp_add_bus_resource()
633 res->flags = IORESOURCE_BUS; in pnp_add_bus_resource()
634 res->start = start; in pnp_add_bus_resource()
635 res->end = end; in pnp_add_bus_resource()
637 dev_printk(KERN_DEBUG, &dev->dev, "%pR\n", res); in pnp_add_bus_resource()
650 struct pnp_mem *mem; in pnp_possible_config() local
652 struct pnp_dma *dma; in pnp_possible_config() local
654 list_for_each_entry(option, &dev->options, list) { in pnp_possible_config()
655 if (option->type != type) in pnp_possible_config()
658 switch (option->type) { in pnp_possible_config()
660 port = &option->u.port; in pnp_possible_config()
661 if (port->min == start && port->size == size) in pnp_possible_config()
665 mem = &option->u.mem; in pnp_possible_config()
666 if (mem->min == start && mem->size == size) in pnp_possible_config()
670 irq = &option->u.irq; in pnp_possible_config()
672 test_bit(start, irq->map.bits)) in pnp_possible_config()
676 dma = &option->u.dma; in pnp_possible_config()
677 if (dma->map & (1 << start)) in pnp_possible_config()
694 list_for_each_entry(pnp_res, &dev->resources, list) { in pnp_range_reserved()
695 dev_start = &pnp_res->res.start; in pnp_range_reserved()
696 dev_end = &pnp_res->res.end; in pnp_range_reserved()