1 /* $NetBSD: ar5315_board.c,v 1.2 2009/07/06 00:43:22 alc Exp $ */ 2 3 /* 4 * Copyright (c) 2006 Urbana-Champaign Independent Media Center. 5 * Copyright (c) 2006 Garrett D'Amore. 6 * All rights reserved. 7 * 8 * Portions of this code were written by Garrett D'Amore for the 9 * Champaign-Urbana Community Wireless Network Project. 10 * 11 * Redistribution and use in source and binary forms, with or 12 * without modification, are permitted provided that the following 13 * conditions are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer in the documentation and/or other materials provided 19 * with the distribution. 20 * 3. All advertising materials mentioning features or use of this 21 * software must display the following acknowledgements: 22 * This product includes software developed by the Urbana-Champaign 23 * Independent Media Center. 24 * This product includes software developed by Garrett D'Amore. 25 * 4. Urbana-Champaign Independent Media Center's name and Garrett 26 * D'Amore's name may not be used to endorse or promote products 27 * derived from this software without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT 30 * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR 31 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 32 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT 34 * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT, 35 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 41 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 */ 43 44 /* 45 * This file provides code to locate board-specific configuration and radio 46 * information data in flash for the AR5315. 47 */ 48 #include <sys/cdefs.h> 49 __KERNEL_RCSID(0, "$NetBSD: ar5315_board.c,v 1.2 2009/07/06 00:43:22 alc Exp $"); 50 51 #include "opt_ddb.h" 52 #include "opt_kgdb.h" 53 54 #include "opt_memsize.h" 55 #include <sys/param.h> 56 #include <sys/systm.h> 57 #include <sys/kernel.h> 58 #include <sys/buf.h> 59 60 #include <dev/cons.h> 61 62 #include <mips/cache.h> 63 #include <mips/locore.h> 64 #include <mips/cpuregs.h> 65 66 #include <net/if.h> 67 #include <net/if_ether.h> 68 69 #include <ah_soc.h> /* XXX really doesn't belong in hal */ 70 71 #include <mips/atheros/include/ar5315reg.h> 72 #include <mips/atheros/include/ar531xvar.h> 73 #include <mips/atheros/include/arbusvar.h> 74 75 #include <machine/locore.h> 76 #include "com.h" 77 78 /* 79 * Locate the Board Configuration data using heuristics. 80 * Search backward from the (aliased) end of flash looking 81 * for the signature string that marks the start of the data. 82 * We search at most 500KB. 83 */ 84 const struct ar531x_boarddata * 85 ar531x_board_info(void) 86 { 87 static const struct ar531x_boarddata *board = NULL; 88 const uint8_t *ptr, *end; 89 90 if (board == NULL) { 91 92 /* search backward in the flash looking for the signature */ 93 ptr = (const uint8_t *) MIPS_PHYS_TO_KSEG1(AR5315_CONFIG_END 94 - 0x1000); 95 end = (const uint8_t *)AR5315_CONFIG_BASE; 96 /* XXX validate end */ 97 for (; ptr > end; ptr -= 0x1000) 98 if (*(const uint32_t *)ptr == AR531X_BD_MAGIC) { 99 board = (const struct ar531x_boarddata *) ptr; 100 break; 101 } 102 } 103 return board; 104 } 105 106 /* 107 * Locate the radio configuration data; it is located relative to the 108 * board configuration data. 109 */ 110 const void * 111 ar531x_radio_info(void) 112 { 113 static const void *radio = NULL; 114 const struct ar531x_boarddata *board; 115 const uint8_t *baddr, *ptr, *end; 116 117 if (radio) 118 goto done; 119 120 board = ar531x_board_info(); 121 if (board == NULL) 122 return NULL; 123 baddr = (const uint8_t *) board; 124 end = (const uint8_t *)MIPS_PHYS_TO_KSEG1(AR5315_RADIO_END); 125 126 for (ptr = baddr + 0x1000; ptr < end; ptr += 0x1000) 127 if (*(const uint32_t *)ptr != 0xffffffffU) { 128 radio = ptr; 129 goto done; 130 } 131 132 /* AR2316 moves radio data */ 133 for (ptr = baddr + 0xf8; ptr < end; ptr += 0x1000) 134 if (*(const uint32_t *)ptr != 0xffffffffU) { 135 radio = ptr; 136 goto done; 137 } 138 139 done: 140 return radio; 141 } 142 143 /* 144 * Locate board and radio configuration data in flash. 145 */ 146 int 147 ar531x_board_config(struct ar531x_config *config) 148 { 149 150 config->board = ar531x_board_info(); 151 if (config->board == NULL) 152 return ENOENT; 153 154 config->radio = ar531x_radio_info(); 155 if (config->radio == NULL) 156 return ENOENT; /* XXX distinct code */ 157 158 return 0; 159 } 160