1/* ********************************************************************* 2 * Broadcom Common Firmware Environment (CFE) 3 * 4 * SENTOSA-specific commands File: ui_sentosa.c 5 * 6 * A temporary sandbox for misc test routines and commands. 7 * 8 * Author: Mitch Lichtenberg 9 * 10 ********************************************************************* 11 * 12 * Copyright 2000,2001,2002,2003 13 * Broadcom Corporation. All rights reserved. 14 * 15 * This software is furnished under license and may be used and 16 * copied only in accordance with the following terms and 17 * conditions. Subject to these conditions, you may download, 18 * copy, install, use, modify and distribute modified or unmodified 19 * copies of this software in source and/or binary form. No title 20 * or ownership is transferred hereby. 21 * 22 * 1) Any source code used, modified or distributed must reproduce 23 * and retain this copyright notice and list of conditions 24 * as they appear in the source file. 25 * 26 * 2) No right is granted to use any trade name, trademark, or 27 * logo of Broadcom Corporation. The "Broadcom Corporation" 28 * name may not be used to endorse or promote products derived 29 * from this software without the prior written permission of 30 * Broadcom Corporation. 31 * 32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR 33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED 34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT 36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN 37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT, 38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF 44 * THE POSSIBILITY OF SUCH DAMAGE. 45 ********************************************************************* */ 46 47 48#include "cfe.h" 49#include "ui_command.h" 50 51#if CFG_PCI 52#include "pcivar.h" 53#endif 54 55#include "sbmips.h" 56#include "sb1250_regs.h" 57#include "sb1250_smbus.h" 58#include "sb1250_scd.h" 59 60#include "sentosa.h" 61 62/* ********************************************************************* 63 * Configuration 64 ********************************************************************* */ 65 66 67/* ********************************************************************* 68 * prototypes 69 ********************************************************************* */ 70 71int ui_init_swarmcmds(void); 72 73#if CFG_PCI 74static int ui_cmd_map_pci(ui_cmdline_t *cmd,int argc,char *argv[]); 75#endif 76 77 78/* ********************************************************************* 79 * Data 80 ********************************************************************* */ 81 82 83/* ********************************************************************* 84 * ui_init_swarmcmds() 85 * 86 * Add SWARM-specific commands to the command table 87 * 88 * Input parameters: 89 * nothing 90 * 91 * Return value: 92 * 0 93 ********************************************************************* */ 94 95 96int ui_init_swarmcmds(void) 97{ 98#if CFG_PCI 99 cmd_addcmd("map pci", 100 ui_cmd_map_pci, 101 NULL, 102 "Define a BAR0 window available to PCI devices", 103 "map pci offset size paddr [-off] [-l2ca] [-matchbits]\n\n" 104 "Map the region of size bytes starting at paddr to appear\n" 105 "at offset relative to BAR0\n", 106 "-off;Remove the region|" 107 "-l2ca;Make L2 cachable|" 108 "-matchbits;Use match bits policy"); 109#endif 110 return 0; 111} 112 113 114#if CFG_PCI 115static uint64_t parse_hex(const char *num) 116{ 117 uint64_t x = 0; 118 unsigned int digit; 119 120 if ((*num == '0') && (*(num+1) == 'x')) num += 2; 121 122 while (*num) { 123 if ((*num >= '0') && (*num <= '9')) { 124 digit = *num - '0'; 125 } 126 else if ((*num >= 'A') && (*num <= 'F')) { 127 digit = 10 + *num - 'A'; 128 } 129 else if ((*num >= 'a') && (*num <= 'f')) { 130 digit = 10 + *num - 'a'; 131 } 132 else { 133 break; 134 } 135 x *= 16; 136 x += digit; 137 num++; 138 } 139 140 return x; 141} 142 143static int ui_cmd_map_pci(ui_cmdline_t *cmd,int argc,char *argv[]) 144{ 145 unsigned long offset, size; 146 uint64_t paddr; 147 int l2ca, endian; 148 int enable; 149 int result; 150 151 enable = !cmd_sw_isset(cmd, "-off"); 152 if (enable) { 153 offset = parse_hex(cmd_getarg(cmd, 0)); 154 size = parse_hex(cmd_getarg(cmd, 1)); 155 paddr = parse_hex(cmd_getarg(cmd, 2)); 156 l2ca = cmd_sw_isset(cmd,"-l2ca"); 157 endian = cmd_sw_isset(cmd, "-matchbits"); 158 result = pci_map_window(paddr, offset, size, l2ca, endian); 159 } 160 else { 161 offset = parse_hex(cmd_getarg(cmd, 0)); 162 size = parse_hex(cmd_getarg(cmd, 1)); 163 result = pci_unmap_window(offset, size); 164 } 165 166 return result; 167} 168#endif 169