From owner-svn-src-all@freebsd.org Thu Aug 6 08:48:24 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8F26637A9FA; Thu, 6 Aug 2020 08:48:24 +0000 (UTC) (envelope-from br@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BMhwS3JlYz3cHh; Thu, 6 Aug 2020 08:48:24 +0000 (UTC) (envelope-from br@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 54EE62451F; Thu, 6 Aug 2020 08:48:24 +0000 (UTC) (envelope-from br@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0768mO8M072491; Thu, 6 Aug 2020 08:48:24 GMT (envelope-from br@FreeBSD.org) Received: (from br@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0768mN7m072485; Thu, 6 Aug 2020 08:48:23 GMT (envelope-from br@FreeBSD.org) Message-Id: <202008060848.0768mN7m072485@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: br set sender to br@FreeBSD.org using -f From: Ruslan Bukin Date: Thu, 6 Aug 2020 08:48:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363946 - in head/sys: dev/iommu x86/iommu X-SVN-Group: head X-SVN-Commit-Author: br X-SVN-Commit-Paths: in head/sys: dev/iommu x86/iommu X-SVN-Commit-Revision: 363946 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Aug 2020 08:48:24 -0000 Author: br Date: Thu Aug 6 08:48:23 2020 New Revision: 363946 URL: https://svnweb.freebsd.org/changeset/base/363946 Log: Add iommu_domain constructor and destructor. Reviewed by: kib Sponsored by: DARPA/AFRL Differential Revision: https://reviews.freebsd.org/D25956 Modified: head/sys/dev/iommu/busdma_iommu.c head/sys/dev/iommu/iommu.h head/sys/x86/iommu/intel_ctx.c head/sys/x86/iommu/intel_dmar.h head/sys/x86/iommu/intel_idpgtbl.c Modified: head/sys/dev/iommu/busdma_iommu.c ============================================================================== --- head/sys/dev/iommu/busdma_iommu.c Thu Aug 6 08:21:33 2020 (r363945) +++ head/sys/dev/iommu/busdma_iommu.c Thu Aug 6 08:48:23 2020 (r363946) @@ -1063,3 +1063,23 @@ bus_dma_iommu_load_ident(bus_dma_tag_t dmat, bus_dmama free(ma, M_TEMP); return (error); } + +void +iommu_domain_init(struct iommu_unit *unit, struct iommu_domain *domain, + const struct iommu_domain_map_ops *ops) +{ + + domain->ops = ops; + domain->iommu = unit; + + RB_INIT(&domain->rb_root); + TAILQ_INIT(&domain->unload_entries); + mtx_init(&domain->lock, "iodom", NULL, MTX_DEF); +} + +void +iommu_domain_fini(struct iommu_domain *domain) +{ + + mtx_destroy(&domain->lock); +} Modified: head/sys/dev/iommu/iommu.h ============================================================================== --- head/sys/dev/iommu/iommu.h Thu Aug 6 08:21:33 2020 (r363945) +++ head/sys/dev/iommu/iommu.h Thu Aug 6 08:48:23 2020 (r363946) @@ -223,6 +223,9 @@ int iommu_gas_reserve_region(struct iommu_domain *doma void iommu_set_buswide_ctx(struct iommu_unit *unit, u_int busno); bool iommu_is_buswide_ctx(struct iommu_unit *unit, u_int busno); +void iommu_domain_init(struct iommu_unit *unit, struct iommu_domain *domain, + const struct iommu_domain_map_ops *ops); +void iommu_domain_fini(struct iommu_domain *domain); bool bus_dma_iommu_set_buswide(device_t dev); int bus_dma_iommu_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map, Modified: head/sys/x86/iommu/intel_ctx.c ============================================================================== --- head/sys/x86/iommu/intel_ctx.c Thu Aug 6 08:21:33 2020 (r363945) +++ head/sys/x86/iommu/intel_ctx.c Thu Aug 6 08:48:23 2020 (r363946) @@ -322,6 +322,7 @@ static struct dmar_domain * dmar_domain_alloc(struct dmar_unit *dmar, bool id_mapped) { struct iommu_domain *iodom; + struct iommu_unit *unit; struct dmar_domain *domain; int error, id, mgaw; @@ -330,16 +331,14 @@ dmar_domain_alloc(struct dmar_unit *dmar, bool id_mapp return (NULL); domain = malloc(sizeof(*domain), M_DMAR_DOMAIN, M_WAITOK | M_ZERO); iodom = DOM2IODOM(domain); + unit = DMAR2IOMMU(dmar); domain->domain = id; LIST_INIT(&domain->contexts); - RB_INIT(&domain->iodom.rb_root); - TAILQ_INIT(&domain->iodom.unload_entries); TASK_INIT(&domain->iodom.unload_task, 0, dmar_domain_unload_task, domain); - mtx_init(&domain->iodom.lock, "dmardom", NULL, MTX_DEF); + iommu_domain_init(unit, iodom, &dmar_domain_map_ops); + domain->dmar = dmar; - domain->iodom.iommu = &dmar->iommu; - domain_pgtbl_init(domain); /* * For now, use the maximal usable physical address of the @@ -430,8 +429,11 @@ dmar_ctx_unlink(struct dmar_ctx *ctx) static void dmar_domain_destroy(struct dmar_domain *domain) { + struct iommu_domain *iodom; struct dmar_unit *dmar; + iodom = DOM2IODOM(domain); + KASSERT(TAILQ_EMPTY(&domain->iodom.unload_entries), ("unfinished unloads %p", domain)); KASSERT(LIST_EMPTY(&domain->contexts), @@ -442,7 +444,7 @@ dmar_domain_destroy(struct dmar_domain *domain) ("destroying dom %p with refs %d", domain, domain->refs)); if ((domain->iodom.flags & IOMMU_DOMAIN_GAS_INITED) != 0) { DMAR_DOMAIN_LOCK(domain); - iommu_gas_fini_domain(DOM2IODOM(domain)); + iommu_gas_fini_domain(iodom); DMAR_DOMAIN_UNLOCK(domain); } if ((domain->iodom.flags & IOMMU_DOMAIN_PGTBL_INITED) != 0) { @@ -450,7 +452,7 @@ dmar_domain_destroy(struct dmar_domain *domain) DMAR_DOMAIN_PGLOCK(domain); domain_free_pgtbl(domain); } - mtx_destroy(&domain->iodom.lock); + iommu_domain_fini(iodom); dmar = DOM2DMAR(domain); free_unr(dmar->domids, domain->domain); free(domain, M_DMAR_DOMAIN); Modified: head/sys/x86/iommu/intel_dmar.h ============================================================================== --- head/sys/x86/iommu/intel_dmar.h Thu Aug 6 08:21:33 2020 (r363945) +++ head/sys/x86/iommu/intel_dmar.h Thu Aug 6 08:48:23 2020 (r363946) @@ -264,7 +264,7 @@ void domain_flush_iotlb_sync(struct dmar_domain *domai iommu_gaddr_t size); int domain_alloc_pgtbl(struct dmar_domain *domain); void domain_free_pgtbl(struct dmar_domain *domain); -void domain_pgtbl_init(struct dmar_domain *domain); +extern const struct iommu_domain_map_ops dmar_domain_map_ops; int dmar_dev_depth(device_t child); void dmar_dev_path(device_t child, int *busno, void *path1, int depth); Modified: head/sys/x86/iommu/intel_idpgtbl.c ============================================================================== --- head/sys/x86/iommu/intel_idpgtbl.c Thu Aug 6 08:21:33 2020 (r363945) +++ head/sys/x86/iommu/intel_idpgtbl.c Thu Aug 6 08:48:23 2020 (r363946) @@ -813,16 +813,7 @@ domain_flush_iotlb_sync(struct dmar_domain *domain, io DMAR_UNLOCK(unit); } -static const struct iommu_domain_map_ops dmar_domain_map_ops = { +const struct iommu_domain_map_ops dmar_domain_map_ops = { .map = domain_map_buf, .unmap = domain_unmap_buf, }; - -void -domain_pgtbl_init(struct dmar_domain *domain) -{ - struct iommu_domain *iodom; - - iodom = DOM2IODOM(domain); - iodom->ops = &dmar_domain_map_ops; -}