Home | History | Annotate | Line # | Download | only in dev
mm.c revision 1.13.26.1
      1  1.13.26.1    cherry /*	$NetBSD: mm.c,v 1.13.26.1 2011/06/23 14:19:54 cherry Exp $	*/
      2        1.1  christos 
      3        1.1  christos /*-
      4  1.13.26.1    cherry  * Copyright (c) 2002, 2008, 2010 The NetBSD Foundation, Inc.
      5        1.1  christos  * All rights reserved.
      6        1.1  christos  *
      7        1.1  christos  * This code is derived from software contributed to The NetBSD Foundation
      8  1.13.26.1    cherry  * by Christos Zoulas, Joerg Sonnenberger and Mindaugas Rasiukevicius.
      9        1.1  christos  *
     10        1.1  christos  * Redistribution and use in source and binary forms, with or without
     11        1.1  christos  * modification, are permitted provided that the following conditions
     12        1.1  christos  * are met:
     13        1.1  christos  * 1. Redistributions of source code must retain the above copyright
     14        1.1  christos  *    notice, this list of conditions and the following disclaimer.
     15        1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     17        1.1  christos  *    documentation and/or other materials provided with the distribution.
     18        1.1  christos  *
     19        1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1  christos  */
     31        1.1  christos 
     32  1.13.26.1    cherry /*
     33  1.13.26.1    cherry  * Special /dev/{mem,kmem,zero,null} memory devices.
     34  1.13.26.1    cherry  */
     35        1.1  christos 
     36        1.1  christos #include <sys/cdefs.h>
     37  1.13.26.1    cherry __KERNEL_RCSID(0, "$NetBSD: mm.c,v 1.13.26.1 2011/06/23 14:19:54 cherry Exp $");
     38        1.1  christos 
     39  1.13.26.1    cherry #include "opt_compat_netbsd.h"
     40        1.1  christos 
     41        1.1  christos #include <sys/param.h>
     42        1.1  christos #include <sys/conf.h>
     43        1.1  christos #include <sys/ioctl.h>
     44  1.13.26.1    cherry #include <sys/mman.h>
     45  1.13.26.1    cherry #include <sys/uio.h>
     46       1.13     oster #include <sys/termios.h>
     47        1.2   gehenna 
     48  1.13.26.1    cherry #include <dev/mm.h>
     49  1.13.26.1    cherry 
     50  1.13.26.1    cherry #include <uvm/uvm_extern.h>
     51  1.13.26.1    cherry 
     52  1.13.26.1    cherry static void *		dev_zero_page	__read_mostly;
     53  1.13.26.1    cherry static kmutex_t		dev_mem_lock	__cacheline_aligned;
     54  1.13.26.1    cherry static vaddr_t		dev_mem_addr	__read_mostly;
     55  1.13.26.1    cherry 
     56  1.13.26.1    cherry static dev_type_read(mm_readwrite);
     57  1.13.26.1    cherry static dev_type_ioctl(mm_ioctl);
     58  1.13.26.1    cherry static dev_type_mmap(mm_mmap);
     59  1.13.26.1    cherry static dev_type_ioctl(mm_ioctl);
     60  1.13.26.1    cherry 
     61  1.13.26.1    cherry const struct cdevsw mem_cdevsw = {
     62  1.13.26.1    cherry #ifdef __HAVE_MM_MD_OPEN
     63  1.13.26.1    cherry 	mm_md_open,
     64  1.13.26.1    cherry #else
     65  1.13.26.1    cherry 	nullopen,
     66  1.13.26.1    cherry #endif
     67  1.13.26.1    cherry 	nullclose, mm_readwrite, mm_readwrite,
     68  1.13.26.1    cherry 	mm_ioctl, nostop, notty, nopoll, mm_mmap, nokqfilter,
     69  1.13.26.1    cherry 	D_MPSAFE
     70  1.13.26.1    cherry };
     71  1.13.26.1    cherry 
     72  1.13.26.1    cherry #ifdef pmax	/* XXX */
     73  1.13.26.1    cherry const struct cdevsw mem_ultrix_cdevsw = {
     74  1.13.26.1    cherry 	nullopen, nullclose, mm_readwrite, mm_readwrite, mm_ioctl,
     75  1.13.26.1    cherry 	nostop, notty, nopoll, mm_mmap, nokqfilter, D_MPSAFE
     76  1.13.26.1    cherry };
     77  1.13.26.1    cherry #endif
     78  1.13.26.1    cherry 
     79  1.13.26.1    cherry /*
     80  1.13.26.1    cherry  * mm_init: initialize memory device driver.
     81  1.13.26.1    cherry  */
     82  1.13.26.1    cherry void
     83  1.13.26.1    cherry mm_init(void)
     84  1.13.26.1    cherry {
     85  1.13.26.1    cherry 	vaddr_t pg;
     86  1.13.26.1    cherry 
     87  1.13.26.1    cherry 	mutex_init(&dev_mem_lock, MUTEX_DEFAULT, IPL_NONE);
     88  1.13.26.1    cherry 
     89  1.13.26.1    cherry 	/* Read-only zero-page. */
     90  1.13.26.1    cherry 	pg = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
     91  1.13.26.1    cherry 	KASSERT(pg != 0);
     92  1.13.26.1    cherry #if 0
     93  1.13.26.1    cherry 	pmap_protect(pmap_kernel(), pg, pg + PAGE_SIZE, VM_PROT_READ);
     94  1.13.26.1    cherry #endif
     95  1.13.26.1    cherry 	pmap_update(pmap_kernel());
     96  1.13.26.1    cherry 	dev_zero_page = (void *)pg;
     97  1.13.26.1    cherry 
     98  1.13.26.1    cherry #ifndef __HAVE_MM_MD_CACHE_ALIASING
     99  1.13.26.1    cherry 	/* KVA for mappings during I/O. */
    100  1.13.26.1    cherry 	dev_mem_addr = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
    101  1.13.26.1    cherry 	    UVM_KMF_VAONLY|UVM_KMF_WAITVA);
    102  1.13.26.1    cherry 	KASSERT(dev_mem_addr != 0);
    103  1.13.26.1    cherry #else
    104  1.13.26.1    cherry 	dev_mem_addr = 0;
    105  1.13.26.1    cherry #endif
    106  1.13.26.1    cherry }
    107  1.13.26.1    cherry 
    108  1.13.26.1    cherry 
    109  1.13.26.1    cherry /*
    110  1.13.26.1    cherry  * dev_mem_getva: get a special virtual address.  If architecture requires,
    111  1.13.26.1    cherry  * allocate VA according to PA, which avoids cache-aliasing issues.  Use a
    112  1.13.26.1    cherry  * constant, general mapping address otherwise.
    113  1.13.26.1    cherry  */
    114  1.13.26.1    cherry static inline vaddr_t
    115  1.13.26.1    cherry dev_mem_getva(paddr_t pa)
    116  1.13.26.1    cherry {
    117  1.13.26.1    cherry #ifdef __HAVE_MM_MD_CACHE_ALIASING
    118  1.13.26.1    cherry 	const vsize_t coloroff = trunc_page(pa) & ptoa(uvmexp.colormask);
    119  1.13.26.1    cherry 	const vaddr_t kva = uvm_km_alloc(kernel_map, PAGE_SIZE + coloroff,
    120  1.13.26.1    cherry 	    ptoa(uvmexp.ncolors), UVM_KMF_VAONLY | UVM_KMF_WAITVA);
    121  1.13.26.1    cherry 
    122  1.13.26.1    cherry 	return kva + coloroff;
    123  1.13.26.1    cherry #else
    124  1.13.26.1    cherry 	return dev_mem_addr;
    125  1.13.26.1    cherry #endif
    126  1.13.26.1    cherry }
    127  1.13.26.1    cherry 
    128  1.13.26.1    cherry static inline void
    129  1.13.26.1    cherry dev_mem_relva(paddr_t pa, vaddr_t va)
    130  1.13.26.1    cherry {
    131  1.13.26.1    cherry #ifdef __HAVE_MM_MD_CACHE_ALIASING
    132  1.13.26.1    cherry 	const vsize_t coloroff = trunc_page(pa) & ptoa(uvmexp.colormask);
    133  1.13.26.1    cherry 	const vaddr_t origva = va - coloroff;
    134  1.13.26.1    cherry 
    135  1.13.26.1    cherry 	uvm_km_free(kernel_map, origva, PAGE_SIZE + coloroff, UVM_KMF_VAONLY);
    136  1.13.26.1    cherry #else
    137  1.13.26.1    cherry 	KASSERT(dev_mem_addr == va);
    138  1.13.26.1    cherry #endif
    139  1.13.26.1    cherry }
    140  1.13.26.1    cherry 
    141  1.13.26.1    cherry /*
    142  1.13.26.1    cherry  * dev_kmem_readwrite: helper for DEV_MEM (/dev/mem) case of R/W.
    143  1.13.26.1    cherry  */
    144  1.13.26.1    cherry static int
    145  1.13.26.1    cherry dev_mem_readwrite(struct uio *uio, struct iovec *iov)
    146  1.13.26.1    cherry {
    147  1.13.26.1    cherry 	paddr_t paddr;
    148  1.13.26.1    cherry 	vaddr_t vaddr;
    149  1.13.26.1    cherry 	vm_prot_t prot;
    150  1.13.26.1    cherry 	size_t len, offset;
    151  1.13.26.1    cherry 	bool have_direct;
    152  1.13.26.1    cherry 	int error;
    153  1.13.26.1    cherry 
    154  1.13.26.1    cherry 	/* Check for wrap around. */
    155  1.13.26.1    cherry 	if ((intptr_t)uio->uio_offset != uio->uio_offset) {
    156  1.13.26.1    cherry 		return EFAULT;
    157  1.13.26.1    cherry 	}
    158  1.13.26.1    cherry 	paddr = uio->uio_offset & ~PAGE_MASK;
    159  1.13.26.1    cherry 	prot = (uio->uio_rw == UIO_WRITE) ? VM_PROT_WRITE : VM_PROT_READ;
    160  1.13.26.1    cherry 	error = mm_md_physacc(paddr, prot);
    161  1.13.26.1    cherry 	if (error) {
    162  1.13.26.1    cherry 		return error;
    163  1.13.26.1    cherry 	}
    164  1.13.26.1    cherry 	offset = uio->uio_offset & PAGE_MASK;
    165  1.13.26.1    cherry 	len = MIN(uio->uio_resid, PAGE_SIZE - offset);
    166  1.13.26.1    cherry 
    167  1.13.26.1    cherry #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
    168  1.13.26.1    cherry 	/* Is physical address directly mapped?  Return VA. */
    169  1.13.26.1    cherry 	have_direct = mm_md_direct_mapped_phys(paddr, &vaddr);
    170  1.13.26.1    cherry #else
    171  1.13.26.1    cherry 	vaddr = 0;
    172  1.13.26.1    cherry 	have_direct = false;
    173  1.13.26.1    cherry #endif
    174  1.13.26.1    cherry 	if (!have_direct) {
    175  1.13.26.1    cherry 		/* Get a special virtual address. */
    176  1.13.26.1    cherry 		const vaddr_t va = dev_mem_getva(paddr);
    177  1.13.26.1    cherry 
    178  1.13.26.1    cherry 		/* Map selected KVA to physical address. */
    179  1.13.26.1    cherry 		mutex_enter(&dev_mem_lock);
    180  1.13.26.1    cherry 		pmap_kenter_pa(va, paddr, prot, 0);
    181  1.13.26.1    cherry 		pmap_update(pmap_kernel());
    182  1.13.26.1    cherry 
    183  1.13.26.1    cherry 		/* Perform I/O. */
    184  1.13.26.1    cherry 		vaddr = va + offset;
    185  1.13.26.1    cherry 		error = uiomove((void *)vaddr, len, uio);
    186  1.13.26.1    cherry 
    187  1.13.26.1    cherry 		/* Unmap, flush before unlock. */
    188  1.13.26.1    cherry 		pmap_kremove(va, PAGE_SIZE);
    189  1.13.26.1    cherry 		pmap_update(pmap_kernel());
    190  1.13.26.1    cherry 		mutex_exit(&dev_mem_lock);
    191  1.13.26.1    cherry 
    192  1.13.26.1    cherry 		/* "Release" the virtual address. */
    193  1.13.26.1    cherry 		dev_mem_relva(paddr, va);
    194  1.13.26.1    cherry 	} else {
    195  1.13.26.1    cherry 		/* Direct map, just perform I/O. */
    196  1.13.26.1    cherry 		vaddr += offset;
    197  1.13.26.1    cherry 		error = uiomove((void *)vaddr, len, uio);
    198  1.13.26.1    cherry 	}
    199  1.13.26.1    cherry 	return error;
    200  1.13.26.1    cherry }
    201  1.13.26.1    cherry 
    202  1.13.26.1    cherry /*
    203  1.13.26.1    cherry  * dev_kmem_readwrite: helper for DEV_KMEM (/dev/kmem) case of R/W.
    204  1.13.26.1    cherry  */
    205  1.13.26.1    cherry static int
    206  1.13.26.1    cherry dev_kmem_readwrite(struct uio *uio, struct iovec *iov)
    207  1.13.26.1    cherry {
    208  1.13.26.1    cherry 	void *addr;
    209  1.13.26.1    cherry 	size_t len, offset;
    210  1.13.26.1    cherry 	vm_prot_t prot;
    211  1.13.26.1    cherry 	int error;
    212  1.13.26.1    cherry 	bool md_kva;
    213  1.13.26.1    cherry 
    214  1.13.26.1    cherry 	/* Check for wrap around. */
    215  1.13.26.1    cherry 	addr = (void *)(intptr_t)uio->uio_offset;
    216  1.13.26.1    cherry 	if ((uintptr_t)addr != uio->uio_offset) {
    217  1.13.26.1    cherry 		return EFAULT;
    218  1.13.26.1    cherry 	}
    219  1.13.26.1    cherry 	/*
    220  1.13.26.1    cherry 	 * Handle non-page aligned offset.
    221  1.13.26.1    cherry 	 * Otherwise, we operate in page-by-page basis.
    222  1.13.26.1    cherry 	 */
    223  1.13.26.1    cherry 	offset = uio->uio_offset & PAGE_MASK;
    224  1.13.26.1    cherry 	len = MIN(uio->uio_resid, PAGE_SIZE - offset);
    225  1.13.26.1    cherry 	prot = (uio->uio_rw == UIO_WRITE) ? VM_PROT_WRITE : VM_PROT_READ;
    226  1.13.26.1    cherry 
    227  1.13.26.1    cherry 	md_kva = false;
    228  1.13.26.1    cherry 
    229  1.13.26.1    cherry #ifdef __HAVE_MM_MD_DIRECT_MAPPED_IO
    230  1.13.26.1    cherry 	paddr_t paddr;
    231  1.13.26.1    cherry 	/* MD case: is this is a directly mapped address? */
    232  1.13.26.1    cherry 	if (mm_md_direct_mapped_io(addr, &paddr)) {
    233  1.13.26.1    cherry 		/* If so, validate physical address. */
    234  1.13.26.1    cherry 		error = mm_md_physacc(paddr, prot);
    235  1.13.26.1    cherry 		if (error) {
    236  1.13.26.1    cherry 			return error;
    237  1.13.26.1    cherry 		}
    238  1.13.26.1    cherry 		md_kva = true;
    239  1.13.26.1    cherry 	}
    240  1.13.26.1    cherry #endif
    241  1.13.26.1    cherry 	if (!md_kva) {
    242  1.13.26.1    cherry 		bool checked = false;
    243  1.13.26.1    cherry 
    244  1.13.26.1    cherry #ifdef __HAVE_MM_MD_KERNACC
    245  1.13.26.1    cherry 		/* MD check for the address. */
    246  1.13.26.1    cherry 		error = mm_md_kernacc(addr, prot, &checked);
    247  1.13.26.1    cherry 		if (error) {
    248  1.13.26.1    cherry 			return error;
    249  1.13.26.1    cherry 		}
    250  1.13.26.1    cherry #endif
    251  1.13.26.1    cherry 		/* UVM check for the address (unless MD indicated to not). */
    252  1.13.26.1    cherry 		if (!checked && !uvm_kernacc(addr, len, prot)) {
    253  1.13.26.1    cherry 			return EFAULT;
    254  1.13.26.1    cherry 		}
    255  1.13.26.1    cherry 	}
    256  1.13.26.1    cherry 	error = uiomove(addr, len, uio);
    257  1.13.26.1    cherry 	return error;
    258  1.13.26.1    cherry }
    259  1.13.26.1    cherry 
    260  1.13.26.1    cherry /*
    261  1.13.26.1    cherry  * dev_zero_readwrite: helper for DEV_ZERO (/dev/null) case of R/W.
    262  1.13.26.1    cherry  */
    263  1.13.26.1    cherry static inline int
    264  1.13.26.1    cherry dev_zero_readwrite(struct uio *uio, struct iovec *iov)
    265  1.13.26.1    cherry {
    266  1.13.26.1    cherry 	size_t len;
    267  1.13.26.1    cherry 
    268  1.13.26.1    cherry 	/* Nothing to do for the write case. */
    269  1.13.26.1    cherry 	if (uio->uio_rw == UIO_WRITE) {
    270  1.13.26.1    cherry 		uio->uio_resid = 0;
    271  1.13.26.1    cherry 		return 0;
    272  1.13.26.1    cherry 	}
    273  1.13.26.1    cherry 	/*
    274  1.13.26.1    cherry 	 * Read in page-by-page basis, caller will continue.
    275  1.13.26.1    cherry 	 * Cut appropriately for a single/last-iteration cases.
    276  1.13.26.1    cherry 	 */
    277  1.13.26.1    cherry 	len = MIN(iov->iov_len, PAGE_SIZE);
    278  1.13.26.1    cherry 	return uiomove(dev_zero_page, len, uio);
    279  1.13.26.1    cherry }
    280        1.1  christos 
    281  1.13.26.1    cherry /*
    282  1.13.26.1    cherry  * mm_readwrite: general memory R/W function.
    283  1.13.26.1    cherry  */
    284  1.13.26.1    cherry static int
    285  1.13.26.1    cherry mm_readwrite(dev_t dev, struct uio *uio, int flags)
    286        1.1  christos {
    287  1.13.26.1    cherry 	struct iovec *iov;
    288  1.13.26.1    cherry 	int error;
    289  1.13.26.1    cherry 
    290  1.13.26.1    cherry #ifdef __HAVE_MM_MD_READWRITE
    291  1.13.26.1    cherry 	/* If defined - there are extra MD cases. */
    292        1.1  christos 	switch (minor(dev)) {
    293  1.13.26.1    cherry 	case DEV_MEM:
    294  1.13.26.1    cherry 	case DEV_KMEM:
    295  1.13.26.1    cherry 	case DEV_NULL:
    296  1.13.26.1    cherry 	case DEV_ZERO:
    297  1.13.26.1    cherry #if defined(COMPAT_16) && defined(__arm)
    298  1.13.26.1    cherry 	case _DEV_ZERO_oARM:
    299  1.13.26.1    cherry #endif
    300  1.13.26.1    cherry 		break;
    301        1.6  jdolecek 	default:
    302  1.13.26.1    cherry 		return mm_md_readwrite(dev, uio);
    303  1.13.26.1    cherry 	}
    304  1.13.26.1    cherry #endif
    305  1.13.26.1    cherry 	error = 0;
    306  1.13.26.1    cherry 	while (uio->uio_resid > 0 && error == 0) {
    307  1.13.26.1    cherry 		iov = uio->uio_iov;
    308  1.13.26.1    cherry 		if (iov->iov_len == 0) {
    309  1.13.26.1    cherry 			/* Processed; next I/O vector. */
    310  1.13.26.1    cherry 			uio->uio_iov++;
    311  1.13.26.1    cherry 			uio->uio_iovcnt--;
    312  1.13.26.1    cherry 			KASSERT(uio->uio_iovcnt >= 0);
    313  1.13.26.1    cherry 			continue;
    314  1.13.26.1    cherry 		}
    315  1.13.26.1    cherry 		/* Helper functions will process in page-by-page basis. */
    316  1.13.26.1    cherry 		switch (minor(dev)) {
    317  1.13.26.1    cherry 		case DEV_MEM:
    318  1.13.26.1    cherry 			error = dev_mem_readwrite(uio, iov);
    319  1.13.26.1    cherry 			break;
    320  1.13.26.1    cherry 		case DEV_KMEM:
    321  1.13.26.1    cherry 			error = dev_kmem_readwrite(uio, iov);
    322  1.13.26.1    cherry 			break;
    323  1.13.26.1    cherry 		case DEV_NULL:
    324  1.13.26.1    cherry 			if (uio->uio_rw == UIO_WRITE) {
    325  1.13.26.1    cherry 				uio->uio_resid = 0;
    326  1.13.26.1    cherry 			}
    327  1.13.26.1    cherry 			/* Break directly out of the loop. */
    328        1.1  christos 			return 0;
    329  1.13.26.1    cherry #if defined(COMPAT_16) && defined(__arm)
    330  1.13.26.1    cherry 		case _DEV_ZERO_oARM:
    331  1.13.26.1    cherry #endif
    332  1.13.26.1    cherry 		case DEV_ZERO:
    333  1.13.26.1    cherry 			error = dev_zero_readwrite(uio, iov);
    334  1.13.26.1    cherry 			break;
    335  1.13.26.1    cherry 		default:
    336  1.13.26.1    cherry 			error = ENXIO;
    337  1.13.26.1    cherry 			break;
    338        1.1  christos 		}
    339  1.13.26.1    cherry 	}
    340  1.13.26.1    cherry 	return error;
    341  1.13.26.1    cherry }
    342  1.13.26.1    cherry 
    343  1.13.26.1    cherry /*
    344  1.13.26.1    cherry  * mm_mmap: general mmap() handler.
    345  1.13.26.1    cherry  */
    346  1.13.26.1    cherry static paddr_t
    347  1.13.26.1    cherry mm_mmap(dev_t dev, off_t off, int acc)
    348  1.13.26.1    cherry {
    349  1.13.26.1    cherry 	vm_prot_t prot;
    350  1.13.26.1    cherry 
    351  1.13.26.1    cherry #ifdef __HAVE_MM_MD_MMAP
    352  1.13.26.1    cherry 	/* If defined - there are extra mmap() MD cases. */
    353  1.13.26.1    cherry 	switch (minor(dev)) {
    354  1.13.26.1    cherry 	case DEV_MEM:
    355  1.13.26.1    cherry 	case DEV_KMEM:
    356  1.13.26.1    cherry 	case DEV_NULL:
    357  1.13.26.1    cherry #if defined(COMPAT_16) && defined(__arm)
    358  1.13.26.1    cherry 	case _DEV_ZERO_oARM:
    359  1.13.26.1    cherry #endif
    360  1.13.26.1    cherry 	case DEV_ZERO:
    361  1.13.26.1    cherry 		break;
    362  1.13.26.1    cherry 	default:
    363  1.13.26.1    cherry 		return mm_md_mmap(dev, off, acc);
    364  1.13.26.1    cherry 	}
    365  1.13.26.1    cherry #endif
    366  1.13.26.1    cherry 	/*
    367  1.13.26.1    cherry 	 * /dev/null does not make sense, /dev/kmem is volatile and
    368  1.13.26.1    cherry 	 * /dev/zero is handled in mmap already.
    369  1.13.26.1    cherry 	 */
    370  1.13.26.1    cherry 	if (minor(dev) != DEV_MEM) {
    371  1.13.26.1    cherry 		return -1;
    372  1.13.26.1    cherry 	}
    373  1.13.26.1    cherry 
    374  1.13.26.1    cherry 	prot = 0;
    375  1.13.26.1    cherry 	if (acc & PROT_EXEC)
    376  1.13.26.1    cherry 		prot |= VM_PROT_EXECUTE;
    377  1.13.26.1    cherry 	if (acc & PROT_READ)
    378  1.13.26.1    cherry 		prot |= VM_PROT_READ;
    379  1.13.26.1    cherry 	if (acc & PROT_WRITE)
    380  1.13.26.1    cherry 		prot |= VM_PROT_WRITE;
    381  1.13.26.1    cherry 
    382  1.13.26.1    cherry 	/* Validate the physical address. */
    383  1.13.26.1    cherry 	if (mm_md_physacc(off, prot) != 0) {
    384  1.13.26.1    cherry 		return -1;
    385  1.13.26.1    cherry 	}
    386  1.13.26.1    cherry 	return off >> PGSHIFT;
    387  1.13.26.1    cherry }
    388  1.13.26.1    cherry 
    389  1.13.26.1    cherry static int
    390  1.13.26.1    cherry mm_ioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
    391  1.13.26.1    cherry {
    392  1.13.26.1    cherry 
    393  1.13.26.1    cherry 	switch (cmd) {
    394  1.13.26.1    cherry 	case FIONBIO:
    395  1.13.26.1    cherry 		/* We never block anyway. */
    396  1.13.26.1    cherry 		return 0;
    397  1.13.26.1    cherry 
    398  1.13.26.1    cherry 	case FIOSETOWN:
    399  1.13.26.1    cherry 	case FIOGETOWN:
    400  1.13.26.1    cherry 	case TIOCGPGRP:
    401  1.13.26.1    cherry 	case TIOCSPGRP:
    402  1.13.26.1    cherry 	case TIOCGETA:
    403  1.13.26.1    cherry 		return ENOTTY;
    404  1.13.26.1    cherry 
    405  1.13.26.1    cherry 	case FIOASYNC:
    406  1.13.26.1    cherry 		if ((*(int *)data) == 0) {
    407  1.13.26.1    cherry 			return 0;
    408  1.13.26.1    cherry 		}
    409  1.13.26.1    cherry 		/* FALLTHROUGH */
    410  1.13.26.1    cherry 	default:
    411        1.1  christos 		return EOPNOTSUPP;
    412        1.1  christos 	}
    413        1.1  christos }
    414