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

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * pnpacpi -- PnP ACPI driver
7 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
40 dev_err(&dev->dev, "can't encode invalid IRQ mode %#x\n", in decode_irq_flags()
76 dev_err(&dev->dev, "invalid DMA type %d\n", type); in dma_flags()
91 dev_err(&dev->dev, "invalid DMA transfer type %d\n", transfer); in dma_flags()
103 if (!(r->flags & IORESOURCE_DISABLED)) in pnpacpi_add_irqresource()
104 pcibios_penalize_isa_irq(r->start, 1); in pnpacpi_add_irqresource()
112 * marked as "consumer-only," but old versions of Windows and Linux ignore
113 * the producer/consumer flag, so HP invented a vendor-defined resource to
127 int uuid_len = sizeof(vendor->uuid); in vendor_resource_matches()
128 u8 uuid_subtype = vendor->uuid_subtype; in vendor_resource_matches()
129 u8 *uuid = vendor->uuid; in vendor_resource_matches()
133 actual_len = vendor->byte_length - uuid_len - 1; in vendor_resource_matches()
135 if (uuid_subtype == match->subtype && in vendor_resource_matches()
136 uuid_len == sizeof(match->data) && in vendor_resource_matches()
137 memcmp(uuid, match->data, uuid_len) == 0) { in vendor_resource_matches()
139 dev_err(&dev->dev, in vendor_resource_matches()
158 memcpy(&range, vendor->byte_data, sizeof(range)); in pnpacpi_parse_allocated_vendor()
160 range.length - 1, 0); in pnpacpi_parse_allocated_vendor()
168 struct acpi_resource_dma *dma; in pnpacpi_allocated_resource() local
181 r->flags = 0; in pnpacpi_allocated_resource()
191 * one interrupt, we won't be able to re-encode it. in pnpacpi_allocated_resource()
194 dev_warn(&dev->dev, in pnpacpi_allocated_resource()
196 dev->capabilities &= ~PNP_WRITE; in pnpacpi_allocated_resource()
205 i = acpi_dev_gpio_irq_get(dev->data, 0); in pnpacpi_allocated_resource()
207 flags = acpi_dev_irq_flags(gpio->triggering, in pnpacpi_allocated_resource()
208 gpio->polarity, in pnpacpi_allocated_resource()
209 gpio->shareable, in pnpacpi_allocated_resource()
210 gpio->wake_capable); in pnpacpi_allocated_resource()
216 } else if (r->flags & IORESOURCE_DISABLED) { in pnpacpi_allocated_resource()
221 switch (res->type) { in pnpacpi_allocated_resource()
234 dma = &res->data.dma; in pnpacpi_allocated_resource()
235 if (dma->channel_count > 0 && dma->channels[0] != (u8) -1) in pnpacpi_allocated_resource()
236 flags = dma_flags(dev, dma->type, dma->bus_master, in pnpacpi_allocated_resource()
237 dma->transfer); in pnpacpi_allocated_resource()
240 pnp_add_dma_resource(dev, dma->channels[0], flags); in pnpacpi_allocated_resource()
248 vendor_typed = &res->data.vendor_typed; in pnpacpi_allocated_resource()
263 dev_warn(&dev->dev, "unknown resource type %d in _CRS\n", in pnpacpi_allocated_resource()
264 res->type); in pnpacpi_allocated_resource()
273 struct acpi_device *acpi_dev = dev->data; in pnpacpi_parse_allocated_resource()
274 acpi_handle handle = acpi_dev->handle; in pnpacpi_parse_allocated_resource()
277 pnp_dbg(&dev->dev, "parse allocated resources\n"); in pnpacpi_parse_allocated_resource()
286 dev_err(&dev->dev, "can't evaluate _CRS: %d", status); in pnpacpi_parse_allocated_resource()
287 return -EPERM; in pnpacpi_parse_allocated_resource()
299 for (i = 0; i < p->channel_count; i++) in pnpacpi_parse_dma_option()
300 map |= 1 << p->channels[i]; in pnpacpi_parse_dma_option()
302 flags = dma_flags(dev, p->type, p->bus_master, p->transfer); in pnpacpi_parse_dma_option()
315 for (i = 0; i < p->interrupt_count; i++) in pnpacpi_parse_irq_option()
316 if (p->interrupts[i]) in pnpacpi_parse_irq_option()
317 __set_bit(p->interrupts[i], map.bits); in pnpacpi_parse_irq_option()
319 flags = acpi_dev_irq_flags(p->triggering, p->polarity, p->shareable, p->wake_capable); in pnpacpi_parse_irq_option()
332 for (i = 0; i < p->interrupt_count; i++) { in pnpacpi_parse_ext_irq_option()
333 if (p->interrupts[i]) { in pnpacpi_parse_ext_irq_option()
334 if (p->interrupts[i] < PNP_IRQ_NR) in pnpacpi_parse_ext_irq_option()
335 __set_bit(p->interrupts[i], map.bits); in pnpacpi_parse_ext_irq_option()
337 dev_err(&dev->dev, in pnpacpi_parse_ext_irq_option()
339 p->interrupts[i], PNP_IRQ_NR); in pnpacpi_parse_ext_irq_option()
343 flags = acpi_dev_irq_flags(p->triggering, p->polarity, p->shareable, p->wake_capable); in pnpacpi_parse_ext_irq_option()
353 if (io->io_decode == ACPI_DECODE_16) in pnpacpi_parse_port_option()
355 pnp_register_port_resource(dev, option_flags, io->minimum, io->maximum, in pnpacpi_parse_port_option()
356 io->alignment, io->address_length, flags); in pnpacpi_parse_port_option()
363 pnp_register_port_resource(dev, option_flags, io->address, io->address, in pnpacpi_parse_fixed_port_option()
364 0, io->address_length, IORESOURCE_IO_FIXED); in pnpacpi_parse_fixed_port_option()
373 if (p->write_protect == ACPI_READ_WRITE_MEMORY) in pnpacpi_parse_mem24_option()
375 pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum, in pnpacpi_parse_mem24_option()
376 p->alignment, p->address_length, flags); in pnpacpi_parse_mem24_option()
385 if (p->write_protect == ACPI_READ_WRITE_MEMORY) in pnpacpi_parse_mem32_option()
387 pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum, in pnpacpi_parse_mem32_option()
388 p->alignment, p->address_length, flags); in pnpacpi_parse_mem32_option()
397 if (p->write_protect == ACPI_READ_WRITE_MEMORY) in pnpacpi_parse_fixed_mem32_option()
399 pnp_register_mem_resource(dev, option_flags, p->address, p->address, in pnpacpi_parse_fixed_mem32_option()
400 0, p->address_length, flags); in pnpacpi_parse_fixed_mem32_option()
413 dev_warn(&dev->dev, "can't convert resource type %d\n", in pnpacpi_parse_address_option()
414 r->type); in pnpacpi_parse_address_option()
418 if (p->resource_type == ACPI_MEMORY_RANGE) { in pnpacpi_parse_address_option()
419 if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY) in pnpacpi_parse_address_option()
421 pnp_register_mem_resource(dev, option_flags, p->address.minimum, in pnpacpi_parse_address_option()
422 p->address.minimum, 0, p->address.address_length, in pnpacpi_parse_address_option()
424 } else if (p->resource_type == ACPI_IO_RANGE) in pnpacpi_parse_address_option()
425 pnp_register_port_resource(dev, option_flags, p->address.minimum, in pnpacpi_parse_address_option()
426 p->address.minimum, 0, p->address.address_length, in pnpacpi_parse_address_option()
434 struct acpi_resource_extended_address64 *p = &r->data.ext_address64; in pnpacpi_parse_ext_address_option()
437 if (p->resource_type == ACPI_MEMORY_RANGE) { in pnpacpi_parse_ext_address_option()
438 if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY) in pnpacpi_parse_ext_address_option()
440 pnp_register_mem_resource(dev, option_flags, p->address.minimum, in pnpacpi_parse_ext_address_option()
441 p->address.minimum, 0, p->address.address_length, in pnpacpi_parse_ext_address_option()
443 } else if (p->resource_type == ACPI_IO_RANGE) in pnpacpi_parse_ext_address_option()
444 pnp_register_port_resource(dev, option_flags, p->address.minimum, in pnpacpi_parse_ext_address_option()
445 p->address.minimum, 0, p->address.address_length, in pnpacpi_parse_ext_address_option()
459 struct pnp_dev *dev = parse_data->dev; in pnpacpi_option_resource()
460 unsigned int option_flags = parse_data->option_flags; in pnpacpi_option_resource()
462 switch (res->type) { in pnpacpi_option_resource()
464 pnpacpi_parse_irq_option(dev, option_flags, &res->data.irq); in pnpacpi_option_resource()
468 pnpacpi_parse_dma_option(dev, option_flags, &res->data.dma); in pnpacpi_option_resource()
472 switch (res->data.start_dpf.compatibility_priority) { in pnpacpi_option_resource()
488 parse_data->option_flags = pnp_new_dependent_set(dev, priority); in pnpacpi_option_resource()
492 parse_data->option_flags = 0; in pnpacpi_option_resource()
496 pnpacpi_parse_port_option(dev, option_flags, &res->data.io); in pnpacpi_option_resource()
501 &res->data.fixed_io); in pnpacpi_option_resource()
510 &res->data.memory24); in pnpacpi_option_resource()
515 &res->data.memory32); in pnpacpi_option_resource()
520 &res->data.fixed_memory32); in pnpacpi_option_resource()
535 &res->data.extended_irq); in pnpacpi_option_resource()
542 dev_warn(&dev->dev, "unknown resource type %d in _PRS\n", in pnpacpi_option_resource()
543 res->type); in pnpacpi_option_resource()
552 struct acpi_device *acpi_dev = dev->data; in pnpacpi_parse_resource_option_data()
553 acpi_handle handle = acpi_dev->handle; in pnpacpi_parse_resource_option_data()
557 pnp_dbg(&dev->dev, "parse resource options\n"); in pnpacpi_parse_resource_option_data()
567 dev_err(&dev->dev, "can't evaluate _PRS: %d", status); in pnpacpi_parse_resource_option_data()
568 return -EPERM; in pnpacpi_parse_resource_option_data()
575 switch (res->type) { in pnpacpi_supported_resource()
611 (*resource)->type = res->type; in pnpacpi_type_resources()
612 (*resource)->length = sizeof(struct acpi_resource); in pnpacpi_type_resources()
613 if (res->type == ACPI_RESOURCE_TYPE_IRQ) in pnpacpi_type_resources()
614 (*resource)->data.irq.descriptor_length = in pnpacpi_type_resources()
615 res->data.irq.descriptor_length; in pnpacpi_type_resources()
625 struct acpi_device *acpi_dev = dev->data; in pnpacpi_build_resource_template()
626 acpi_handle handle = acpi_dev->handle; in pnpacpi_build_resource_template()
634 dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status); in pnpacpi_build_resource_template()
635 return -EINVAL; in pnpacpi_build_resource_template()
638 return -EINVAL; in pnpacpi_build_resource_template()
639 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1; in pnpacpi_build_resource_template()
640 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL); in pnpacpi_build_resource_template()
641 if (!buffer->pointer) in pnpacpi_build_resource_template()
642 return -ENOMEM; in pnpacpi_build_resource_template()
644 resource = (struct acpi_resource *)buffer->pointer; in pnpacpi_build_resource_template()
648 kfree(buffer->pointer); in pnpacpi_build_resource_template()
649 dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status); in pnpacpi_build_resource_template()
650 return -EINVAL; in pnpacpi_build_resource_template()
653 resource->type = ACPI_RESOURCE_TYPE_END_TAG; in pnpacpi_build_resource_template()
654 resource->length = sizeof(struct acpi_resource); in pnpacpi_build_resource_template()
663 struct acpi_resource_irq *irq = &resource->data.irq; in pnpacpi_encode_irq()
667 irq->interrupt_count = 0; in pnpacpi_encode_irq()
668 pnp_dbg(&dev->dev, " encode irq (%s)\n", in pnpacpi_encode_irq()
673 decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); in pnpacpi_encode_irq()
674 irq->triggering = triggering; in pnpacpi_encode_irq()
675 irq->polarity = polarity; in pnpacpi_encode_irq()
676 irq->shareable = shareable; in pnpacpi_encode_irq()
677 irq->interrupt_count = 1; in pnpacpi_encode_irq()
678 irq->interrupts[0] = p->start; in pnpacpi_encode_irq()
680 pnp_dbg(&dev->dev, " encode irq %d %s %s %s (%d-byte descriptor)\n", in pnpacpi_encode_irq()
681 (int) p->start, in pnpacpi_encode_irq()
684 irq->shareable == ACPI_SHARED ? "shared" : "exclusive", in pnpacpi_encode_irq()
685 irq->descriptor_length); in pnpacpi_encode_irq()
692 struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq; in pnpacpi_encode_ext_irq()
696 extended_irq->interrupt_count = 0; in pnpacpi_encode_ext_irq()
697 pnp_dbg(&dev->dev, " encode extended irq (%s)\n", in pnpacpi_encode_ext_irq()
702 decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); in pnpacpi_encode_ext_irq()
703 extended_irq->producer_consumer = ACPI_CONSUMER; in pnpacpi_encode_ext_irq()
704 extended_irq->triggering = triggering; in pnpacpi_encode_ext_irq()
705 extended_irq->polarity = polarity; in pnpacpi_encode_ext_irq()
706 extended_irq->shareable = shareable; in pnpacpi_encode_ext_irq()
707 extended_irq->interrupt_count = 1; in pnpacpi_encode_ext_irq()
708 extended_irq->interrupts[0] = p->start; in pnpacpi_encode_ext_irq()
710 pnp_dbg(&dev->dev, " encode irq %d %s %s %s\n", (int) p->start, in pnpacpi_encode_ext_irq()
713 extended_irq->shareable == ACPI_SHARED ? "shared" : "exclusive"); in pnpacpi_encode_ext_irq()
720 struct acpi_resource_dma *dma = &resource->data.dma; in pnpacpi_encode_dma() local
723 dma->channel_count = 0; in pnpacpi_encode_dma()
724 pnp_dbg(&dev->dev, " encode dma (%s)\n", in pnpacpi_encode_dma()
729 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ in pnpacpi_encode_dma()
730 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) { in pnpacpi_encode_dma()
732 dma->type = ACPI_TYPE_A; in pnpacpi_encode_dma()
735 dma->type = ACPI_TYPE_B; in pnpacpi_encode_dma()
738 dma->type = ACPI_TYPE_F; in pnpacpi_encode_dma()
741 dma->type = ACPI_COMPATIBILITY; in pnpacpi_encode_dma()
744 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) { in pnpacpi_encode_dma()
746 dma->transfer = ACPI_TRANSFER_8; in pnpacpi_encode_dma()
749 dma->transfer = ACPI_TRANSFER_8_16; in pnpacpi_encode_dma()
752 dma->transfer = ACPI_TRANSFER_16; in pnpacpi_encode_dma()
755 dma->bus_master = !!(p->flags & IORESOURCE_DMA_MASTER); in pnpacpi_encode_dma()
756 dma->channel_count = 1; in pnpacpi_encode_dma()
757 dma->channels[0] = p->start; in pnpacpi_encode_dma()
759 pnp_dbg(&dev->dev, " encode dma %d " in pnpacpi_encode_dma()
761 (int) p->start, dma->type, dma->transfer, dma->bus_master); in pnpacpi_encode_dma()
768 struct acpi_resource_io *io = &resource->data.io; in pnpacpi_encode_io()
771 /* Note: pnp_assign_port copies pnp_port->flags into p->flags */ in pnpacpi_encode_io()
772 io->io_decode = (p->flags & IORESOURCE_IO_16BIT_ADDR) ? in pnpacpi_encode_io()
774 io->minimum = p->start; in pnpacpi_encode_io()
775 io->maximum = p->end; in pnpacpi_encode_io()
776 io->alignment = 0; /* Correct? */ in pnpacpi_encode_io()
777 io->address_length = resource_size(p); in pnpacpi_encode_io()
779 io->minimum = 0; in pnpacpi_encode_io()
780 io->address_length = 0; in pnpacpi_encode_io()
783 pnp_dbg(&dev->dev, " encode io %#x-%#x decode %#x\n", io->minimum, in pnpacpi_encode_io()
784 io->minimum + io->address_length - 1, io->io_decode); in pnpacpi_encode_io()
791 struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io; in pnpacpi_encode_fixed_io()
794 fixed_io->address = p->start; in pnpacpi_encode_fixed_io()
795 fixed_io->address_length = resource_size(p); in pnpacpi_encode_fixed_io()
797 fixed_io->address = 0; in pnpacpi_encode_fixed_io()
798 fixed_io->address_length = 0; in pnpacpi_encode_fixed_io()
801 pnp_dbg(&dev->dev, " encode fixed_io %#x-%#x\n", fixed_io->address, in pnpacpi_encode_fixed_io()
802 fixed_io->address + fixed_io->address_length - 1); in pnpacpi_encode_fixed_io()
809 struct acpi_resource_memory24 *memory24 = &resource->data.memory24; in pnpacpi_encode_mem24()
812 /* Note: pnp_assign_mem copies pnp_mem->flags into p->flags */ in pnpacpi_encode_mem24()
813 memory24->write_protect = p->flags & IORESOURCE_MEM_WRITEABLE ? in pnpacpi_encode_mem24()
815 memory24->minimum = p->start; in pnpacpi_encode_mem24()
816 memory24->maximum = p->end; in pnpacpi_encode_mem24()
817 memory24->alignment = 0; in pnpacpi_encode_mem24()
818 memory24->address_length = resource_size(p); in pnpacpi_encode_mem24()
820 memory24->minimum = 0; in pnpacpi_encode_mem24()
821 memory24->address_length = 0; in pnpacpi_encode_mem24()
824 pnp_dbg(&dev->dev, " encode mem24 %#x-%#x write_protect %#x\n", in pnpacpi_encode_mem24()
825 memory24->minimum, in pnpacpi_encode_mem24()
826 memory24->minimum + memory24->address_length - 1, in pnpacpi_encode_mem24()
827 memory24->write_protect); in pnpacpi_encode_mem24()
834 struct acpi_resource_memory32 *memory32 = &resource->data.memory32; in pnpacpi_encode_mem32()
837 memory32->write_protect = p->flags & IORESOURCE_MEM_WRITEABLE ? in pnpacpi_encode_mem32()
839 memory32->minimum = p->start; in pnpacpi_encode_mem32()
840 memory32->maximum = p->end; in pnpacpi_encode_mem32()
841 memory32->alignment = 0; in pnpacpi_encode_mem32()
842 memory32->address_length = resource_size(p); in pnpacpi_encode_mem32()
844 memory32->minimum = 0; in pnpacpi_encode_mem32()
845 memory32->alignment = 0; in pnpacpi_encode_mem32()
848 pnp_dbg(&dev->dev, " encode mem32 %#x-%#x write_protect %#x\n", in pnpacpi_encode_mem32()
849 memory32->minimum, in pnpacpi_encode_mem32()
850 memory32->minimum + memory32->address_length - 1, in pnpacpi_encode_mem32()
851 memory32->write_protect); in pnpacpi_encode_mem32()
858 struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32; in pnpacpi_encode_fixed_mem32()
861 fixed_memory32->write_protect = in pnpacpi_encode_fixed_mem32()
862 p->flags & IORESOURCE_MEM_WRITEABLE ? in pnpacpi_encode_fixed_mem32()
864 fixed_memory32->address = p->start; in pnpacpi_encode_fixed_mem32()
865 fixed_memory32->address_length = resource_size(p); in pnpacpi_encode_fixed_mem32()
867 fixed_memory32->address = 0; in pnpacpi_encode_fixed_mem32()
868 fixed_memory32->address_length = 0; in pnpacpi_encode_fixed_mem32()
871 pnp_dbg(&dev->dev, " encode fixed_mem32 %#x-%#x write_protect %#x\n", in pnpacpi_encode_fixed_mem32()
872 fixed_memory32->address, in pnpacpi_encode_fixed_mem32()
873 fixed_memory32->address + fixed_memory32->address_length - 1, in pnpacpi_encode_fixed_mem32()
874 fixed_memory32->write_protect); in pnpacpi_encode_fixed_mem32()
880 /* pnpacpi_build_resource_template allocates extra mem */ in pnpacpi_encode_resources()
881 int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1; in pnpacpi_encode_resources()
882 struct acpi_resource *resource = buffer->pointer; in pnpacpi_encode_resources()
883 unsigned int port = 0, irq = 0, dma = 0, mem = 0; in pnpacpi_encode_resources() local
885 pnp_dbg(&dev->dev, "encode %d resources\n", res_cnt); in pnpacpi_encode_resources()
887 switch (resource->type) { in pnpacpi_encode_resources()
896 pnp_get_resource(dev, IORESOURCE_DMA, dma)); in pnpacpi_encode_resources()
897 dma++; in pnpacpi_encode_resources()
911 pnp_get_resource(dev, IORESOURCE_MEM, mem)); in pnpacpi_encode_resources()
912 mem++; in pnpacpi_encode_resources()
916 pnp_get_resource(dev, IORESOURCE_MEM, mem)); in pnpacpi_encode_resources()
917 mem++; in pnpacpi_encode_resources()
921 pnp_get_resource(dev, IORESOURCE_MEM, mem)); in pnpacpi_encode_resources()
922 mem++; in pnpacpi_encode_resources()
939 dev_warn(&dev->dev, in pnpacpi_encode_resources()
941 resource->type); in pnpacpi_encode_resources()
942 return -EINVAL; in pnpacpi_encode_resources()