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>
26 static int pnp_reserve_irq[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some IRQ */
27 static int pnp_reserve_dma[8] = {[0 ... 7] = -1 }; /* reserve (don't use) some DMA */
28 static int pnp_reserve_io[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some I/O region */
29 static int pnp_reserve_mem[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some memory region */
44 option->flags = option_flags; in pnp_build_option()
45 option->type = type; in pnp_build_option()
47 list_add_tail(&option->list, &dev->options); in pnp_build_option()
59 return -ENOMEM; in pnp_register_irq_resource()
61 irq = &option->u.irq; in pnp_register_irq_resource()
62 irq->map = *map; in pnp_register_irq_resource()
63 irq->flags = flags; in pnp_register_irq_resource()
70 if (test_bit(i, irq->map.bits)) in pnp_register_irq_resource()
83 struct pnp_dma *dma; in pnp_register_dma_resource() local
87 return -ENOMEM; in pnp_register_dma_resource()
89 dma = &option->u.dma; in pnp_register_dma_resource()
90 dma->map = map; in pnp_register_dma_resource()
91 dma->flags = flags; in pnp_register_dma_resource()
107 return -ENOMEM; in pnp_register_port_resource()
109 port = &option->u.port; in pnp_register_port_resource()
110 port->min = min; in pnp_register_port_resource()
111 port->max = max; in pnp_register_port_resource()
112 port->align = align; in pnp_register_port_resource()
113 port->size = size; in pnp_register_port_resource()
114 port->flags = flags; in pnp_register_port_resource()
126 struct pnp_mem *mem; in pnp_register_mem_resource() local
130 return -ENOMEM; in pnp_register_mem_resource()
132 mem = &option->u.mem; in pnp_register_mem_resource()
133 mem->min = min; in pnp_register_mem_resource()
134 mem->max = max; in pnp_register_mem_resource()
135 mem->align = align; in pnp_register_mem_resource()
136 mem->size = size; in pnp_register_mem_resource()
137 mem->flags = flags; in pnp_register_mem_resource()
147 list_for_each_entry_safe(option, tmp, &dev->options, list) { in pnp_free_options()
148 list_del(&option->list); in pnp_free_options()
157 #define length(start, end) (*(end) - *(start) + 1)
173 port = &res->start; in pnp_check_port()
174 end = &res->end; in pnp_check_port()
177 if (cannot_compare(res->flags)) in pnp_check_port()
182 if (!dev->active) { in pnp_check_port()
191 int rend = pnp_reserve_io[(i << 1) + 1] + rport - 1; in pnp_check_port()
198 if (tres != res && tres->flags & IORESOURCE_IO) { in pnp_check_port()
199 tport = &tres->start; in pnp_check_port()
200 tend = &tres->end; in pnp_check_port()
213 if (tres->flags & IORESOURCE_IO) { in pnp_check_port()
214 if (cannot_compare(tres->flags)) in pnp_check_port()
216 if (tres->flags & IORESOURCE_WINDOW) in pnp_check_port()
218 tport = &tres->start; in pnp_check_port()
219 tend = &tres->end; in pnp_check_port()
236 addr = &res->start; in pnp_check_mem()
237 end = &res->end; in pnp_check_mem()
240 if (cannot_compare(res->flags)) in pnp_check_mem()
245 if (!dev->active) { in pnp_check_mem()
254 int rend = pnp_reserve_mem[(i << 1) + 1] + raddr - 1; in pnp_check_mem()
261 if (tres != res && tres->flags & IORESOURCE_MEM) { in pnp_check_mem()
262 taddr = &tres->start; in pnp_check_mem()
263 tend = &tres->end; in pnp_check_mem()
276 if (tres->flags & IORESOURCE_MEM) { in pnp_check_mem()
277 if (cannot_compare(tres->flags)) in pnp_check_mem()
279 if (tres->flags & IORESOURCE_WINDOW) in pnp_check_mem()
281 taddr = &tres->start; in pnp_check_mem()
282 tend = &tres->end; in pnp_check_mem()
304 if (pci->irq == irq) { in pci_dev_uses_irq()
305 pnp_dbg(&pnp->dev, " device %s using irq %d\n", in pci_dev_uses_irq()
321 * Unless both channels are native-PCI mode only, in pci_dev_uses_irq()
327 pnp_dbg(&pnp->dev, " legacy IDE device %s " in pci_dev_uses_irq()
359 irq = &res->start; in pnp_check_irq()
362 if (cannot_compare(res->flags)) in pnp_check_irq()
377 if (tres != res && tres->flags & IORESOURCE_IRQ) { in pnp_check_irq()
378 if (tres->start == *irq) in pnp_check_irq()
389 if (!dev->active) { in pnp_check_irq()
403 if (tres->flags & IORESOURCE_IRQ) { in pnp_check_irq()
404 if (cannot_compare(tres->flags)) in pnp_check_irq()
406 if (tres->start == *irq) in pnp_check_irq()
421 resource_size_t *dma; in pnp_check_dma() local
423 dma = &res->start; in pnp_check_dma()
426 if (cannot_compare(res->flags)) in pnp_check_dma()
430 if (*dma == 4 || *dma > 7) in pnp_check_dma()
435 if (pnp_reserve_dma[i] == *dma) in pnp_check_dma()
441 if (tres != res && tres->flags & IORESOURCE_DMA) { in pnp_check_dma()
442 if (tres->start == *dma) in pnp_check_dma()
449 if (!dev->active) { in pnp_check_dma()
450 if (request_dma(*dma, "pnp")) in pnp_check_dma()
452 free_dma(*dma); in pnp_check_dma()
462 if (tres->flags & IORESOURCE_DMA) { in pnp_check_dma()
463 if (cannot_compare(tres->flags)) in pnp_check_dma()
465 if (tres->start == *dma) in pnp_check_dma()
477 return res->flags & (IORESOURCE_IO | IORESOURCE_MEM | in pnp_resource_type()
488 list_for_each_entry(pnp_res, &dev->resources, list) { in pnp_get_resource()
489 res = &pnp_res->res; in pnp_get_resource()
490 if (pnp_resource_type(res) == type && num-- == 0) in pnp_get_resource()
505 list_add_tail(&pnp_res->list, &dev->resources); in pnp_new_resource()
516 dev_err(&dev->dev, "can't add resource %pR\n", res); in pnp_add_resource()
520 pnp_res->res = *res; in pnp_add_resource()
521 pnp_res->res.name = dev->name; in pnp_add_resource()
522 dev_dbg(&dev->dev, "%pR\n", res); in pnp_add_resource()
534 dev_err(&dev->dev, "can't add resource for IRQ %d\n", irq); in pnp_add_irq_resource()
538 res = &pnp_res->res; in pnp_add_irq_resource()
539 res->flags = IORESOURCE_IRQ | flags; in pnp_add_irq_resource()
540 res->start = irq; in pnp_add_irq_resource()
541 res->end = irq; in pnp_add_irq_resource()
543 dev_printk(KERN_DEBUG, &dev->dev, "%pR\n", res); in pnp_add_irq_resource()
547 struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma, in pnp_add_dma_resource() argument
555 dev_err(&dev->dev, "can't add resource for DMA %d\n", dma); in pnp_add_dma_resource()
559 res = &pnp_res->res; in pnp_add_dma_resource()
560 res->flags = IORESOURCE_DMA | flags; in pnp_add_dma_resource()
561 res->start = dma; in pnp_add_dma_resource()
562 res->end = dma; in pnp_add_dma_resource()
564 dev_printk(KERN_DEBUG, &dev->dev, "%pR\n", res); in pnp_add_dma_resource()
577 dev_err(&dev->dev, "can't add resource for IO %#llx-%#llx\n", in pnp_add_io_resource()
583 res = &pnp_res->res; in pnp_add_io_resource()
584 res->flags = IORESOURCE_IO | flags; in pnp_add_io_resource()
585 res->start = start; in pnp_add_io_resource()
586 res->end = end; in pnp_add_io_resource()
588 dev_printk(KERN_DEBUG, &dev->dev, "%pR\n", res); in pnp_add_io_resource()
601 dev_err(&dev->dev, "can't add resource for MEM %#llx-%#llx\n", in pnp_add_mem_resource()
607 res = &pnp_res->res; in pnp_add_mem_resource()
608 res->flags = IORESOURCE_MEM | flags; in pnp_add_mem_resource()
609 res->start = start; in pnp_add_mem_resource()
610 res->end = end; in pnp_add_mem_resource()
612 dev_printk(KERN_DEBUG, &dev->dev, "%pR\n", res); in pnp_add_mem_resource()
625 dev_err(&dev->dev, "can't add resource for BUS %#llx-%#llx\n", in pnp_add_bus_resource()
631 res = &pnp_res->res; in pnp_add_bus_resource()
632 res->flags = IORESOURCE_BUS; in pnp_add_bus_resource()
633 res->start = start; in pnp_add_bus_resource()
634 res->end = end; in pnp_add_bus_resource()
636 dev_printk(KERN_DEBUG, &dev->dev, "%pR\n", res); in pnp_add_bus_resource()
649 struct pnp_mem *mem; in pnp_possible_config() local
651 struct pnp_dma *dma; in pnp_possible_config() local
653 list_for_each_entry(option, &dev->options, list) { in pnp_possible_config()
654 if (option->type != type) in pnp_possible_config()
657 switch (option->type) { in pnp_possible_config()
659 port = &option->u.port; in pnp_possible_config()
660 if (port->min == start && port->size == size) in pnp_possible_config()
664 mem = &option->u.mem; in pnp_possible_config()
665 if (mem->min == start && mem->size == size) in pnp_possible_config()
669 irq = &option->u.irq; in pnp_possible_config()
671 test_bit(start, irq->map.bits)) in pnp_possible_config()
675 dma = &option->u.dma; in pnp_possible_config()
676 if (dma->map & (1 << start)) in pnp_possible_config()
693 list_for_each_entry(pnp_res, &dev->resources, list) { in pnp_range_reserved()
694 dev_start = &pnp_res->res.start; in pnp_range_reserved()
695 dev_end = &pnp_res->res.end; in pnp_range_reserved()