brintos

brintos / linux-shallow public Read only

0
0
Text · 7.9 KiB · 397a52f Raw
272 lines · c
1/*2 * Copyright (c) 2004-2011 Atheros Communications Inc.3 * Copyright (c) 2011 Qualcomm Atheros, Inc.4 *5 * Permission to use, copy, modify, and/or distribute this software for any6 * purpose with or without fee is hereby granted, provided that the above7 * copyright notice and this permission notice appear in all copies.8 *9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.16 */17 18#ifndef BMI_H19#define BMI_H20 21/*22 * Bootloader Messaging Interface (BMI)23 *24 * BMI is a very simple messaging interface used during initialization25 * to read memory, write memory, execute code, and to define an26 * application entry PC.27 *28 * It is used to download an application to ATH6KL, to provide29 * patches to code that is already resident on ATH6KL, and generally30 * to examine and modify state.  The Host has an opportunity to use31 * BMI only once during bootup.  Once the Host issues a BMI_DONE32 * command, this opportunity ends.33 *34 * The Host writes BMI requests to mailbox0, and reads BMI responses35 * from mailbox0.   BMI requests all begin with a command36 * (see below for specific commands), and are followed by37 * command-specific data.38 *39 * Flow control:40 * The Host can only issue a command once the Target gives it a41 * "BMI Command Credit", using ATH6KL Counter #4.  As soon as the42 * Target has completed a command, it issues another BMI Command43 * Credit (so the Host can issue the next command).44 *45 * BMI handles all required Target-side cache flushing.46 */47 48/* BMI Commands */49 50#define BMI_NO_COMMAND                      051 52#define BMI_DONE                            153/*54 * Semantics: Host is done using BMI55 * Request format:56 *    u32 command (BMI_DONE)57 * Response format: none58 */59 60#define BMI_READ_MEMORY                     261/*62 * Semantics: Host reads ATH6KL memory63 * Request format:64 *    u32 command (BMI_READ_MEMORY)65 *    u32 address66 *    u32 length, at most BMI_DATASZ_MAX67 * Response format:68 *    u8 data[length]69 */70 71#define BMI_WRITE_MEMORY                    372/*73 * Semantics: Host writes ATH6KL memory74 * Request format:75 *    u32 command (BMI_WRITE_MEMORY)76 *    u32 address77 *    u32 length, at most BMI_DATASZ_MAX78 *    u8 data[length]79 * Response format: none80 */81 82#define BMI_EXECUTE                         483/*84 * Semantics: Causes ATH6KL to execute code85 * Request format:86 *    u32 command (BMI_EXECUTE)87 *    u32 address88 *    u32 parameter89 * Response format:90 *    u32 return value91 */92 93#define BMI_SET_APP_START                   594/*95 * Semantics: Set Target application starting address96 * Request format:97 *    u32 command (BMI_SET_APP_START)98 *    u32 address99 * Response format: none100 */101 102#define BMI_READ_SOC_REGISTER               6103/*104 * Semantics: Read a 32-bit Target SOC register.105 * Request format:106 *    u32 command (BMI_READ_REGISTER)107 *    u32 address108 * Response format:109 *    u32 value110 */111 112#define BMI_WRITE_SOC_REGISTER              7113/*114 * Semantics: Write a 32-bit Target SOC register.115 * Request format:116 *    u32 command (BMI_WRITE_REGISTER)117 *    u32 address118 *    u32 value119 *120 * Response format: none121 */122 123#define BMI_GET_TARGET_ID                  8124#define BMI_GET_TARGET_INFO                8125/*126 * Semantics: Fetch the 4-byte Target information127 * Request format:128 *    u32 command (BMI_GET_TARGET_ID/INFO)129 * Response format1 (old firmware):130 *    u32 TargetVersionID131 * Response format2 (newer firmware):132 *    u32 TARGET_VERSION_SENTINAL133 *    struct bmi_target_info;134 */135 136#define TARGET_VERSION_SENTINAL 0xffffffff137#define TARGET_TYPE_AR6003      3138#define TARGET_TYPE_AR6004      5139#define BMI_ROMPATCH_INSTALL               9140/*141 * Semantics: Install a ROM Patch.142 * Request format:143 *    u32 command (BMI_ROMPATCH_INSTALL)144 *    u32 Target ROM Address145 *    u32 Target RAM Address or Value (depending on Target Type)146 *    u32 Size, in bytes147 *    u32 Activate? 1-->activate;148 *                            0-->install but do not activate149 * Response format:150 *    u32 PatchID151 */152 153#define BMI_ROMPATCH_UNINSTALL             10154/*155 * Semantics: Uninstall a previously-installed ROM Patch,156 * automatically deactivating, if necessary.157 * Request format:158 *    u32 command (BMI_ROMPATCH_UNINSTALL)159 *    u32 PatchID160 *161 * Response format: none162 */163 164#define BMI_ROMPATCH_ACTIVATE              11165/*166 * Semantics: Activate a list of previously-installed ROM Patches.167 * Request format:168 *    u32 command (BMI_ROMPATCH_ACTIVATE)169 *    u32 rompatch_count170 *    u32 PatchID[rompatch_count]171 *172 * Response format: none173 */174 175#define BMI_ROMPATCH_DEACTIVATE            12176/*177 * Semantics: Deactivate a list of active ROM Patches.178 * Request format:179 *    u32 command (BMI_ROMPATCH_DEACTIVATE)180 *    u32 rompatch_count181 *    u32 PatchID[rompatch_count]182 *183 * Response format: none184 */185 186 187#define BMI_LZ_STREAM_START                13188/*189 * Semantics: Begin an LZ-compressed stream of input190 * which is to be uncompressed by the Target to an191 * output buffer at address.  The output buffer must192 * be sufficiently large to hold the uncompressed193 * output from the compressed input stream.  This BMI194 * command should be followed by a series of 1 or more195 * BMI_LZ_DATA commands.196 *    u32 command (BMI_LZ_STREAM_START)197 *    u32 address198 * Note: Not supported on all versions of ROM firmware.199 */200 201#define BMI_LZ_DATA                        14202/*203 * Semantics: Host writes ATH6KL memory with LZ-compressed204 * data which is uncompressed by the Target.  This command205 * must be preceded by a BMI_LZ_STREAM_START command. A series206 * of BMI_LZ_DATA commands are considered part of a single207 * input stream until another BMI_LZ_STREAM_START is issued.208 * Request format:209 *    u32 command (BMI_LZ_DATA)210 *    u32 length (of compressed data),211 *                  at most BMI_DATASZ_MAX212 *    u8 CompressedData[length]213 * Response format: none214 * Note: Not supported on all versions of ROM firmware.215 */216 217#define BMI_COMMUNICATION_TIMEOUT       1000 /* in msec */218 219struct ath6kl;220struct ath6kl_bmi_target_info {221	__le32 byte_count;   /* size of this structure */222	__le32 version;      /* target version id */223	__le32 type;         /* target type */224} __packed;225 226#define ath6kl_bmi_write_hi32(ar, item, val)				\227	({								\228		u32 addr;						\229		__le32 v;						\230									\231		addr = ath6kl_get_hi_item_addr(ar, HI_ITEM(item));	\232		v = cpu_to_le32(val);					\233		ath6kl_bmi_write(ar, addr, (u8 *) &v, sizeof(v));	\234	})235 236#define ath6kl_bmi_read_hi32(ar, item, val)				\237	({								\238		u32 addr, *check_type = val;				\239		__le32 tmp;						\240		int ret;						\241									\242		(void) (check_type == val);				\243		addr = ath6kl_get_hi_item_addr(ar, HI_ITEM(item));	\244		ret = ath6kl_bmi_read(ar, addr, (u8 *) &tmp, 4);	\245		if (!ret)						\246			*val = le32_to_cpu(tmp);			\247		ret;							\248	})249 250int ath6kl_bmi_init(struct ath6kl *ar);251void ath6kl_bmi_cleanup(struct ath6kl *ar);252void ath6kl_bmi_reset(struct ath6kl *ar);253 254int ath6kl_bmi_done(struct ath6kl *ar);255int ath6kl_bmi_get_target_info(struct ath6kl *ar,256			       struct ath6kl_bmi_target_info *targ_info);257int ath6kl_bmi_read(struct ath6kl *ar, u32 addr, u8 *buf, u32 len);258int ath6kl_bmi_write(struct ath6kl *ar, u32 addr, u8 *buf, u32 len);259int ath6kl_bmi_execute(struct ath6kl *ar,260		       u32 addr, u32 *param);261int ath6kl_bmi_set_app_start(struct ath6kl *ar,262			     u32 addr);263int ath6kl_bmi_reg_read(struct ath6kl *ar, u32 addr, u32 *param);264int ath6kl_bmi_reg_write(struct ath6kl *ar, u32 addr, u32 param);265int ath6kl_bmi_lz_data(struct ath6kl *ar,266		       u8 *buf, u32 len);267int ath6kl_bmi_lz_stream_start(struct ath6kl *ar,268			       u32 addr);269int ath6kl_bmi_fast_download(struct ath6kl *ar,270			     u32 addr, u8 *buf, u32 len);271#endif272