From owner-svn-src-all@FreeBSD.ORG Tue Jun 2 15:11:48 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 832761065673; Tue, 2 Jun 2009 15:11:48 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 417A68FC19; Tue, 2 Jun 2009 15:11:48 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id B85A646B35; Tue, 2 Jun 2009 11:11:47 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id 8D6A28A02B; Tue, 2 Jun 2009 11:11:46 -0400 (EDT) From: John Baldwin To: Andrew Gallatin Date: Tue, 2 Jun 2009 11:10:39 -0400 User-Agent: KMail/1.9.7 References: <200906012132.n51LWq2U092924@svn.freebsd.org> <4A253627.4090505@cs.duke.edu> In-Reply-To: <4A253627.4090505@cs.duke.edu> MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200906021110.40347.jhb@freebsd.org> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Tue, 02 Jun 2009 11:11:46 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r193275 - in head/sys: kern sys vm X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Tue, 02 Jun 2009 15:11:49 -0000 On Tuesday 02 June 2009 10:24:39 am Andrew Gallatin wrote: > John Baldwin wrote: > > Author: jhb > > Date: Mon Jun 1 21:32:52 2009 > > New Revision: 193275 > > URL: http://svn.freebsd.org/changeset/base/193275 > > > > Log: > > Add an extension to the character device interface that allows character > > device drivers to use arbitrary VM objects to satisfy individual mmap() > > requests. > > Is there an example usage of this? Was this one of the things that > Nvidia asked for? Yes, this is for Nvidia. I have a bizarr-o test device in //depot/user/jhb/pat/modules/patdev/patdev.c. It exports a single anonymous memory object for mappings that use an offset at page 0 and a OBJT_SG (new type of VM object) object that maps the local APIC for mappings that use an offset at page 1. It's d_mmap_single() routine looks like this: static int pat_mmap_single(struct cdev *dev, vm_ooffset_t *offset, vm_size_t size, vm_object_t *object, int nprot) { struct patdev_softc *sc; int error; sc = dev->si_drv1; error = 0; sx_xlock(&sc->lock); switch (*offset) { case 0: /* * The first mmap() attempt with an offset of 0 creates * a new memory object with the requested size. Subsequent * mmap()'s map the same object. */ if (sc->mem == NULL) { /* * Note that this does not wire any backing * pages. I could do that later before a DMA * was started by wiring pages (even just * using the userland mapping to do that) * while the DMA was in-progress and unwiring * them later. */ sc->mem = vm_pager_allocate(OBJT_DEFAULT, NULL, size, VM_PROT_DEFAULT, 0); VM_OBJECT_LOCK(sc->mem); vm_object_clear_flag(sc->mem, OBJ_ONEMAPPING); vm_object_set_flag(sc->mem, OBJ_NOSPLIT); vm_object_set_cache_mode(sc->mem, VM_CACHE_WRITE_COMBINING); VM_OBJECT_UNLOCK(sc->mem); } vm_object_reference(sc->mem); *object = sc->mem; break; case PAGE_SIZE: /* Map the local APIC. */ vm_object_reference(sc->sgobj); *object = sc->sgobj; *offset = 0; break; default: /* Use ENODEV to fallback to d_mmap(). */ error = EINVAL; break; } sx_xunlock(&sc->lock); return (error); } The 'sgobj' object is created when the module is loaded: static int pat_attach(struct patdev_softc *sc) { vm_offset_t va; int rv; bzero(sc, sizeof(*sc)); sx_init(&sc->lock, "patdev"); sc->cdev = make_dev(&pat_devsw, 0, UID_ROOT, GID_WHEEL, 0640, "pat"); sc->cdev->si_drv1 = sc; /* Create a scatter/gather list that maps the local APIC. */ sc->sg = sglist_alloc(1, M_WAITOK); sglist_append_phys(sc->sg, lapic_paddr, LAPIC_LEN); /* Create a VM object that is backed by the scatter/gather list. */ sc->sgobj = vm_pager_allocate(OBJT_SG, sc->sg, LAPIC_LEN, VM_PROT_READ, 0); VM_OBJECT_LOCK(sc->sgobj); vm_object_set_cache_mode(sc->sgobj, VM_CACHE_UNCACHEABLE); VM_OBJECT_UNLOCK(sc->sgobj); ... } -- John Baldwin