www.pudn.com > efs.rar > fs_pm.h


/********************************************************************** 
 * fs_pm.h 
 * 
 * Copyright (C) 2003, 2004, 2005, 2006 Qualcomm, Inc. 
 * Page Manager Header for EFS. 
 */ 
 
 
/*=========================================================================== 
 
                        EDIT HISTORY FOR MODULE 
 
  This section contains comments describing changes made to the module. 
  Notice that changes are listed in reverse chronological order. 
 
  $Header: //depot/asic/MSMSHARED/services/efs/MSM_EFS.01.02/fs_pm.h#5 $ $DateTime: 2006/11/13 09:22:31 $ $Author: davidb $ 
 
when          who     what, where, why 
--------      ---     ------------------------------------------------------ 
11/09/06      dlb     Add pm query of freemap. 
10/30/05      sh      Lint cleanup. 
04/26/05      dlb     Add 2K page support. 
10/15/04      dlb     Update copyright line. 
10/07/04      dlb     Whitespace cleanup. 
04/04/03      bgc     Added incremental garbage collection data and types. 
02/13/03      dlb     Created based on fs_pm_gc.h. 
 
===========================================================================*/ 
 
#ifndef __FS_PM_H__ 
#define __FS_PM_H__ 
 
#include "customer.h" 
#include "fs_device.h" 
 
 
#include "fs_pm_ptable.h" 
#include "fs_logr.h" 
#include "qw.h" 
 
struct fs_pm_data; 
struct fs_pm_flash_data; 
typedef struct fs_pm_data *fs_pm_t; 
typedef struct fs_pm_flash_data *fs_pm_flash_t; 
 
/* Initialze the Garbage collector.  Calls initialize on all of the page 
 * table code. */ 
void 
fs_pm_init ( 
    fs_pm_flash_t       gc, 
    fs_device_t         dev); 
 
/* Page manager operations. */ 
struct fs_pm_ops { 
  /* Write a single page of data. */ 
  void (*page_write) (fs_pm_t gc, cluster_id cluster, void *buffer); 
 
  /* Read a single page of data.  If the page has never been written, fill 
   * the buffer with all 0xFF. */ 
  void (*page_read) (fs_pm_t gc, cluster_id cluster, void *buffer); 
 
  /* Store a uint32 for an upper layer.  The number of these allowed is 
   * defined by FS_UPPER_DATA_COUNT.  These always have as an initial value 
   * (on powerup) of INVALID_PAGE_ID.  This data will be managed in the 
   * context of transactions. */ 
  void (*store_info) (fs_pm_t, unsigned offset, uint32 data); 
 
  /* Retrieve the value previously stored. */ 
  uint32 (*get_info) (fs_pm_t, unsigned offset); 
 
  /* Start and end transactions.  This should _NOT_ be nested. */ 
  void (*start_transaction) (fs_pm_t gc); 
  void (*end_transaction) (fs_pm_t gc); 
 
  /* Compute the space limit for this particular device. */ 
  uint32 (*space_limit) (fs_pm_t gc); 
 
  /* Register the freespace query function.  The garbage collector will be 
   * much more efficient if it can query for a given cluster as to whether 
   * or not it is still in use.  If the user of the page manager registers 
   * this function, it will be called periodically by the garbage 
   * collector.  This function must not make any calls into the page 
   * manager (i.e. it must not read or write any data).  The function 
   * should return true if the cluster is still used. */ 
  void (*register_free_check_cb) (fs_pm_t gc, 
      int (*is_used_cb) (void *, cluster_id cluster), void *data); 
}; 
 
/* Flush enough that now would be a good time to shutdown. */ 
void fs_pm_shutdown_flush (fs_pm_t gc); 
 
#ifdef FS_UNIT_TEST 
#error code not present 
#endif 
 
 
#define NUM_REGIONS     4 
 
#define FS_PM_SUPER_CHAIN_SIZE          64 
 
enum gc_state { 
  FS_PM_HEAD, FS_PM_MOVING, FS_PM_ERASE 
}; 
 
 
enum gc_erase_state { 
  FS_PM_ERASE_IDLE,     /* flash device is not doing an erase */ 
  FS_PM_ERASE_BUSY,     /* flash device was left erasing a block */ 
  FS_PM_ERASE_SUSPEND   /* flash device has a pending erase to finish */ 
}; 
 
struct fs_pm_data { 
  struct fs_pm_ops      ops; 
}; 
 
struct fs_pm_flash_data { 
  struct fs_pm_data     parent; 
 
  fs_ptable_t           ptable; 
  fs_device_t           dev; 
  struct fs_log_data    log; 
 
  page_id               alloc_next; 
  page_id               gc_next; 
  page_id               free_count; 
 
  enum gc_state         state; 
 
  page_id               next_super_page; 
 
  page_id               super_chain[FS_PM_SUPER_CHAIN_SIZE]; 
  int                   super_head, super_tail; 
 
  /* Callback to query for usage (and associated data). */ 
  int (*is_used_cb) (void *data, cluster_id cluster); 
  void *is_used_data; 
 
  /* Buffer to hold the space to reallocate pages. */ 
  uint8                 realloc_buffer[EFS_PAGE_SIZE]; 
 
  /* Indicates we are inside of a transaction, and shouldn't be performing 
   * GC. */ 
  int                   inside_xact; 
 
  /* Boundaries of each of the regions. */ 
  page_id               min_page; 
  page_id               max_page; 
 
  /* Log region handling.  (NAND) */ 
  struct fs_logr_data   logr; 
 
 
  /* Incremental garbage collector state variables * 
   *                                               */ 
  /* free count stored at a transaction start */ 
  page_id trans_start_free_count; 
  /* The current state of the flash regarding erases */ 
  enum gc_erase_state erase_state; 
  /* current erase block only valid during an erase */ 
  block_id gc_current_erase_block; 
  /* unfinished work holds incremental work left to be done */ 
  int unfinished_work; 
  /* erase_factor is a variable used to tune the amount 
   * of work a page erase is compared to a page move. 
   * It is fixed point *10, so erase_factor=125 means 
   * 12.5 page moves = 1 page erase. */ 
  int erase_factor; 
  /* erase_time is the best guess time of a block erase. 
   * erase_countdown is used to measure erases as they 
   * progress. */ 
  int erase_time;  /* in millisec */ 
  int erase_countdown;  /* in millisecs */ 
  qword erase_start; /* in time of day millisecs */ 
}; 
 
 
#endif /* not __FS_PM_H__ */