Path: blob/main/sys/contrib/dev/athk/ath10k/bmi.h
106597 views
/* SPDX-License-Identifier: ISC */1/*2* Copyright (c) 2005-2011 Atheros Communications Inc.3* Copyright (c) 2011-2015,2017 Qualcomm Atheros, Inc.4*/56#ifndef _BMI_H_7#define _BMI_H_89#include "core.h"1011/*12* Bootloader Messaging Interface (BMI)13*14* BMI is a very simple messaging interface used during initialization15* to read memory, write memory, execute code, and to define an16* application entry PC.17*18* It is used to download an application to QCA988x, to provide19* patches to code that is already resident on QCA988x, and generally20* to examine and modify state. The Host has an opportunity to use21* BMI only once during bootup. Once the Host issues a BMI_DONE22* command, this opportunity ends.23*24* The Host writes BMI requests to mailbox0, and reads BMI responses25* from mailbox0. BMI requests all begin with a command26* (see below for specific commands), and are followed by27* command-specific data.28*29* Flow control:30* The Host can only issue a command once the Target gives it a31* "BMI Command Credit", using AR8K Counter #4. As soon as the32* Target has completed a command, it issues another BMI Command33* Credit (so the Host can issue the next command).34*35* BMI handles all required Target-side cache flushing.36*/3738/* Maximum data size used for BMI transfers */39#define BMI_MAX_DATA_SIZE 2564041/* len = cmd + addr + length */42#define BMI_MAX_CMDBUF_SIZE (BMI_MAX_DATA_SIZE + \43sizeof(u32) + \44sizeof(u32) + \45sizeof(u32))4647/* Maximum data size used for large BMI transfers */48#define BMI_MAX_LARGE_DATA_SIZE 20484950/* len = cmd + addr + length */51#define BMI_MAX_LARGE_CMDBUF_SIZE (BMI_MAX_LARGE_DATA_SIZE + \52sizeof(u32) + \53sizeof(u32) + \54sizeof(u32))5556/* BMI Commands */5758enum bmi_cmd_id {59BMI_NO_COMMAND = 0,60BMI_DONE = 1,61BMI_READ_MEMORY = 2,62BMI_WRITE_MEMORY = 3,63BMI_EXECUTE = 4,64BMI_SET_APP_START = 5,65BMI_READ_SOC_REGISTER = 6,66BMI_READ_SOC_WORD = 6,67BMI_WRITE_SOC_REGISTER = 7,68BMI_WRITE_SOC_WORD = 7,69BMI_GET_TARGET_ID = 8,70BMI_GET_TARGET_INFO = 8,71BMI_ROMPATCH_INSTALL = 9,72BMI_ROMPATCH_UNINSTALL = 10,73BMI_ROMPATCH_ACTIVATE = 11,74BMI_ROMPATCH_DEACTIVATE = 12,75BMI_LZ_STREAM_START = 13, /* should be followed by LZ_DATA */76BMI_LZ_DATA = 14,77BMI_NVRAM_PROCESS = 15,78};7980#define BMI_NVRAM_SEG_NAME_SZ 168182#define BMI_PARAM_GET_EEPROM_BOARD_ID 0x1083#define BMI_PARAM_GET_FLASH_BOARD_ID 0x800084#define BMI_PARAM_FLASH_SECTION_ALL 0x100008586/* Dual-band Extended Board ID */87#define BMI_PARAM_GET_EXT_BOARD_ID 0x4000088#define ATH10K_BMI_EXT_BOARD_ID_SUPPORT 0x400008990#define ATH10K_BMI_BOARD_ID_FROM_OTP_MASK 0x7c0091#define ATH10K_BMI_BOARD_ID_FROM_OTP_LSB 109293#define ATH10K_BMI_CHIP_ID_FROM_OTP_MASK 0x1800094#define ATH10K_BMI_CHIP_ID_FROM_OTP_LSB 159596#define ATH10K_BMI_BOARD_ID_STATUS_MASK 0xff97#define ATH10K_BMI_EBOARD_ID_STATUS_MASK 0xff9899struct bmi_cmd {100__le32 id; /* enum bmi_cmd_id */101union {102struct {103} done;104struct {105__le32 addr;106__le32 len;107} read_mem;108struct {109__le32 addr;110__le32 len;111u8 payload[];112} write_mem;113struct {114__le32 addr;115__le32 param;116} execute;117struct {118__le32 addr;119} set_app_start;120struct {121__le32 addr;122} read_soc_reg;123struct {124__le32 addr;125__le32 value;126} write_soc_reg;127struct {128} get_target_info;129struct {130__le32 rom_addr;131__le32 ram_addr; /* or value */132__le32 size;133__le32 activate; /* 0=install, but dont activate */134} rompatch_install;135struct {136__le32 patch_id;137} rompatch_uninstall;138struct {139__le32 count;140__le32 patch_ids[]; /* length of @count */141} rompatch_activate;142struct {143__le32 count;144__le32 patch_ids[]; /* length of @count */145} rompatch_deactivate;146struct {147__le32 addr;148} lz_start;149struct {150__le32 len; /* max BMI_MAX_DATA_SIZE */151u8 payload[]; /* length of @len */152} lz_data;153struct {154u8 name[BMI_NVRAM_SEG_NAME_SZ];155} nvram_process;156u8 payload[BMI_MAX_CMDBUF_SIZE];157};158} __packed;159160union bmi_resp {161struct {162DECLARE_FLEX_ARRAY(u8, payload);163} read_mem;164struct {165__le32 result;166} execute;167struct {168__le32 value;169} read_soc_reg;170struct {171__le32 len;172__le32 version;173__le32 type;174} get_target_info;175struct {176__le32 patch_id;177} rompatch_install;178struct {179__le32 patch_id;180} rompatch_uninstall;181struct {182/* 0 = nothing executed183* otherwise = NVRAM segment return value184*/185__le32 result;186} nvram_process;187u8 payload[BMI_MAX_CMDBUF_SIZE];188} __packed;189190struct bmi_target_info {191u32 version;192u32 type;193};194195struct bmi_segmented_file_header {196__le32 magic_num;197__le32 file_flags;198u8 data[];199};200201struct bmi_segmented_metadata {202__le32 addr;203__le32 length;204u8 data[];205};206207#define BMI_SGMTFILE_MAGIC_NUM 0x544d4753 /* "SGMT" */208#define BMI_SGMTFILE_FLAG_COMPRESS 1209210/* Special values for bmi_segmented_metadata.length (all have high bit set) */211212/* end of segmented data */213#define BMI_SGMTFILE_DONE 0xffffffff214215/* Board Data segment */216#define BMI_SGMTFILE_BDDATA 0xfffffffe217218/* set beginning address */219#define BMI_SGMTFILE_BEGINADDR 0xfffffffd220221/* immediate function execution */222#define BMI_SGMTFILE_EXEC 0xfffffffc223224/* in jiffies */225#define BMI_COMMUNICATION_TIMEOUT_HZ (3 * HZ)226227#define BMI_CE_NUM_TO_TARG 0228#define BMI_CE_NUM_TO_HOST 1229230void ath10k_bmi_start(struct ath10k *ar);231int ath10k_bmi_done(struct ath10k *ar);232int ath10k_bmi_get_target_info(struct ath10k *ar,233struct bmi_target_info *target_info);234int ath10k_bmi_get_target_info_sdio(struct ath10k *ar,235struct bmi_target_info *target_info);236#if defined(__linux__)237int ath10k_bmi_read_memory(struct ath10k *ar, u32 address,238void *buffer, u32 length);239int ath10k_bmi_write_memory(struct ath10k *ar, u32 address,240const void *buffer, u32 length);241#elif defined(__FreeBSD__)242int ath10k_bmi_read_memory(struct ath10k *ar, u32 address,243u8 *buffer, u32 length);244int ath10k_bmi_write_memory(struct ath10k *ar, u32 address,245const u8 *buffer, u32 length);246#endif247248#define ath10k_bmi_read32(ar, item, val) \249({ \250int ret; \251u32 addr; \252__le32 tmp; \253\254addr = host_interest_item_address(HI_ITEM(item)); \255ret = ath10k_bmi_read_memory(ar, addr, (u8 *)&tmp, 4); \256if (!ret) \257*val = __le32_to_cpu(tmp); \258ret; \259})260261#define ath10k_bmi_write32(ar, item, val) \262({ \263int ret; \264u32 address; \265__le32 v = __cpu_to_le32(val); \266\267address = host_interest_item_address(HI_ITEM(item)); \268ret = ath10k_bmi_write_memory(ar, address, \269(u8 *)&v, sizeof(v)); \270ret; \271})272273int ath10k_bmi_execute(struct ath10k *ar, u32 address, u32 param, u32 *result);274int ath10k_bmi_lz_stream_start(struct ath10k *ar, u32 address);275#if defined(__linux__)276int ath10k_bmi_lz_data(struct ath10k *ar, const void *buffer, u32 length);277#endif278279int ath10k_bmi_fast_download(struct ath10k *ar, u32 address,280const void *buffer, u32 length);281int ath10k_bmi_read_soc_reg(struct ath10k *ar, u32 address, u32 *reg_val);282int ath10k_bmi_write_soc_reg(struct ath10k *ar, u32 address, u32 reg_val);283int ath10k_bmi_set_start(struct ath10k *ar, u32 address);284285#endif /* _BMI_H_ */286287288