openocd: src/target: replace the GPL-2.0-or-later license tag
[fw/openocd] / src / target / arm_adi_v5.c
index 84518b0a10199e856ddcb73a204fe0d12e2e7c8c..ff0d9b5495d6c2691a16eb20b2298eab1513e631 100644 (file)
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
 /***************************************************************************
  *   Copyright (C) 2006 by Magnus Lundin                                   *
  *   lundin@mlu.mine.nu                                                    *
  *   andreas.fritiofson@gmail.com                                          *
  *                                                                         *
  *   Copyright (C) 2019-2021, Ampere Computing LLC                         *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 /**
@@ -930,6 +919,7 @@ static const struct {
 #define DEVARCH_ID_MASK         (ARM_CS_C9_DEVARCH_ARCHITECT_MASK | ARM_CS_C9_DEVARCH_ARCHID_MASK)
 #define DEVARCH_MEM_AP          ARCH_ID(ARM_ID, 0x0A17)
 #define DEVARCH_ROM_C_0X9       ARCH_ID(ARM_ID, 0x0AF7)
+#define DEVARCH_UNKNOWN_V2      ARCH_ID(ARM_ID, 0x0A47)
 
 static const char *class0x9_devarch_description(uint32_t devarch)
 {
@@ -1844,8 +1834,16 @@ static int rtp_cs_component(enum coresight_access_mode mode, const struct rtp_op
                if ((v.devarch & ARM_CS_C9_DEVARCH_PRESENT) == 0)
                        return ERROR_OK;
 
-               if (is_mem_ap && (v.devarch & DEVARCH_ID_MASK) == DEVARCH_MEM_AP)
-                       *is_mem_ap = true;
+               if (is_mem_ap) {
+                       if ((v.devarch & DEVARCH_ID_MASK) == DEVARCH_MEM_AP)
+                               *is_mem_ap = true;
+
+                       /* SoC-600 APv1 Adapter */
+                       if ((v.devarch & DEVARCH_ID_MASK) == DEVARCH_UNKNOWN_V2 &&
+                                       ARM_CS_PIDR_DESIGNER(v.pid) == ARM_ID &&
+                                       ARM_CS_PIDR_PART(v.pid) == 0x9e5)
+                               *is_mem_ap = true;
+               }
 
                /* quit if not ROM table */
                if ((v.devarch & DEVARCH_ID_MASK) != DEVARCH_ROM_C_0X9)
@@ -1880,7 +1878,7 @@ static int rtp_ap(const struct rtp_ops *ops, struct adiv5_ap *ap, int depth)
 
                if (!is_mem_ap)
                        return ERROR_OK;
-               /* Continue for an ADIv6 MEM-AP */
+               /* Continue for an ADIv6 MEM-AP or SoC-600 APv1 Adapter */
        }
 
        /* Now we read ROM table ID registers, ref. ARM IHI 0029B sec  */
@@ -2124,6 +2122,7 @@ struct dap_lookup_data {
        unsigned int type;
        /* output */
        uint64_t component_base;
+       uint64_t ap_num;
 };
 
 static int dap_lookup_cs_component_cs_component(int retval,
@@ -2152,6 +2151,7 @@ static int dap_lookup_cs_component_cs_component(int retval,
 
        /* Found! */
        lookup->component_base = v->component_base;
+       lookup->ap_num = v->ap->ap_num;
        return CORESIGHT_COMPONENT_FOUND;
 }
 
@@ -2172,6 +2172,11 @@ int dap_lookup_cs_component(struct adiv5_ap *ap, uint8_t type,
 
        int retval = rtp_ap(&dap_lookup_cs_component_ops, ap, 0);
        if (retval == CORESIGHT_COMPONENT_FOUND) {
+               if (lookup.ap_num != ap->ap_num) {
+                       /* TODO: handle search from root ROM table */
+                       LOG_DEBUG("CS lookup ended in AP # 0x%" PRIx64 ". Ignore it", lookup.ap_num);
+                       return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
+               }
                LOG_DEBUG("CS lookup found at 0x%" PRIx64, lookup.component_base);
                *addr = lookup.component_base;
                return ERROR_OK;