MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


Kernel Functions for Drivers                      ddicopyout(9F)



NAME
     ddicopyout - copy data from a driver

SYNOPSIS
     #include 
     #include 
     #include 



     int ddicopyout(const void *driverbuf, void *buf, sizet cn, int flags);


INTERFACE LEVEL
     Solaris DI specific (Solaris DI).

PARAMETERS
     driverbuf    Source address in the  driver  from  which  the
                  data is transferred.


     buf          Destination  address  to  which  the  data   is
                  transferred.


     cn           Number of bytes to copy.


     flags        Set of flag bits  that  provide  address  space
                  information about buf.


DESCRIPTION
     This routine is designed for use in  driver  ioctl(9E)  rou-
     tines for drivers that support layered ioctls. ddicopyout()
     copies data from a driver buffer to a  destination  address,
     buf.


     The flags argument determines the address space  information
     about  buf.  If the FKIOCTL flag is set, this indicates that
     buf is a kernel address,  and   ddicopyout()  behaves  like
     bcopy(9F).  Otherwise,   buf is interpreted as a user buffer
     address, and ddicopyout() behaves like copyout(9F).


     Addresses that are word-aligned are moved most  efficiently.
     However,  the  driver  developer  is  not  obliged to ensure
     alignment.  This function automatically finds the most effi-
     cient move algorithm according to address alignment.





SunOS 5.11          Last change: 19 Apr 2000                    1






Kernel Functions for Drivers                      ddicopyout(9F)



RETURN VALUES
     Under normal conditions, 0 is returned to  indicate  a  suc-
     cessful  copy.  Otherwise, -1 is returned if one of the fol-
     lowing occurs:

         o    Paging fault; the driver tried to access a page  of
              memory  for  which  it  did  not have read or write
              access.

         o    Invalid user address, such as a user area or  stack
              area.

         o    Invalid address that would have  resulted  in  data
              being copied into the user block.

         o    Hardware fault; a hardware error  prevented  access
              to  the  specified  user  memory.  For  example, an
              uncorrectable parity or EC error occurred.


     If -1 is returned to the caller, driver entry point routines
     should return EFAULT.

CONTEXT
     ddicopyout() can be called  from  user  or  kernel  context
     only.

EXAMPLES
     Example 1 ddicopyout() example


     A driver ioctl(9E) routine (line 12) can be used to  get  or
     set device attributes or registers. In the XGETREGS condi-
     tion (line 25), the driver copies the current device  regis-
     ter  values to another data area.  If the specified argument
     contains an invalid address, an error code is returned.


       1  struct device  {        /* layout of physical device registers  */
        2     int      control;    /* physical device control word  */
        3     int      status;     /* physical device status word   */
        4     short    recvchar;  /* receive character from device */
        5     short    xmitchar;  /* transmit character to device  */
        6  };

        7  struct devicestate {
        8     volatile struct device *regsp;   /* pointer to device registers */
        9     kmutext regmutex;              /* protect device registers */
              . . .
       10  };

       11  static void *statep; /* for soft state routines */



SunOS 5.11          Last change: 19 Apr 2000                    2






Kernel Functions for Drivers                      ddicopyout(9F)




       12  xxioctl(devt dev, int cmd, int arg, int mode,
       13      credt *credp, int *rvalp)
       14  {
       15      struct devicestate *sp;
       16      volatile struct device *rp;
       17      struct device regbuf;     /* temporary buffer for registers */
       18      int instance;

       19      instance = getminor(dev);
       20      sp = ddigetsoftstate(statep, instance);
       21      if (sp == NUL)
       22          return (ENXIO);
       23      rp = sp->regsp;
               . . .
       24      switch (cmd)  {

       25      case XGETREGS:   /* copy registers to arg */
       26            mutexenter(&sp->regmutex);
       27            /*
       28             * Copy data from device registers to
       29             * temporary device register buffer
       30             * e.g. regbuf.control = rp->control;
       31             */
       32            mutexexit(&sp->regmutex);
       33            if (ddicopyout(®buf, arg,
       34                sizeof (struct device), mode) != 0) {
       35                    return (EFAULT);
       36            }

       37            break;
       38      }
       39  }


SEE ALSO
     ioctl(9E),     bcopy(9F),      copyin(9F),      copyout(9F),
     ddicopyin(9F), uiomove(9F)


     Writing Device Drivers

NOTES
     The value of the flags argument to ddicopyout()  should  be
     passed  through  directly  from the mode argument of ioctl()
     untranslated.


     Driver defined locks should not be held across calls to this
     function.





SunOS 5.11          Last change: 19 Apr 2000                    3






Kernel Functions for Drivers                      ddicopyout(9F)



     ddicopyout() should not be used from a streams driver.  See
     MCOPYIN and MCOPYOUT in STREAMS Programming Guide.





















































SunOS 5.11          Last change: 19 Apr 2000                    4



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™