The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/freebsd32/freebsd32_ioctl.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * SPDX-License-Identifier: BSD-3-Clause
    3  *
    4  * Copyright (c) 2008 David E. O'Brien
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. Neither the name of the author nor the names of its contributors
   16  *    may be used to endorse or promote products derived from this software
   17  *    without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __FBSDID("$FreeBSD$");
   34 
   35 #include <sys/param.h>
   36 #include <sys/capsicum.h>
   37 #include <sys/cdio.h>
   38 #include <sys/fcntl.h>
   39 #include <sys/filio.h>
   40 #include <sys/file.h>
   41 #include <sys/ioccom.h>
   42 #include <sys/malloc.h>
   43 #include <sys/memrange.h>
   44 #include <sys/pciio.h>
   45 #include <sys/proc.h>
   46 #include <sys/syscall.h>
   47 #include <sys/syscallsubr.h>
   48 #include <sys/sysctl.h>
   49 #include <sys/sysproto.h>
   50 #include <sys/systm.h>
   51 #include <sys/uio.h>
   52 
   53 #include <compat/freebsd32/freebsd32.h>
   54 #include <compat/freebsd32/freebsd32_ioctl.h>
   55 #include <compat/freebsd32/freebsd32_misc.h>
   56 #include <compat/freebsd32/freebsd32_proto.h>
   57 
   58 CTASSERT(sizeof(struct mem_range_op32) == 12);
   59 
   60 static int
   61 freebsd32_ioctl_memrange(struct thread *td,
   62     struct freebsd32_ioctl_args *uap, struct file *fp)
   63 {
   64         struct mem_range_op mro;
   65         struct mem_range_op32 mro32;
   66         int error;
   67         u_long com;
   68 
   69         if ((error = copyin(uap->data, &mro32, sizeof(mro32))) != 0)
   70                 return (error);
   71 
   72         PTRIN_CP(mro32, mro, mo_desc);
   73         CP(mro32, mro, mo_arg[0]);
   74         CP(mro32, mro, mo_arg[1]);
   75 
   76         com = 0;
   77         switch (uap->com) {
   78         case MEMRANGE_GET32:
   79                 com = MEMRANGE_GET;
   80                 break;
   81 
   82         case MEMRANGE_SET32:
   83                 com = MEMRANGE_SET;
   84                 break;
   85 
   86         default:
   87                 panic("%s: unknown MEMRANGE %#x", __func__, uap->com);
   88         }
   89 
   90         if ((error = fo_ioctl(fp, com, (caddr_t)&mro, td->td_ucred, td)) != 0)
   91                 return (error);
   92 
   93         if ( (com & IOC_OUT) ) {
   94                 CP(mro, mro32, mo_arg[0]);
   95                 CP(mro, mro32, mo_arg[1]);
   96 
   97                 error = copyout(&mro32, uap->data, sizeof(mro32));
   98         }
   99 
  100         return (error);
  101 }
  102 
  103 static int
  104 freebsd32_ioctl_barmmap(struct thread *td,
  105     struct freebsd32_ioctl_args *uap, struct file *fp)
  106 {
  107         struct pci_bar_mmap32 pbm32;
  108         struct pci_bar_mmap pbm;
  109         int error;
  110 
  111         error = copyin(uap->data, &pbm32, sizeof(pbm32));
  112         if (error != 0)
  113                 return (error);
  114         PTRIN_CP(pbm32, pbm, pbm_map_base);
  115         CP(pbm32, pbm, pbm_sel);
  116         CP(pbm32, pbm, pbm_reg);
  117         CP(pbm32, pbm, pbm_flags);
  118         CP(pbm32, pbm, pbm_memattr);
  119         pbm.pbm_bar_length = PAIR32TO64(uint64_t, pbm32.pbm_bar_length);
  120         error = fo_ioctl(fp, PCIOCBARMMAP, (caddr_t)&pbm, td->td_ucred, td);
  121         if (error == 0) {
  122                 PTROUT_CP(pbm, pbm32, pbm_map_base);
  123                 CP(pbm, pbm32, pbm_map_length);
  124 #if BYTE_ORDER == LITTLE_ENDIAN
  125                 pbm32.pbm_bar_length1 = pbm.pbm_bar_length;
  126                 pbm32.pbm_bar_length2 = pbm.pbm_bar_length >> 32;
  127 #else
  128                 pbm32.pbm_bar_length1 = pbm.pbm_bar_length >> 32;
  129                 pbm32.pbm_bar_length2 = pbm.pbm_bar_length;
  130 #endif
  131                 CP(pbm, pbm32, pbm_bar_off);
  132                 error = copyout(&pbm32, uap->data, sizeof(pbm32));
  133         }
  134         return (error);
  135 }
  136 
  137 static int
  138 freebsd32_ioctl_sg(struct thread *td,
  139     struct freebsd32_ioctl_args *uap, struct file *fp)
  140 {
  141         struct sg_io_hdr io;
  142         struct sg_io_hdr32 io32;
  143         int error;
  144 
  145         if ((error = copyin(uap->data, &io32, sizeof(io32))) != 0)
  146                 return (error);
  147 
  148         CP(io32, io, interface_id);
  149         CP(io32, io, dxfer_direction);
  150         CP(io32, io, cmd_len);
  151         CP(io32, io, mx_sb_len);
  152         CP(io32, io, iovec_count);
  153         CP(io32, io, dxfer_len);
  154         PTRIN_CP(io32, io, dxferp);
  155         PTRIN_CP(io32, io, cmdp);
  156         PTRIN_CP(io32, io, sbp);
  157         CP(io32, io, timeout);
  158         CP(io32, io, flags);
  159         CP(io32, io, pack_id);
  160         PTRIN_CP(io32, io, usr_ptr);
  161         CP(io32, io, status);
  162         CP(io32, io, masked_status);
  163         CP(io32, io, msg_status);
  164         CP(io32, io, sb_len_wr);
  165         CP(io32, io, host_status);
  166         CP(io32, io, driver_status);
  167         CP(io32, io, resid);
  168         CP(io32, io, duration);
  169         CP(io32, io, info);
  170 
  171         if ((error = fo_ioctl(fp, SG_IO, (caddr_t)&io, td->td_ucred, td)) != 0)
  172                 return (error);
  173 
  174         CP(io, io32, interface_id);
  175         CP(io, io32, dxfer_direction);
  176         CP(io, io32, cmd_len);
  177         CP(io, io32, mx_sb_len);
  178         CP(io, io32, iovec_count);
  179         CP(io, io32, dxfer_len);
  180         PTROUT_CP(io, io32, dxferp);
  181         PTROUT_CP(io, io32, cmdp);
  182         PTROUT_CP(io, io32, sbp);
  183         CP(io, io32, timeout);
  184         CP(io, io32, flags);
  185         CP(io, io32, pack_id);
  186         PTROUT_CP(io, io32, usr_ptr);
  187         CP(io, io32, status);
  188         CP(io, io32, masked_status);
  189         CP(io, io32, msg_status);
  190         CP(io, io32, sb_len_wr);
  191         CP(io, io32, host_status);
  192         CP(io, io32, driver_status);
  193         CP(io, io32, resid);
  194         CP(io, io32, duration);
  195         CP(io, io32, info);
  196 
  197         error = copyout(&io32, uap->data, sizeof(io32));
  198 
  199         return (error);
  200 }
  201 
  202 int
  203 freebsd32_ioctl(struct thread *td, struct freebsd32_ioctl_args *uap)
  204 {
  205         struct ioctl_args ap /*{
  206                 int     fd;
  207                 u_long  com;
  208                 caddr_t data;
  209         }*/ ;
  210         struct file *fp;
  211         cap_rights_t rights;
  212         int error;
  213 
  214         error = fget(td, uap->fd, cap_rights_init_one(&rights, CAP_IOCTL), &fp);
  215         if (error != 0)
  216                 return (error);
  217         if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
  218                 fdrop(fp, td);
  219                 return (EBADF);
  220         }
  221 
  222         switch (uap->com) {
  223         case MEMRANGE_GET32:    /* FALLTHROUGH */
  224         case MEMRANGE_SET32:
  225                 error = freebsd32_ioctl_memrange(td, uap, fp);
  226                 break;
  227 
  228         case SG_IO_32:
  229                 error = freebsd32_ioctl_sg(td, uap, fp);
  230                 break;
  231 
  232         case PCIOCBARMMAP_32:
  233                 error = freebsd32_ioctl_barmmap(td, uap, fp);
  234                 break;
  235 
  236         default:
  237                 fdrop(fp, td);
  238                 ap.fd = uap->fd;
  239                 ap.com = uap->com;
  240                 PTRIN_CP(*uap, ap, data);
  241                 return sys_ioctl(td, &ap);
  242         }
  243 
  244         fdrop(fp, td);
  245         return (error);
  246 }

Cache object: 4e51e36b1183bc346f5f883d422d695b


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.