From owner-svn-src-all@FreeBSD.ORG Mon Jun 8 21:47:46 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0A9EE6A8; Mon, 8 Jun 2015 21:47:46 +0000 (UTC) (envelope-from marcel@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id ECD781DCD; Mon, 8 Jun 2015 21:47:45 +0000 (UTC) (envelope-from marcel@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t58LljME076495; Mon, 8 Jun 2015 21:47:45 GMT (envelope-from marcel@FreeBSD.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t58LljFN076490; Mon, 8 Jun 2015 21:47:45 GMT (envelope-from marcel@FreeBSD.org) Message-Id: <201506082147.t58LljFN076490@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: marcel set sender to marcel@FreeBSD.org using -f From: Marcel Moolenaar Date: Mon, 8 Jun 2015 21:47:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284168 - head/sys/dev/proto X-SVN-Group: head 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.20 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: Mon, 08 Jun 2015 21:47:46 -0000 Author: marcel Date: Mon Jun 8 21:47:44 2015 New Revision: 284168 URL: https://svnweb.freebsd.org/changeset/base/284168 Log: Implement mmap(2) for the busdma resource. Modified: head/sys/dev/proto/proto_busdma.c head/sys/dev/proto/proto_busdma.h head/sys/dev/proto/proto_core.c Modified: head/sys/dev/proto/proto_busdma.c ============================================================================== --- head/sys/dev/proto/proto_busdma.c Mon Jun 8 20:12:44 2015 (r284167) +++ head/sys/dev/proto/proto_busdma.c Mon Jun 8 21:47:44 2015 (r284168) @@ -146,16 +146,17 @@ proto_busdma_mem_alloc(struct proto_busd free(md, M_PROTO_BUSDMA); return (error); } - error = bus_dmamem_alloc(md->bd_tag, &md->kva, 0, &md->bd_map); + error = bus_dmamem_alloc(md->bd_tag, &md->virtaddr, 0, &md->bd_map); if (error) { bus_dma_tag_destroy(md->bd_tag); free(md, M_PROTO_BUSDMA); return (error); } + md->physaddr = pmap_kextract((uintptr_t)(md->virtaddr)); LIST_INSERT_HEAD(&tag->mds, md, peers); LIST_INSERT_HEAD(&busdma->mds, md, mds); ioc->u.mem.nsegs = 1; - ioc->u.mem.physaddr = pmap_kextract((uintptr_t)(md->kva)); + ioc->u.mem.physaddr = md->physaddr; ioc->result = (uintptr_t)(void *)md; return (0); } @@ -166,7 +167,7 @@ proto_busdma_mem_free(struct proto_busdm LIST_REMOVE(md, mds); LIST_REMOVE(md, peers); - bus_dmamem_free(md->bd_tag, md->kva, md->bd_map); + bus_dmamem_free(md->bd_tag, md->virtaddr, md->bd_map); bus_dma_tag_destroy(md->bd_tag); free(md, M_PROTO_BUSDMA); return (0); @@ -267,3 +268,16 @@ proto_busdma_ioctl(struct proto_softc *s } return (error); } + +int +proto_busdma_mmap_allowed(struct proto_busdma *busdma, vm_paddr_t physaddr) +{ + struct proto_md *md; + + LIST_FOREACH(md, &busdma->mds, mds) { + if (physaddr >= trunc_page(md->physaddr) && + physaddr <= trunc_page(md->physaddr + md->tag->maxsz)) + return (1); + } + return (0); +} Modified: head/sys/dev/proto/proto_busdma.h ============================================================================== --- head/sys/dev/proto/proto_busdma.h Mon Jun 8 20:12:44 2015 (r284167) +++ head/sys/dev/proto/proto_busdma.h Mon Jun 8 21:47:44 2015 (r284168) @@ -50,7 +50,8 @@ struct proto_md { LIST_ENTRY(proto_md) mds; LIST_ENTRY(proto_md) peers; struct proto_tag *tag; - void *kva; + void *virtaddr; + vm_paddr_t physaddr; bus_dma_tag_t bd_tag; bus_dmamap_t bd_map; }; @@ -69,4 +70,6 @@ int proto_busdma_cleanup(struct proto_so int proto_busdma_ioctl(struct proto_softc *, struct proto_busdma *, struct proto_ioc_busdma *); +int proto_busdma_mmap_allowed(struct proto_busdma *, vm_paddr_t); + #endif /* _DEV_PROTO_BUSDMA_H_ */ Modified: head/sys/dev/proto/proto_core.c ============================================================================== --- head/sys/dev/proto/proto_core.c Mon Jun 8 20:12:44 2015 (r284167) +++ head/sys/dev/proto/proto_core.c Mon Jun 8 21:47:44 2015 (r284168) @@ -402,19 +402,29 @@ proto_mmap(struct cdev *cdev, vm_ooffset { struct proto_res *r; - r = cdev->si_drv2; - - if (r->r_type != SYS_RES_MEMORY) - return (ENXIO); if (offset & PAGE_MASK) return (EINVAL); if (prot & PROT_EXEC) return (EACCES); - if (offset >= r->r_size) - return (EINVAL); - *paddr = rman_get_start(r->r_d.res) + offset; + + r = cdev->si_drv2; + + switch (r->r_type) { + case SYS_RES_MEMORY: + if (offset >= r->r_size) + return (EINVAL); + *paddr = rman_get_start(r->r_d.res) + offset; #ifndef __sparc64__ - *memattr = VM_MEMATTR_UNCACHEABLE; + *memattr = VM_MEMATTR_UNCACHEABLE; #endif + break; + case PROTO_RES_BUSDMA: + if (!proto_busdma_mmap_allowed(r->r_d.busdma, offset)) + return (EINVAL); + *paddr = offset; + break; + default: + return (ENXIO); + } return (0); }