⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sources.htm

📁 What is this ``device driver stuff anyway? Here s a very short introduction to the concept.
💻 HTM
📖 第 1 页 / 共 5 页
字号:
 * contains the strings that are stored in the     *
 * sysconfigtab database for this subsystem (the   *
 * /dev/none driver).                              *
 ***************************************************/
</p><p>
#define NONE_DEBUG
#ifdef NONE_DEBUG
        cfg_attr_t cfg_buf[MAX_DEVICE_CFG_ENTRIES]; 
#endif /* NONE_DEBUG */

</p><p>
</p></pre>
<p>
</p><p>
</p><pre>        switch (op) {
<p>
</p><p>
</p><p>
</p><p>
/***************************************************
 *            Configure (load) the driver.         *
 *                                                 *
 ***************************************************/
</p><p>
</p><p>
</p><p>
</p><p>
              case CFG_OP_CONFIGURE: 
</p><p>
#ifdef NONE_DEBUG
printf("none_configure: CFG_OP_CONFIGURE.\n");
#endif /* NONE_DEBUG */
</p><p>

/***************************************************
 *      Pass Attributes Verification               *
 *                                                 *
 * Attributes passed through the cfg_attr_t        *
 * structure are not known to be valid until the   *
 * /dev/none driver can check their status in the  *
 * indata argument.  A status other than           *
 * CFG_FRAME_SUCCESS is an error condition.  You   *
 * can use this code to:                           *
 *                                                 *
 *  o Check cfgmgr loading problems with the       *
 *    none_attributes (struct type                 *
 *    cfg_subsys_attr_t)                           *
 *                                                 *
 *  o Display the contents and status of the       *
 *    attributes in the sysconfigtab database for  *
 *    the /dev/none driver                         *
 *                                                 *
 *  o Report cfgmgr's status that indicates a      *
 *    failure to load any of the attribute fields  *
 *    into the none_attributes structure           *
 ***************************************************/


                bcopy(indata, cfg_buf[0].name, 
                      indatalen*(sizeof(cfg_attr_t)));
                  for(i=0; i &lt; indatalen; i++) 
                     switch(cfg_buf[i].type){ 
                         case CFG_ATTR_STRTYPE:
                           break;
                         default:
                           switch(cfg_buf[i].status){ 
                              case CFG_FRAME_SUCCESS:
                                break;
                              default:
                                 printf("%s:",cfg_buf[i].name); 
                                 switch(cfg_buf[i].status){ 
                                  case CFG_ATTR_EEXISTS: 
                                     printf("Attribute does not exist\n");
                                     break;
                                  case CFG_ATTR_EOP:
                                     printf("Attribute does not support operation\n");
                                     break;
                                  case CFG_ATTR_ESUBSYS:
                                     printf("Subsystem Failure\n");
                                     break;
                                  case CFG_ATTR_ESMALL:
                                     printf("Attribute size/value too small\n");
                                     break;
                                  case CFG_ATTR_ELARGE:
                                     printf("Attribute size/value too large\n");
                                     break;
                                  case CFG_ATTR_ETYPE:
                                     printf("Attribute invalid type\n");
                                     break;
                                  case CFG_ATTR_EINDEX:
                                     printf("Attribute invalid index\n");
                                     break;
                                     case CFG_ATTR_EMEM:
                                     printf("Attribute memory allocation error\n");
                                     break;
                                     default:
                                     printf("**Unknown attribute: ");
                                     printf("%x\n", cfg_buf[i].status);
                                     }
                       /*        return(EINVAL); */
                                 }
                         break;
                    }

        /*
         * If this device driver has already been configured,
         * either statically or dynamically, then return this
         * none_configure call indicating an error when the
         * cfgmgr framework calls the CFG_OP_CONFIGURE entry
         * point of the driver's configure interface.
         */
                             if(none_config == TRUE)
                                return(EINVAL); 
</p></pre>
<p>
</p><p>
</p><pre>/***************************************************
 * The following code performs a check on the      *
 * device driver name that  the cfgmgr             *
 * framework uses to statically or dynamically     *
 * configure the driver into the kernel.           *
 * If the device driver name is NULL,              *
 * subsequent code uses the controller name stored *
 * in the driver structure's ctlr_name member.     *
 * The driver structure for the /dev/none driver   *
 * is called nonedriver.  This structure was       *
 * declared and initialized to appropriate values  *
 * in the Declarations Section of the /dev/none    *
 * driver.                                         *
 *                                                 *
 * The name specified in the ctlr_name member will *
 * be replaced if the mcfgname variable is not     *
 * NULL.  The value stored in mcfgname             *
 * supersedes the controller name stored in        *
 * ctlr_name during configuration of the driver.   *
 ***************************************************/

                             if(strcmp(mcfgname,)==0) { 
                                /* If the operator is interested in
                                   knowing the configuration name of
                                   this driver, you can set this attribute
                                   to CFG_OP_QUERY in the driver's
                                   cfg_subsys_attr_t structure.

                                   The mcfgname variable is important
                                   because this name is later matched
                                   to the driver name in the Driver_Name
                                   field of the option data attribute
                                   for a specific bus.  This mechanism
                                   is how a hardware device is matched
                                   to its associated driver.
                                 */
                                  strcpy(mcfgname,"none"); 
                              }
                              else { 
                                /* mcfgname from sysconfigtab is used
                                   to configure the device driver in
                                   the following calls to the
                                   configure_driver interface.
                                 */
</pre>
<p>
</p><p>
</p><pre>              if(cfgmgr_get_state(mcfgname, &amp;driver_cfg_state) != ESUCCESS){
                   return(EINVAL); /* cfgmgr fatal error determining
                                     * the state of the "none" subsystem
                                     */
              }

              if(driver_cfg_state == SUBSYSTEM_STATICALLY_CONFIGURED)  { 

                 callback_return_status = ESUCCESS;

                 none_is_dynamic = SUBSYSTEM_STATICALLY_CONFIGURED;

                 register_callback(callback_register_configuration,
                                   CFG_PT_PRECONFIG,
                                   CFG_ORD_NOMINAL, (long) 0L );

                 register_callback(callback_register_major_number,
                                   CFG_PT_POSTCONFIG,
                                   CFG_ORD_NOMINAL, (long) 0L );
              }
              else { 


                 none_is_dynamic = SUBSYSTEM_DYNAMICALLY_CONFIGURED; 

                 retval = register_configuration(); 
                 if(retval != ESUCCESS)
                    return(retval); 

                 if((retval = configure_driver(mcfgname, DRIVER_WILDNUM,
                    DN_BUSNAME1, &amp;nonedriver)) != ESUCCESS) { 

                     return(retval);
                 }

                 retval = register_major_number(); 
                 if(retval != ESUCCESS) 
                    return(retval);

               }

             break;
</pre>
<p>
</p><p>
</p><pre><p>
</p><p>
</p><p>
</p><p>
/***************************************************
 * Unconfigure (unload) the driver.                *
 ***************************************************/
</p><p>
</p><p>
</p><p>
</p><p>
              case CFG_OP_UNCONFIGURE: 
</p><p>
</p><p>
</p><p>
</p><p>
/***************************************************
 *              DEBUG STATEMENT                    *
 ***************************************************/
#ifdef NONE_DEBUG
printf("none_configure: CFG_OP_UNCONFIGURE.\n");
#endif /* NONE_DEBUG */
/***************************************************
 *          Return ESUCCESS if the driver is not   *
 *          currently dynamically configured.  A   *
 *          statically configured driver CANNOT be *
 *          unconfigure/unloaded.                  *
 *                                                 *
 *          Static drivers will all physically     *
 *          remain in the kernel whether or not    *
 *          they are configured. Dynamic drivers   *
 *          when they are unconfigured are also    *
 *          unloaded from the kernel.              *
 ***************************************************/
</p><p>
</p><p>
</p><p>
</p><p>
                if(none_is_dynamic == SUBSYSTEM_STATICALLY_CONFIGURED)
{
                        return(ESUCCESS);
                } 
</p><p>
</p><p>
</p><p>
</p><p>
/***************************************************
 *          Do not allow the driver to be unloaded *
 *          if it is currently active.  To see if  *
 *          the driver is active look to see if    *
 *          any users have the device open.        *
 ***************************************************/
</p><p>
</p><p>
</p><p>
</p><p>
                for (i = 0; i &lt; num_none; i++) {
                        if (none_softc[i].sc_openf != 0) {
                                return(EBUSY);
                        } 
                }
</p><p>
</p><p>
</p><p>
</p><p>
/***************************************************
 *        Call cdevsw_del to remove the driver     *
 *        entry points from the in-memory resident *
 *        cdevsw table.  This is done prior to     *
 *        deleting the loadable configuration      *
 *        and handlers to prevent users from       *
 *        accessing the device in the middle of    *
 *        deconfigure operation.                   *
 ***************************************************/
</p><p>
</p><p>
</p><p>
</p><p>
                retval = devsw_del(mcfgname, MAJOR_INSTANCE);
                if (retval == NO_DEV) {
                        return(ESRCH);
                }  
</p><p>
</p><p>
</p><p>
</p><p>
/***************************************************
 *       Deregister the driver's configuration     *
 *       data structures from the hardware         *
 *       topology and cause the interrupt handlers *
 *       to be deleted.                            *
 ***************************************************/
</p><p>
</p><p>
</p><p>
</p><p>
</p><p>
</p><p>
</p><p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -