Print this page
Reduce lint
OS-3878 The pseudo nexus should be FMA capable
OS-3881 pseudonex_detach does not properly check the detach command
Reviewed by: Joshua M. Clulow <josh@sysmgr.org>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/pseudonex.c
          +++ new/usr/src/uts/common/io/pseudonex.c
↓ open down ↓ 75 lines elided ↑ open up ↑
  76   76   * Config information
  77   77   */
  78   78  static int pseudonex_intr_op(dev_info_t *dip, dev_info_t *rdip,
  79   79              ddi_intr_op_t op, ddi_intr_handle_impl_t *hdlp, void *result);
  80   80  
  81   81  static int pseudonex_attach(dev_info_t *, ddi_attach_cmd_t);
  82   82  static int pseudonex_detach(dev_info_t *, ddi_detach_cmd_t);
  83   83  static int pseudonex_open(dev_t *, int, int, cred_t *);
  84   84  static int pseudonex_close(dev_t, int, int, cred_t *);
  85   85  static int pseudonex_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
       86 +static int pseudonex_fm_init(dev_info_t *, dev_info_t *, int,
       87 +    ddi_iblock_cookie_t *);
  86   88  static int pseudonex_ctl(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *,
  87   89      void *);
  88   90  
  89   91  static void *pseudonex_state;
  90   92  
  91   93  typedef struct pseudonex_state {
  92   94          dev_info_t *pnx_devi;
       95 +        int pnx_fmcap;
       96 +        ddi_iblock_cookie_t pnx_fm_ibc;
  93   97  } pseudonex_state_t;
  94   98  
  95   99  static struct bus_ops pseudonex_bus_ops = {
  96  100          BUSO_REV,
  97  101          nullbusmap,             /* bus_map */
  98  102          NULL,                   /* bus_get_intrspec */
  99  103          NULL,                   /* bus_add_intrspec */
 100  104          NULL,                   /* bus_remove_intrspec */
 101  105          i_ddi_map_fault,        /* bus_map_fault */
 102  106          ddi_no_dma_map,         /* bus_dma_map */
↓ open down ↓ 6 lines elided ↑ open up ↑
 109  113          NULL,                   /* bus_dma_ctl */
 110  114          pseudonex_ctl,          /* bus_ctl */
 111  115          ddi_bus_prop_op,        /* bus_prop_op */
 112  116          0,                      /* bus_get_eventcookie */
 113  117          0,                      /* bus_add_eventcall */
 114  118          0,                      /* bus_remove_eventcall */
 115  119          0,                      /* bus_post_event */
 116  120          NULL,                   /* bus_intr_ctl */
 117  121          NULL,                   /* bus_config */
 118  122          NULL,                   /* bus_unconfig */
 119      -        NULL,                   /* bus_fm_init */
      123 +        pseudonex_fm_init,      /* bus_fm_init */
 120  124          NULL,                   /* bus_fm_fini */
 121  125          NULL,                   /* bus_fm_access_enter */
 122  126          NULL,                   /* bus_fm_access_exit */
 123  127          NULL,                   /* bus_power */
 124  128          pseudonex_intr_op       /* bus_intr_op */
 125  129  };
 126  130  
 127  131  static struct cb_ops pseudonex_cb_ops = {
 128  132          pseudonex_open,                 /* open */
 129  133          pseudonex_close,                /* close */
↓ open down ↓ 91 lines elided ↑ open up ↑
 221  225  
 222  226          /*
 223  227           * Save the devi for this instance in the soft_state data.
 224  228           */
 225  229          instance = ddi_get_instance(devi);
 226  230          if (ddi_soft_state_zalloc(pseudonex_state, instance) != DDI_SUCCESS)
 227  231                  return (DDI_FAILURE);
 228  232          pnx_state = ddi_get_soft_state(pseudonex_state, instance);
 229  233          pnx_state->pnx_devi = devi;
 230  234  
      235 +        pnx_state->pnx_fmcap = DDI_FM_EREPORT_CAPABLE;
      236 +        ddi_fm_init(devi, &pnx_state->pnx_fmcap, &pnx_state->pnx_fm_ibc);
      237 +
 231  238          if (ddi_create_minor_node(devi, "devctl", S_IFCHR, instance,
 232  239              DDI_NT_NEXUS, 0) != DDI_SUCCESS) {
 233  240                  ddi_remove_minor_node(devi, NULL);
 234  241                  ddi_soft_state_free(pseudonex_state, instance);
 235  242                  return (DDI_FAILURE);
 236  243          }
 237  244          ddi_report_dev(devi);
 238  245          return (DDI_SUCCESS);
 239  246  }
 240  247  
 241  248  /*ARGSUSED*/
 242  249  static int
 243  250  pseudonex_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
 244  251  {
 245  252          int instance = ddi_get_instance(devi);
 246  253  
 247  254          if (cmd == DDI_SUSPEND)
 248  255                  return (DDI_SUCCESS);
 249  256  
      257 +        if (cmd != DDI_DETACH)
      258 +                return (DDI_FAILURE);
      259 +
      260 +        ddi_fm_fini(devi);
 250  261          ddi_remove_minor_node(devi, NULL);
 251  262          ddi_soft_state_free(pseudonex_state, instance);
 252  263          return (DDI_SUCCESS);
 253  264  }
 254  265  
 255  266  /*ARGSUSED*/
 256  267  static int
 257  268  pseudonex_open(dev_t *devp, int flags, int otyp, cred_t *credp)
 258  269  {
 259  270          int instance;
↓ open down ↓ 107 lines elided ↑ open up ↑
 367  378                  }
 368  379                  if (tdip == NULL) {
 369  380                          UNLOCK_DEV_OPS(dmp);
 370  381                          return (inst);
 371  382                  }
 372  383          }
 373  384          UNLOCK_DEV_OPS(dmp);
 374  385          return (-1);
 375  386  }
 376  387  
      388 +/* ARGSUSED */
      389 +static int
      390 +pseudonex_fm_init(dev_info_t *dip, dev_info_t *tdip, int cap,
      391 +    ddi_iblock_cookie_t *ibc)
      392 +{
      393 +        pseudonex_state_t *pnx_state;
      394 +
      395 +        pnx_state = ddi_get_soft_state(pseudonex_state, ddi_get_instance(dip));
      396 +        ASSERT(pnx_state != NULL);
      397 +        ASSERT(ibc != NULL);
      398 +        *ibc = pnx_state->pnx_fm_ibc;
      399 +        return (pnx_state->pnx_fmcap & cap);
      400 +}
      401 +
 377  402  static int
 378  403  pseudonex_ctl(dev_info_t *dip, dev_info_t *rdip, ddi_ctl_enum_t ctlop,
 379  404      void *arg, void *result)
 380  405  {
 381  406          switch (ctlop) {
 382  407          case DDI_CTLOPS_REPORTDEV:
 383  408                  if (rdip == NULL)
 384  409                          return (DDI_FAILURE);
 385  410                  cmn_err(CE_CONT, "?pseudo-device: %s%d\n",
 386  411                      ddi_driver_name(rdip), ddi_get_instance(rdip));
↓ open down ↓ 151 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX