Deleted Added
full compact
busdma_dmar.c (279117) busdma_dmar.c (280260)
1/*-
2 * Copyright (c) 2013 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

--- 14 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>
1/*-
2 * Copyright (c) 2013 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

--- 14 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/busdma_dmar.c 279117 2015-02-21 22:38:32Z kib $");
31__FBSDID("$FreeBSD: head/sys/x86/iommu/busdma_dmar.c 280260 2015-03-19 13:57:47Z kib $");
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/malloc.h>
36#include <sys/bus.h>
37#include <sys/conf.h>
38#include <sys/interrupt.h>
39#include <sys/kernel.h>
40#include <sys/ktr.h>
41#include <sys/lock.h>
42#include <sys/proc.h>
43#include <sys/memdesc.h>
44#include <sys/mutex.h>
45#include <sys/sysctl.h>
46#include <sys/rman.h>
47#include <sys/taskqueue.h>
48#include <sys/tree.h>
49#include <sys/uio.h>
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/malloc.h>
36#include <sys/bus.h>
37#include <sys/conf.h>
38#include <sys/interrupt.h>
39#include <sys/kernel.h>
40#include <sys/ktr.h>
41#include <sys/lock.h>
42#include <sys/proc.h>
43#include <sys/memdesc.h>
44#include <sys/mutex.h>
45#include <sys/sysctl.h>
46#include <sys/rman.h>
47#include <sys/taskqueue.h>
48#include <sys/tree.h>
49#include <sys/uio.h>
50#include <sys/vmem.h>
50#include <dev/pci/pcireg.h>
51#include <dev/pci/pcivar.h>
52#include <vm/vm.h>
53#include <vm/vm_extern.h>
54#include <vm/vm_kern.h>
55#include <vm/vm_object.h>
56#include <vm/vm_page.h>
57#include <vm/vm_map.h>

--- 29 unchanged lines hidden (view full) ---

87 * Given original device, find the requester ID that will be seen by
88 * the DMAR unit and used for page table lookup. PCI bridges may take
89 * ownership of transactions from downstream devices, so it may not be
90 * the same as the BSF of the target device. In those cases, all
91 * devices downstream of the bridge must share a single mapping
92 * domain, and must collectively be assigned to use either DMAR or
93 * bounce mapping.
94 */
51#include <dev/pci/pcireg.h>
52#include <dev/pci/pcivar.h>
53#include <vm/vm.h>
54#include <vm/vm_extern.h>
55#include <vm/vm_kern.h>
56#include <vm/vm_object.h>
57#include <vm/vm_page.h>
58#include <vm/vm_map.h>

--- 29 unchanged lines hidden (view full) ---

88 * Given original device, find the requester ID that will be seen by
89 * the DMAR unit and used for page table lookup. PCI bridges may take
90 * ownership of transactions from downstream devices, so it may not be
91 * the same as the BSF of the target device. In those cases, all
92 * devices downstream of the bridge must share a single mapping
93 * domain, and must collectively be assigned to use either DMAR or
94 * bounce mapping.
95 */
95static device_t
96device_t
96dmar_get_requester(device_t dev, uint16_t *rid)
97{
98 devclass_t pci_class;
99 device_t l, pci, pcib, pcip, pcibp, requester;
100 int cap_offset;
101 uint16_t pcie_flags;
102 bool bridge_is_pcie;
103

--- 146 unchanged lines hidden (view full) ---

250 struct dmar_unit *dmar;
251 struct dmar_ctx *ctx;
252 bus_dma_tag_t res;
253
254 dmar = dmar_find(child);
255 /* Not in scope of any DMAR ? */
256 if (dmar == NULL)
257 return (NULL);
97dmar_get_requester(device_t dev, uint16_t *rid)
98{
99 devclass_t pci_class;
100 device_t l, pci, pcib, pcip, pcibp, requester;
101 int cap_offset;
102 uint16_t pcie_flags;
103 bool bridge_is_pcie;
104

--- 146 unchanged lines hidden (view full) ---

251 struct dmar_unit *dmar;
252 struct dmar_ctx *ctx;
253 bus_dma_tag_t res;
254
255 dmar = dmar_find(child);
256 /* Not in scope of any DMAR ? */
257 if (dmar == NULL)
258 return (NULL);
259 if (!dmar->dma_enabled)
260 return (NULL);
258 dmar_quirks_pre_use(dmar);
259 dmar_instantiate_rmrr_ctxs(dmar);
260
261 ctx = dmar_instantiate_ctx(dmar, child, false);
262 res = ctx == NULL ? NULL : (bus_dma_tag_t)&ctx->ctx_tag;
263 return (res);
264}
265

--- 581 unchanged lines hidden (view full) ---

847 DMAR_UNLOCK(unit);
848 taskqueue_enqueue(unit->delayed_taskqueue, &unit->dmamap_load_task);
849}
850
851int
852dmar_init_busdma(struct dmar_unit *unit)
853{
854
261 dmar_quirks_pre_use(dmar);
262 dmar_instantiate_rmrr_ctxs(dmar);
263
264 ctx = dmar_instantiate_ctx(dmar, child, false);
265 res = ctx == NULL ? NULL : (bus_dma_tag_t)&ctx->ctx_tag;
266 return (res);
267}
268

--- 581 unchanged lines hidden (view full) ---

850 DMAR_UNLOCK(unit);
851 taskqueue_enqueue(unit->delayed_taskqueue, &unit->dmamap_load_task);
852}
853
854int
855dmar_init_busdma(struct dmar_unit *unit)
856{
857
858 unit->dma_enabled = 1;
859 TUNABLE_INT_FETCH("hw.dmar.dma", &unit->dma_enabled);
855 TAILQ_INIT(&unit->delayed_maps);
856 TASK_INIT(&unit->dmamap_load_task, 0, dmar_bus_task_dmamap, unit);
857 unit->delayed_taskqueue = taskqueue_create("dmar", M_WAITOK,
858 taskqueue_thread_enqueue, &unit->delayed_taskqueue);
859 taskqueue_start_threads(&unit->delayed_taskqueue, 1, PI_DISK,
860 "dmar%d busdma taskq", unit->unit);
861 return (0);
862}

--- 12 unchanged lines hidden ---
860 TAILQ_INIT(&unit->delayed_maps);
861 TASK_INIT(&unit->dmamap_load_task, 0, dmar_bus_task_dmamap, unit);
862 unit->delayed_taskqueue = taskqueue_create("dmar", M_WAITOK,
863 taskqueue_thread_enqueue, &unit->delayed_taskqueue);
864 taskqueue_start_threads(&unit->delayed_taskqueue, 1, PI_DISK,
865 "dmar%d busdma taskq", unit->unit);
866 return (0);
867}

--- 12 unchanged lines hidden ---