Print this page
5253 kmem_alloc/kmem_zalloc won't fail with KM_SLEEP
5254 getrbuf won't fail with KM_SLEEP


   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <sys/debug.h>
  30 #include <sys/types.h>
  31 #include <sys/param.h>
  32 #include <sys/time.h>
  33 #include <sys/buf.h>
  34 #include <sys/errno.h>
  35 #include <sys/systm.h>
  36 #include <sys/conf.h>
  37 #include <sys/signal.h>
  38 #include <sys/file.h>
  39 #include <sys/uio.h>
  40 #include <sys/ioctl.h>
  41 #include <sys/map.h>
  42 #include <sys/proc.h>
  43 #include <sys/user.h>
  44 #include <sys/mman.h>
  45 #include <sys/cred.h>
  46 #include <sys/open.h>
  47 #include <sys/stat.h>
  48 #include <sys/utsname.h>


 147         } else {
 148                 rc = DDI_WALK_CONTINUE;
 149         }
 150 
 151         return (rc);
 152 }
 153 
 154 gfxp_acc_handle_t
 155 gfxp_pci_init_handle(uint8_t bus, uint8_t slot, uint8_t function,
 156         uint16_t *vendor, uint16_t *device)
 157 {
 158         dev_info_t      *dip;
 159         gfxp_pci_bsf_t  *pci_bsf;
 160 
 161         /*
 162          * Find a PCI device based on its address, and return a unique handle
 163          * to be used in subsequent calls to read from or write to the config
 164          * space of this device.
 165          */
 166 
 167         if ((pci_bsf = kmem_zalloc(sizeof (gfxp_pci_bsf_t), KM_SLEEP))
 168                         == NULL) {
 169                 return (NULL);
 170         }
 171 
 172         pci_bsf->bus = bus;
 173         pci_bsf->slot = slot;
 174         pci_bsf->function = function;
 175 
 176         ddi_walk_devs(ddi_root_node(), gfxp_pci_find_bsf, pci_bsf);
 177 
 178         if (pci_bsf->found) {
 179                 dip = pci_bsf->dip;
 180 
 181                 if (vendor) *vendor = pci_bsf->vendor;
 182                 if (device) *device = pci_bsf->device;
 183         } else {
 184                 dip = NULL;
 185                 if (vendor) *vendor = 0x0000;
 186                 if (device) *device = 0x0000;
 187         }
 188 
 189         kmem_free(pci_bsf, sizeof (gfxp_pci_bsf_t));
 190 


 313         if ((vendor_id == pci_bsf->vendor) && (device_id == pci_bsf->device)) {
 314                 pci_bsf->found = 1;
 315                 rc = DDI_WALK_TERMINATE;
 316         } else {
 317                 rc = DDI_WALK_CONTINUE;
 318         }
 319 
 320         return (rc);
 321 }
 322 
 323 int
 324 gfxp_pci_device_present(uint16_t vendor, uint16_t device)
 325 {
 326         gfxp_pci_bsf_t  *pci_bsf;
 327         int             rv;
 328 
 329         /*
 330          * Find a PCI device based on its device and vendor id.
 331          */
 332 
 333         if ((pci_bsf = kmem_zalloc(sizeof (gfxp_pci_bsf_t), KM_SLEEP)) == NULL)
 334             return (0);
 335 
 336         pci_bsf->vendor = vendor;
 337         pci_bsf->device = device;
 338         ddi_walk_devs(ddi_root_node(), gfxp_pci_find_vd, pci_bsf);
 339 
 340         if (pci_bsf->found) {
 341                 rv = 1;
 342         } else {
 343                 rv = 0;
 344         }
 345 
 346         kmem_free(pci_bsf, sizeof (gfxp_pci_bsf_t));
 347 
 348         return (rv);
 349 }


   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 


  27 #include <sys/debug.h>
  28 #include <sys/types.h>
  29 #include <sys/param.h>
  30 #include <sys/time.h>
  31 #include <sys/buf.h>
  32 #include <sys/errno.h>
  33 #include <sys/systm.h>
  34 #include <sys/conf.h>
  35 #include <sys/signal.h>
  36 #include <sys/file.h>
  37 #include <sys/uio.h>
  38 #include <sys/ioctl.h>
  39 #include <sys/map.h>
  40 #include <sys/proc.h>
  41 #include <sys/user.h>
  42 #include <sys/mman.h>
  43 #include <sys/cred.h>
  44 #include <sys/open.h>
  45 #include <sys/stat.h>
  46 #include <sys/utsname.h>


 145         } else {
 146                 rc = DDI_WALK_CONTINUE;
 147         }
 148 
 149         return (rc);
 150 }
 151 
 152 gfxp_acc_handle_t
 153 gfxp_pci_init_handle(uint8_t bus, uint8_t slot, uint8_t function,
 154         uint16_t *vendor, uint16_t *device)
 155 {
 156         dev_info_t      *dip;
 157         gfxp_pci_bsf_t  *pci_bsf;
 158 
 159         /*
 160          * Find a PCI device based on its address, and return a unique handle
 161          * to be used in subsequent calls to read from or write to the config
 162          * space of this device.
 163          */
 164 
 165         pci_bsf = kmem_zalloc(sizeof (gfxp_pci_bsf_t), KM_SLEEP);



 166 
 167         pci_bsf->bus = bus;
 168         pci_bsf->slot = slot;
 169         pci_bsf->function = function;
 170 
 171         ddi_walk_devs(ddi_root_node(), gfxp_pci_find_bsf, pci_bsf);
 172 
 173         if (pci_bsf->found) {
 174                 dip = pci_bsf->dip;
 175 
 176                 if (vendor) *vendor = pci_bsf->vendor;
 177                 if (device) *device = pci_bsf->device;
 178         } else {
 179                 dip = NULL;
 180                 if (vendor) *vendor = 0x0000;
 181                 if (device) *device = 0x0000;
 182         }
 183 
 184         kmem_free(pci_bsf, sizeof (gfxp_pci_bsf_t));
 185 


 308         if ((vendor_id == pci_bsf->vendor) && (device_id == pci_bsf->device)) {
 309                 pci_bsf->found = 1;
 310                 rc = DDI_WALK_TERMINATE;
 311         } else {
 312                 rc = DDI_WALK_CONTINUE;
 313         }
 314 
 315         return (rc);
 316 }
 317 
 318 int
 319 gfxp_pci_device_present(uint16_t vendor, uint16_t device)
 320 {
 321         gfxp_pci_bsf_t  *pci_bsf;
 322         int             rv;
 323 
 324         /*
 325          * Find a PCI device based on its device and vendor id.
 326          */
 327 
 328         pci_bsf = kmem_zalloc(sizeof (gfxp_pci_bsf_t), KM_SLEEP);

 329 
 330         pci_bsf->vendor = vendor;
 331         pci_bsf->device = device;
 332         ddi_walk_devs(ddi_root_node(), gfxp_pci_find_vd, pci_bsf);
 333 
 334         if (pci_bsf->found) {
 335                 rv = 1;
 336         } else {
 337                 rv = 0;
 338         }
 339 
 340         kmem_free(pci_bsf, sizeof (gfxp_pci_bsf_t));
 341 
 342         return (rv);
 343 }