Print this page
10703 smatch unreachable code checking needs reworking
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2012 Garrett D'Amore <garrett@damore.org>.  All rights reserved.

  25  */
  26 
  27 #include <sys/sunddi.h>
  28 #include <sys/sunndi.h>
  29 #include <sys/iommulib.h>
  30 #include <sys/amd_iommu.h>
  31 #include <sys/pci_cap.h>
  32 #include <sys/bootconf.h>
  33 #include <sys/ddidmareq.h>
  34 
  35 #include "amd_iommu_impl.h"
  36 #include "amd_iommu_acpi.h"
  37 #include "amd_iommu_page_tables.h"
  38 
  39 static int amd_iommu_fini(amd_iommu_t *iommu, int type);
  40 static void amd_iommu_teardown_interrupts(amd_iommu_t *iommu);
  41 static void amd_iommu_stop(amd_iommu_t *iommu);
  42 
  43 static int amd_iommu_probe(iommulib_handle_t handle, dev_info_t *rdip);
  44 static int amd_iommu_allochdl(iommulib_handle_t handle,


1375         dev_info_t *pdip;
1376         const char *driver = ddi_driver_name(rdip);
1377         int instance = ddi_get_instance(rdip);
1378         const char *f = "amd_iommu_pci_dip";
1379 
1380         /* Hold rdip so it and its parents don't go away */
1381         ndi_hold_devi(rdip);
1382 
1383         if (ddi_is_pci_dip(rdip))
1384                 return (rdip);
1385 
1386         pdip = rdip;
1387         while (pdip = ddi_get_parent(pdip)) {
1388                 if (ddi_is_pci_dip(pdip)) {
1389                         ndi_hold_devi(pdip);
1390                         ndi_rele_devi(rdip);
1391                         return (pdip);
1392                 }
1393         }
1394 
1395         cmn_err(
1396 #ifdef  DEBUG
1397             CE_PANIC,

1398 #else
1399             CE_WARN,
1400 #endif  /* DEBUG */
1401             "%s: %s%d dip = %p has no PCI parent, path = %s",
1402             f, driver, instance, (void *)rdip, path);
1403 
1404         ndi_rele_devi(rdip);

1405 
1406         return (NULL);
1407 }
1408 
1409 /* Interface with IOMMULIB */
1410 /*ARGSUSED*/
1411 static int
1412 amd_iommu_probe(iommulib_handle_t handle, dev_info_t *rdip)
1413 {
1414         const char *driver = ddi_driver_name(rdip);
1415         char *s;
1416         int bus, device, func, bdf;
1417         amd_iommu_acpi_ivhd_t *hinfop;
1418         dev_info_t *pci_dip;
1419         amd_iommu_t *iommu = iommulib_iommu_getdata(handle);
1420         const char *f = "amd_iommu_probe";
1421         int instance = ddi_get_instance(iommu->aiomt_dip);
1422         const char *idriver = ddi_driver_name(iommu->aiomt_dip);
1423         char *path, *pathp;
1424 




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2012 Garrett D'Amore <garrett@damore.org>.  All rights reserved.
  25  * Copyright 2019 Joyent, Inc.
  26  */
  27 
  28 #include <sys/sunddi.h>
  29 #include <sys/sunndi.h>
  30 #include <sys/iommulib.h>
  31 #include <sys/amd_iommu.h>
  32 #include <sys/pci_cap.h>
  33 #include <sys/bootconf.h>
  34 #include <sys/ddidmareq.h>
  35 
  36 #include "amd_iommu_impl.h"
  37 #include "amd_iommu_acpi.h"
  38 #include "amd_iommu_page_tables.h"
  39 
  40 static int amd_iommu_fini(amd_iommu_t *iommu, int type);
  41 static void amd_iommu_teardown_interrupts(amd_iommu_t *iommu);
  42 static void amd_iommu_stop(amd_iommu_t *iommu);
  43 
  44 static int amd_iommu_probe(iommulib_handle_t handle, dev_info_t *rdip);
  45 static int amd_iommu_allochdl(iommulib_handle_t handle,


1376         dev_info_t *pdip;
1377         const char *driver = ddi_driver_name(rdip);
1378         int instance = ddi_get_instance(rdip);
1379         const char *f = "amd_iommu_pci_dip";
1380 
1381         /* Hold rdip so it and its parents don't go away */
1382         ndi_hold_devi(rdip);
1383 
1384         if (ddi_is_pci_dip(rdip))
1385                 return (rdip);
1386 
1387         pdip = rdip;
1388         while (pdip = ddi_get_parent(pdip)) {
1389                 if (ddi_is_pci_dip(pdip)) {
1390                         ndi_hold_devi(pdip);
1391                         ndi_rele_devi(rdip);
1392                         return (pdip);
1393                 }
1394         }
1395 

1396 #ifdef  DEBUG
1397         cmn_err(CE_PANIC, "%s: %s%d dip = %p has no PCI parent, path = %s",
1398             f, driver, instance, (void *)rdip, path);
1399 #else
1400         cmn_err(CE_WARN, "%s: %s%d dip = %p has no PCI parent, path = %s",


1401             f, driver, instance, (void *)rdip, path);

1402         ndi_rele_devi(rdip);
1403 #endif  /* DEBUG */
1404 
1405         return (NULL);
1406 }
1407 
1408 /* Interface with IOMMULIB */
1409 /*ARGSUSED*/
1410 static int
1411 amd_iommu_probe(iommulib_handle_t handle, dev_info_t *rdip)
1412 {
1413         const char *driver = ddi_driver_name(rdip);
1414         char *s;
1415         int bus, device, func, bdf;
1416         amd_iommu_acpi_ivhd_t *hinfop;
1417         dev_info_t *pci_dip;
1418         amd_iommu_t *iommu = iommulib_iommu_getdata(handle);
1419         const char *f = "amd_iommu_probe";
1420         int instance = ddi_get_instance(iommu->aiomt_dip);
1421         const char *idriver = ddi_driver_name(iommu->aiomt_dip);
1422         char *path, *pathp;
1423