openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

phymod_symbol.c (1645B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  */
      7 
      8 /*******************************************************************************
      9  *
     10  * PHYMOD Symbol Routines
     11  */
     12 
     13 #include <phymod/phymod_symbols.h>
     14 #include <phymod/phymod_system.h>
     15 
     16 
     17 #if PHYMOD_CONFIG_INCLUDE_CHIP_SYMBOLS == 1
     18 
     19 static const void *
     20 __phymod_symbol_find(const char *name, const void *table, int size, int entry_size)
     21 {
     22     int i; 
     23     phymod_symbol_t *sym;
     24     unsigned char *ptr = (unsigned char*)table; 
     25 
     26     if (table == NULL) {
     27         return NULL;
     28     }
     29     
     30     for (i = 0; (sym = (phymod_symbol_t*)(ptr)) && (i < size); i++) {
     31 	if (PHYMOD_STRCMP(sym->name, name) == 0) {
     32 	    return (void*) sym; 
     33 	}
     34 #if PHYMOD_CONFIG_INCLUDE_ALIAS_NAMES == 1
     35 	if (sym->ufname && PHYMOD_STRCMP(sym->ufname, name) == 0) {
     36 	    return (void*) sym; 
     37 	}
     38 	if (sym->alias && PHYMOD_STRCMP(sym->alias, name) == 0) {
     39 	    return (void*) sym; 
     40 	}
     41 #endif
     42 	ptr += entry_size; 
     43     }
     44 
     45     return NULL; 
     46 }
     47 	
     48 
     49 const phymod_symbol_t *
     50 phymod_symbol_find(const char *name, const phymod_symbol_t *table, int size)
     51 {
     52     return (phymod_symbol_t*) __phymod_symbol_find(name, table, size, sizeof(phymod_symbol_t)); 
     53 }
     54 
     55 
     56 int 
     57 phymod_symbols_find(const char *name, const phymod_symbols_t *symbols, phymod_symbol_t *rsym)
     58 {
     59     const phymod_symbol_t *s = NULL; 
     60 
     61     if (rsym == NULL) return -1; 
     62 
     63     if ((symbols->symbols) && (s = phymod_symbol_find(name, symbols->symbols, symbols->size))) {
     64 	*rsym = *s;
     65 	return 0; 
     66     }
     67     return -1;
     68 }
     69 
     70 #endif