From owner-svn-src-head@freebsd.org Fri Jul 31 13:39:52 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6E9639AE492; Fri, 31 Jul 2015 13:39:52 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org (repo.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 3CB3413AA; Fri, 31 Jul 2015 13:39:52 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6VDdqv6035005; Fri, 31 Jul 2015 13:39:52 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6VDdq8G035004; Fri, 31 Jul 2015 13:39:52 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201507311339.t6VDdq8G035004@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Fri, 31 Jul 2015 13:39:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r286129 - head/sys/arm64/arm64 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Jul 2015 13:39:52 -0000 Author: andrew Date: Fri Jul 31 13:39:51 2015 New Revision: 286129 URL: https://svnweb.freebsd.org/changeset/base/286129 Log: Add memrw. This has had minimal testing, and will likely panic the kernel when trying to read data from outside the DMAP region. I expect this panic to be from within uiomove_fromphys, which needs to grow support to support such addresses. Obtained from: ABT Systems Ltd Sponsored by: The FreeBSD Foundation Modified: head/sys/arm64/arm64/mem.c Modified: head/sys/arm64/arm64/mem.c ============================================================================== --- head/sys/arm64/arm64/mem.c Fri Jul 31 13:34:43 2015 (r286128) +++ head/sys/arm64/arm64/mem.c Fri Jul 31 13:39:51 2015 (r286129) @@ -33,15 +33,84 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include +#include + +#include +#include +#include +#include struct mem_range_softc mem_range_softc; int memrw(struct cdev *dev, struct uio *uio, int flags) { + struct iovec *iov; + struct vm_page m; + vm_page_t marr; + vm_offset_t off, v; + u_int cnt; + int error; + + error = 0; + + while (uio->uio_resid > 0 && error == 0) { + iov = uio->uio_iov; + if (iov->iov_len == 0) { + uio->uio_iov++; + uio->uio_iovcnt--; + if (uio->uio_iovcnt < 0) + panic("memrw"); + continue; + } + + v = uio->uio_offset; + off = v & PAGE_MASK; + cnt = ulmin(iov->iov_len, PAGE_SIZE - (u_int)off); + if (cnt == 0) + continue; + + switch(dev2unit(dev)) { + case CDEV_MINOR_KMEM: + /* If the address is in the DMAP just copy it */ + if (VIRT_IN_DMAP(v)) { + error = uiomove((void *)v, cnt, uio); + break; + } + + if (!kernacc((void *)v, cnt, uio->uio_rw == UIO_READ ? + VM_PROT_READ : VM_PROT_WRITE)) { + error = EFAULT; + break; + } + + /* Get the physical address to read */ + v = pmap_extract(kernel_pmap, v); + if (v == 0) { + error = EFAULT; + break; + } + + /* FALLTHROUGH */ + case CDEV_MINOR_MEM: + /* If within the DMAP use this to copy from */ + if (PHYS_IN_DMAP(v)) { + v = PHYS_TO_DMAP(v); + error = uiomove((void *)v, cnt, uio); + break; + } + + /* Have uiomove_fromphys handle the data */ + m.phys_addr = trunc_page(v); + marr = &m; + uiomove_fromphys(&marr, off, cnt, uio); + break; + } + } - panic("ARM64TODO: memrw"); + return (error); }