intel_drv.c (278606) | intel_drv.c (280260) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 2013 The FreeBSD Foundation | 2 * Copyright (c) 2013-2015 The FreeBSD Foundation |
3 * All rights reserved. 4 * 5 * This software was developed by Konstantin Belousov <kib@FreeBSD.org> 6 * under sponsorship from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: --- 12 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> | 3 * All rights reserved. 4 * 5 * This software was developed by Konstantin Belousov <kib@FreeBSD.org> 6 * under sponsorship from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: --- 12 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/x86/iommu/intel_drv.c 278606 2015-02-11 23:30:46Z kib $"); | 31__FBSDID("$FreeBSD: head/sys/x86/iommu/intel_drv.c 280260 2015-03-19 13:57:47Z kib $"); |
32 33#include "opt_acpi.h" 34#if defined(__amd64__) 35#define DEV_APIC 36#else 37#include "opt_apic.h" 38#endif 39#include "opt_ddb.h" --- 5 unchanged lines hidden (view full) --- 45#include <sys/malloc.h> 46#include <sys/memdesc.h> 47#include <sys/module.h> 48#include <sys/rman.h> 49#include <sys/rwlock.h> 50#include <sys/smp.h> 51#include <sys/taskqueue.h> 52#include <sys/tree.h> | 32 33#include "opt_acpi.h" 34#if defined(__amd64__) 35#define DEV_APIC 36#else 37#include "opt_apic.h" 38#endif 39#include "opt_ddb.h" --- 5 unchanged lines hidden (view full) --- 45#include <sys/malloc.h> 46#include <sys/memdesc.h> 47#include <sys/module.h> 48#include <sys/rman.h> 49#include <sys/rwlock.h> 50#include <sys/smp.h> 51#include <sys/taskqueue.h> 52#include <sys/tree.h> |
53#include <sys/vmem.h> |
|
53#include <machine/bus.h> 54#include <contrib/dev/acpica/include/acpi.h> 55#include <contrib/dev/acpica/include/accommon.h> 56#include <dev/acpica/acpivar.h> 57#include <vm/vm.h> 58#include <vm/vm_extern.h> 59#include <vm/vm_kern.h> 60#include <vm/vm_object.h> 61#include <vm/vm_page.h> 62#include <vm/vm_pager.h> 63#include <vm/vm_map.h> 64#include <x86/include/busdma_impl.h> 65#include <x86/iommu/intel_reg.h> 66#include <x86/iommu/busdma_dmar.h> 67#include <x86/iommu/intel_dmar.h> | 54#include <machine/bus.h> 55#include <contrib/dev/acpica/include/acpi.h> 56#include <contrib/dev/acpica/include/accommon.h> 57#include <dev/acpica/acpivar.h> 58#include <vm/vm.h> 59#include <vm/vm_extern.h> 60#include <vm/vm_kern.h> 61#include <vm/vm_object.h> 62#include <vm/vm_page.h> 63#include <vm/vm_pager.h> 64#include <vm/vm_map.h> 65#include <x86/include/busdma_impl.h> 66#include <x86/iommu/intel_reg.h> 67#include <x86/iommu/busdma_dmar.h> 68#include <x86/iommu/intel_dmar.h> |
69#include <dev/pci/pcireg.h> |
|
68#include <dev/pci/pcivar.h> 69 70#ifdef DEV_APIC 71#include "pcib_if.h" 72#endif 73 74#define DMAR_FAULT_IRQ_RID 0 75#define DMAR_QI_IRQ_RID 1 --- 162 unchanged lines hidden (view full) --- 238} 239 240static void 241dmar_release_resources(device_t dev, struct dmar_unit *unit) 242{ 243 int i; 244 245 dmar_fini_busdma(unit); | 70#include <dev/pci/pcivar.h> 71 72#ifdef DEV_APIC 73#include "pcib_if.h" 74#endif 75 76#define DMAR_FAULT_IRQ_RID 0 77#define DMAR_QI_IRQ_RID 1 --- 162 unchanged lines hidden (view full) --- 240} 241 242static void 243dmar_release_resources(device_t dev, struct dmar_unit *unit) 244{ 245 int i; 246 247 dmar_fini_busdma(unit); |
248 dmar_fini_irt(unit); |
|
246 dmar_fini_qi(unit); 247 dmar_fini_fault_log(unit); 248 for (i = 0; i < DMAR_INTR_TOTAL; i++) 249 dmar_release_intr(dev, unit, i); 250 if (unit->regs != NULL) { 251 bus_deactivate_resource(dev, SYS_RES_MEMORY, unit->reg_rid, 252 unit->regs); 253 bus_release_resource(dev, SYS_RES_MEMORY, unit->reg_rid, --- 250 unchanged lines hidden (view full) --- 504 dmar_release_resources(dev, unit); 505 return (error); 506 } 507 error = dmar_init_qi(unit); 508 if (error != 0) { 509 dmar_release_resources(dev, unit); 510 return (error); 511 } | 249 dmar_fini_qi(unit); 250 dmar_fini_fault_log(unit); 251 for (i = 0; i < DMAR_INTR_TOTAL; i++) 252 dmar_release_intr(dev, unit, i); 253 if (unit->regs != NULL) { 254 bus_deactivate_resource(dev, SYS_RES_MEMORY, unit->reg_rid, 255 unit->regs); 256 bus_release_resource(dev, SYS_RES_MEMORY, unit->reg_rid, --- 250 unchanged lines hidden (view full) --- 507 dmar_release_resources(dev, unit); 508 return (error); 509 } 510 error = dmar_init_qi(unit); 511 if (error != 0) { 512 dmar_release_resources(dev, unit); 513 return (error); 514 } |
515 error = dmar_init_irt(unit); 516 if (error != 0) { 517 dmar_release_resources(dev, unit); 518 return (error); 519 } |
|
512 error = dmar_init_busdma(unit); 513 if (error != 0) { 514 dmar_release_resources(dev, unit); 515 return (error); 516 } 517 518#ifdef NOTYET 519 DMAR_LOCK(unit); --- 238 unchanged lines hidden (view full) --- 758 } 759 } 760 } 761 return (NULL); 762found: 763 return (device_get_softc(dmar_dev)); 764} 765 | 520 error = dmar_init_busdma(unit); 521 if (error != 0) { 522 dmar_release_resources(dev, unit); 523 return (error); 524 } 525 526#ifdef NOTYET 527 DMAR_LOCK(unit); --- 238 unchanged lines hidden (view full) --- 766 } 767 } 768 } 769 return (NULL); 770found: 771 return (device_get_softc(dmar_dev)); 772} 773 |
774static struct dmar_unit * 775dmar_find_nonpci(u_int id, u_int entry_type, uint16_t *rid) 776{ 777 device_t dmar_dev; 778 struct dmar_unit *unit; 779 ACPI_DMAR_HARDWARE_UNIT *dmarh; 780 ACPI_DMAR_DEVICE_SCOPE *devscope; 781 ACPI_DMAR_PCI_PATH *path; 782 char *ptr, *ptrend; 783 int i; 784 785 for (i = 0; i < dmar_devcnt; i++) { 786 dmar_dev = dmar_devs[i]; 787 if (dmar_dev == NULL) 788 continue; 789 unit = (struct dmar_unit *)device_get_softc(dmar_dev); 790 dmarh = dmar_find_by_index(i); 791 if (dmarh == NULL) 792 continue; 793 ptr = (char *)dmarh + sizeof(*dmarh); 794 ptrend = (char *)dmarh + dmarh->Header.Length; 795 for (;;) { 796 if (ptr >= ptrend) 797 break; 798 devscope = (ACPI_DMAR_DEVICE_SCOPE *)ptr; 799 ptr += devscope->Length; 800 if (devscope->EntryType != entry_type) 801 continue; 802 if (devscope->EnumerationId != id) 803 continue; 804 if (devscope->Length - sizeof(ACPI_DMAR_DEVICE_SCOPE) 805 == 2) { 806 if (rid != NULL) { 807 path = (ACPI_DMAR_PCI_PATH *) 808 (devscope + 1); 809 *rid = PCI_RID(devscope->Bus, 810 path->Device, path->Function); 811 } 812 return (unit); 813 } else { 814 /* XXXKIB */ 815 printf( 816 "dmar_find_nonpci: id %d type %d path length != 2\n", 817 id, entry_type); 818 } 819 } 820 } 821 return (NULL); 822} 823 824 825struct dmar_unit * 826dmar_find_hpet(device_t dev, uint16_t *rid) 827{ 828 ACPI_HANDLE handle; 829 uint32_t hpet_id; 830 831 handle = acpi_get_handle(dev); 832 if (ACPI_FAILURE(acpi_GetInteger(handle, "_UID", &hpet_id))) 833 return (NULL); 834 return (dmar_find_nonpci(hpet_id, ACPI_DMAR_SCOPE_TYPE_HPET, rid)); 835} 836 837struct dmar_unit * 838dmar_find_ioapic(u_int apic_id, uint16_t *rid) 839{ 840 841 return (dmar_find_nonpci(apic_id, ACPI_DMAR_SCOPE_TYPE_IOAPIC, rid)); 842} 843 |
|
766struct rmrr_iter_args { 767 struct dmar_ctx *ctx; 768 device_t dev; 769 int dev_domain; 770 int dev_busno; 771 ACPI_DMAR_PCI_PATH *dev_path; 772 int dev_path_len; 773 struct dmar_map_entries_tailq *rmrr_entries; --- 414 unchanged lines hidden --- | 844struct rmrr_iter_args { 845 struct dmar_ctx *ctx; 846 device_t dev; 847 int dev_domain; 848 int dev_busno; 849 ACPI_DMAR_PCI_PATH *dev_path; 850 int dev_path_len; 851 struct dmar_map_entries_tailq *rmrr_entries; --- 414 unchanged lines hidden --- |