ASR_BASE

Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/marvell/obm/Common/Include/BBM.h b/marvell/obm/Common/Include/BBM.h
new file mode 100644
index 0000000..c85430a
--- /dev/null
+++ b/marvell/obm/Common/Include/BBM.h
@@ -0,0 +1,239 @@
+/******************************************************************************
+**
+** INTEL CONFIDENTIAL
+** Copyright 2003-2004 Intel Corporation All Rights Reserved.
+**
+** The source code contained or described herein and all documents
+** related to the source code (Material) are owned by Intel Corporation
+** or its suppliers or licensors.  Title to the Material remains with
+** Intel Corporation or its suppliers and licensors. The Material contains
+** trade secrets and proprietary and confidential information of Intel
+** or its suppliers and licensors. The Material is protected by worldwide
+** copyright and trade secret laws and treaty provisions. No part of the
+** Material may be used, copied, reproduced, modified, published, uploaded,
+** posted, transmitted, distributed, or disclosed in any way without Intel's
+** prior express written permission.
+**
+** No license under any patent, copyright, trade secret or other intellectual
+** property right is granted to or conferred upon you by disclosure or
+** delivery of the Materials, either expressly, by implication, inducement,
+** estoppel or otherwise. Any license under such intellectual property rights
+** must be express and approved by Intel in writing.
+**
+**	 BBM.h
+******************************************************************************//******************************************************************************
+ *
+ *  (C)Copyright 2005 - 2011 Marvell. All Rights Reserved.
+ *
+ *  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MARVELL.
+ *  The copyright notice above does not evidence any actual or intended
+ *  publication of such source code.
+ *  This Module contains Proprietary Information of Marvell and should be
+ *  treated as Confidential.
+ *  The information in this file is provided for the exclusive use of the
+ *  licensees of Marvell.
+ *  Such users have the right to use, modify, and incorporate this code into
+ *  products for purposes authorized by the license agreement provided they
+ *  include this notice and the associated copyright notice with any such
+ *  product.
+ *  The information in this file is provided "AS IS" without warranty.
+ 
+ ******************************************************************************
+**
+**  FILENAME:	BBM.h
+**
+**  PURPOSE: 	Holds all flash related definitions
+**
+******************************************************************************/
+#ifndef __BBM_H__
+#define __BBM_H__
+
+#include "Typedef.h"
+
+#define MBBT_VERSION_1	0x31303031
+/*
+ * For some nand flash with higher manufacturing process, such as 1xnm,
+ * page program in a block must start from low address to high address.
+ * Do not use this macro if not know what it means.
+ */
+//#define BBT_ORDER_REVERSE
+
+#define READ_DISTURB_LIST_ID 0x52444953	//'RDIS'
+
+#if defined(NEZHA701)
+/* P701 need to reserve larger area for BBM */
+#define LEGACY_BBM_RELOC_PERCENTAGE	(7)
+#elif defined(NEZHA702)
+/* P702 need to reserve larger area for BBM */
+#define LEGACY_BBM_RELOC_PERCENTAGE	(10)
+#else
+/* 5% of whole device is enough for most FLASH */
+#define LEGACY_BBM_RELOC_PERCENTAGE	(5)
+#endif
+
+// Indicates the state of the BBT in volatile memory
+typedef enum
+{
+    BBT_INVALID     = 1,
+    BBT_UNCHANGED   = 2,
+    BBT_CHANGED     = 3,
+    BBT_ERASED      = 4,
+    BBT_NEED_SYNC   = 5,
+    ABBT_BITFLIP0   = (1<<6),
+    ABBT_BITFLIP1	= (1<<7)
+} ReloState_T;
+
+#define ABBT_STATE_MASK (0xF)
+
+// BBT Types
+typedef enum
+{
+	BBT_TYPE_NA			= 0x00000000,		//Runtime BBT not being used
+	BBT_TYPE_LEGACY		= 0x0000524E,		//Legacy version
+	BBT_TYPE_MBBT		= 0x4D424254,		//"MBBT" Marvell Bad Block Table (NOTE: used as ID for factory AND runtime MBBT)
+	BBT_TYPE_MBBT_FACT	= 0x46616374,		//"Fact" Factory Bad Block Table (sub type of the MBBT)
+	BBT_TYPE_MBBT_RUN	= 0x52756E74,		//"Runt" Runtime Bad Block Table (sub type of the MBBT)
+	BBT_TYPE_WNCE		= 0x574E4345,		//"WNCE" WinCE Bad Block Table
+	BBT_TYPE_LINX		= 0x4C695E78,		//"Linx" Linux Bad Block Table
+	BBT_TYPE_ASR        = 0x41424254        //"ASR" Bad Block Table
+} BBT_TYPE;
+
+//Block state introduced for bitflips
+typedef enum
+{
+	BLOCK_RECYCLED = 0xFFF1,
+	BLOCK_TO_RECYCLE = 0xFFF2,
+	BLOCK_RECYCLE_FAILED = 0xFFF3,
+	BLOCK_RELOCATED = 0xFFF4,
+	BLK_FLIP_COUNT = 0xFFFE,
+	BLOCK_BAD = 0xFFFF
+}Block_State;
+
+//Relocation Pairs - same for MBBT, FBBT, and Legacy BBT
+typedef struct {
+	USHORT	From;
+	USHORT	To;
+} ReloPair_T, *P_ReloPair_T;
+
+typedef struct {
+	USHORT State;
+	USHORT Index;
+}BlockState_T, *P_BlockState_T;
+
+// Marvell BBT Structure
+typedef struct {
+	UINT_T	Identifier;
+	UINT_T	Version;
+	UINT_T	Type;
+	UINT_T	Reserved;
+	UINT_T	PartitionID;
+	UINT_T	NumRelo;
+	UINT_T	BBTLocation;
+	UINT_T	Reserved1;		//for now, the upper 32bits of 64bit address are reserved
+	UINT_T	BackupBBTLoc;
+	UINT_T	Reserved2;		//for now, the upper 32bits of 64bit address are reserved
+	ReloPair_T Entry[1]; //need to make it an array
+} MBBT_Table_T, *P_MBBT_Table_T;
+
+// Factory BBT Structure
+typedef struct {
+	UINT_T	Identifier;
+	UINT_T	Version;
+	UINT_T  Type;
+	UINT_T  Reserved0;
+	UINT_T	Reserved1;
+	UINT_T	NumRelo;
+	UINT_T	BBTLocation;
+	UINT_T	Reserved2;		//for now, the upper 32bits of 64bit address are reserved
+	UINT_T	Reserved3;
+	UINT_T	Reserved4;
+	USHORT	BadBlocks[1]; //need to make it an array
+} FBBT_Table_T, *P_FBBT_Table_T;
+
+//1.001
+#define ABBT_VERSION 0x31303031
+//1.002
+#define ABBT_VERSION_1002 0x31303032
+//2.001, use complement to distinguish from previous version more clearly
+#define ABBT_VERSION_2001 (~0x32303031)
+
+typedef enum {
+	BBT_NONE = 0,
+	BBT_OBM = 1,
+	BBT_UBOOT = 2,
+	BBT_KERNEL = 3,
+}BBT_Owner;
+
+struct BBT_INFO_Bits {
+	UINT_T Owner : 2;
+	UINT_T Reserved : 14;
+	UINT_T CRC : 16;
+};
+
+typedef union {
+	UINT_T Value;
+	struct BBT_INFO_Bits Bits;
+}BBT_INFO;
+
+//ASR BBT Structure
+typedef struct {
+	UINT_T	Identifier;
+	UINT_T	Version;
+	union {
+		UINT_T  Type;
+		BBT_INFO  Info;
+	};
+	UINT_T  RefCounter;
+	UINT_T	NumReloc;
+	union {
+		UINT_T	BackupBBTLoc;
+		UINT_T	Reserved0;
+	};
+	UINT_T	NumBlockRecyled;
+	UINT_T	NumBlockToRecyle;
+	union{
+		ReloPair_T	Relo[2]; //need to make it an array
+		BlockState_T BlkInfo[2]; //
+		UINT_T ReloValue[2];
+	};
+} ABBT_Table_T, *P_ABBT_Table_T;
+
+// Legacy BBT Structure
+typedef struct
+{
+	USHORT			Header;
+	USHORT			NumReloc;
+	ReloPair_T		Relo[2];
+} ReloTable_T, *P_ReloTable_T;
+
+/* need to update if ABBT_Table_T changes */
+#define ABBT_HEADER_SIZE  (32)
+/* need to update if ReloTable_T changes */
+#define BBT_HEADER_SIZE   (4)
+
+#if (RVCT || DS5)
+#pragma anon_unions
+#endif
+//Read Disturb entries
+typedef struct
+{
+	union
+	{
+		unsigned int value;
+		struct
+		{
+			USHORT block;
+			USHORT partition;
+		};
+	};
+} ReadDisturbEntry_T, *P_ReadDisturbEntry_T;
+
+// Read Distrub structure to keep track of read disturbed blocks
+typedef struct
+{
+	UINT_T RDID;	//Read Disturb ID
+	UINT_T num_entries;
+	ReadDisturbEntry_T entries[10];
+} ReadDisturbList_T, *P_ReadDisturbList_T;
+
+#endif