blkmem.c
来自「这是一个SIGMA方案的PMP播放器的UCLINUX程序,可播放DVD,VCD,」· C语言 代码 · 共 2,493 行 · 第 1/5 页
C
2,493 行
/* blkmem.c: Block access to memory spaces * * Copyright (C) 2001 SnapGear Inc. <davidm@snapgear.com> * Copyright (C) 2000 Lineo, Inc. (www.lineo.com) * Copyright (C) 1997, 1998 D. Jeff Dionne <jeff@lineo.ca>, * Kenneth Albanowski <kjahds@kjahds.com>, * * Based z2ram - Amiga pseudo-driver to access 16bit-RAM in ZorroII space * Copyright (C) 1994 by Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation. This software is provided "as is" without express or * implied warranty. * * NOV/2000 -- hacked for Linux kernel 2.2 and NETtel/x86 (gerg@snapgear.com) * VZ Support/Fixes Evan Stawnyczy <e@lineo.ca> */#include <linux/module.h>#include <linux/config.h>#include <linux/major.h>#include <linux/slab.h>#include <linux/reboot.h>#include <linux/ledman.h>#include <linux/init.h>#include <linux/tqueue.h>#include <asm/semaphore.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/hardware.h>#undef VERBOSE#undef DEBUG#define TRUE (1)#define FALSE (0)#define BLKMEM_MAJOR 31#define MAJOR_NR BLKMEM_MAJOR#ifdef CONFIG_ARCH_CNXT#define CONFIG_LINEOHW 1#define DEVEL 1 /* everything in SDRAM for now */#endif// #define DEVICE_NAME "blkmem"#define DEVICE_REQUEST do_blkmem_request#define DEVICE_NR(device) (MINOR(device))#define DEVICE_ON(device)#define DEVICE_OFF(device)#define DEVICE_NO_RANDOM#define TIMEOUT_VALUE (6 * HZ)#include <linux/blkmem.h>#include <linux/blk.h>#ifdef CONFIG_LEDMAN#include <linux/ledman.h>#endif#include <asm/bitops.h>#include <asm/delay.h>#include <asm/semaphore.h>/* * Timeout loop counter for FLASH operations. */#define FTIMEOUT 16000000/* * Please, configure the ROMFS for your system here *//* Samsung 4510 Mac Wang <mac@os.nctu.edu.tw> */#ifdef CONFIG_ARCH_SAMSUNGextern char romfs_data[];extern char romfs_data_end[];#endif/* v850e; this config stuff is ugly, ugly, ugly! */#ifdef CONFIG_V850E#include <asm/blkmem.h>#endif/* (es) *//* note: this is configured somewhere in arch/m68knommu/kernel/setup.c *//* does it need to be here? */#if defined( CONFIG_M68328 ) || defined ( CONFIG_M68EZ328 ) || defined( CONFIG_M68VZ328)#include <asm/shglports.h>#define CAT_ROMARRAY#endif/* (/es) */#if defined( CONFIG_PILOT ) && defined( CONFIG_M68EZ328 )extern char _flashstart[];#define FIXED_ROMARRAY _flashstart#endif/* (es) */#if defined(CONFIG_UCSIMM) || defined(CONFIG_UCDIMM) || defined (CONFIG_DRAGEN2)#define CAT_ROMARRAY#endif/* (/es) */#ifdef CONFIG_M68EZ328ADS#ifdef CONFIG_M68EZ328ADS_RAMextern char _flashstart[];#define FIXED_ROMARRAY _flashstart#else#define CAT_ROMARRAY#endif #endif #ifdef CONFIG_ARCH_TRIO#define FIXED_ROMARRAY (char*)(3512*1024)#endif#ifdef CONFIG_ALMA_ANS#ifdef CONFIG_ALMA_ANS_RAMextern char _flashstart[];#define FIXED_ROMARRAY _flashstart#else#define CAT_ROMARRAY#endif #endif #ifdef CONFIG_COLDFIRE#ifdef CONFIG_TELOS#define CAT_ROMARRAY#elseunsigned char *romarray;extern char _ebss;#ifndef CONFIG_ROMFS_FROM_ROM #define FIXUP_ARENAS arena[0].address = (unsigned long) &_ebss;#else #define FIXUP_ARENAS { \ register char *sp = (char *) arena[4].address; \ register char *ep = sp + arena[4].length; \ if (strncmp((char *) &_ebss, "-rom1fs-", 8) == 0) { \ sp = (char *) &_ebss; \ } else { \ while (sp < ep && strncmp(sp, "-rom1fs-", 8)) \ sp++; \ if (sp >= ep) \ sp = &_ebss; \ } \ arena[0].address = (unsigned long) sp; \ }#endif /* CONFIG_ROMFS_FROM_ROM *//* * Stub out the LED functions for now. */#define SET_ALARM_LED(x)#define GET_COMM_STATUS_LED(x)#define SET_COMM_STATUS_LED(x)#define SET_COMM_ERROR_LED(x)#endif /* CONFIG_TELOS */#endif /* CONFIG_COLDFIRE */#if defined(CONFIG_ARCH_DSC21) || defined(CONFIG_ARCH_ATMEL) || defined(CONFIG_ARCH_INTEGRATOR)|| defined(CONFIG_ARCH_JASPER)#define FIXED_ROMARRAY (char *)(FLASH_MEM_BASE)#endif#if defined( CONFIG_M68360 )#define CAT_ROMARRAY#endif/* * Lineo hardware has similar FLASH layouts on all devices. */#if defined(CONFIG_NETtel) || \ defined(CONFIG_eLIA) || \ defined(CONFIG_DISKtel) || \ defined(CONFIG_SECUREEDGEMP3)#define CONFIG_LINEOHW 1#endif/******* END OF BOARD-SPECIFIC CONFIGURATION ************//* Simple romfs, at internal, cat on the end of kernel, or seperate fixed adderess romfs. */#ifdef INTERNAL_ROMARRAY#include "romdisk.c"#endif#ifdef CAT_ROMARRAYunsigned char *romarray;extern char __data_rom_start[];extern char _edata[];extern char __data_start[];#ifndef FIXUP_ARENAS#define FIXUP_ARENAS \ arena[0].address = (unsigned long)__data_rom_start + (unsigned long)_edata - (unsigned long)__data_start;#endif#endif#if defined(CONFIG_WATCHDOG)extern void watchdog_disable(void);extern void watchdog_enable(void);#endif#ifdef FIXED_ROMARRAYunsigned char *romarray = (char *)(FIXED_ROMARRAY);#endif/* If defined, ROOT_ARENA causes the root device to be the specified arena, useful with romfs *//* Now defining ROOT_DEV in arch/setup.c *//*#define ROOT_ARENA 0*/struct arena_t;typedef void (*xfer_func_t)(struct arena_t *, unsigned long address, unsigned long length, char * buffer);typedef void (*erase_func_t)(struct arena_t *, unsigned long address);typedef void (*program_func_t)(struct arena_t *, struct blkmem_program_t * prog);#ifndef CONFIG_COLDFIREvoid program_main(struct arena_t *, struct blkmem_program_t *);void read_spare(struct arena_t *, unsigned long, unsigned long, char *);void write_spare(struct arena_t *, unsigned long, unsigned long, char *);void erase_spare(struct arena_t *, unsigned long);#endif#if defined(CONFIG_ARNEWSH) || defined(CONFIG_MOTOROLA)void write_pair(struct arena_t *, unsigned long, unsigned long, char *);void erase_pair(struct arena_t *, unsigned long);#endif#if defined(CONFIG_LINEOHW)#if defined(CONFIG_INTELFLASH)/* * Lineo hardware with INTEL FLASH. */static void flash_intel_writeall(struct arena_t *, struct blkmem_program_t *);static void flash_intel_write(struct arena_t *, unsigned long, unsigned long, char *);static void flash_intel_erase(struct arena_t *, unsigned long);#define flash_erase flash_intel_erase#define flash_write flash_intel_write#define flash_writeall flash_intel_writeall#else#ifdef CONFIG_FLASH8BIT/* * Lineo hardware with 8bit AMD FLASH. */static void flash_amd8_writeall(struct arena_t *, struct blkmem_program_t *);static void flash_amd8_write(struct arena_t *, unsigned long, unsigned long, char *);static void flash_amd8_erase(struct arena_t *, unsigned long);#define flash_erase flash_amd8_erase#define flash_write flash_amd8_write#define flash_writeall flash_amd8_writeall#else/* * Lineo hardware with 16bit AMD FLASH (this is the default). */static void flash_amd16_writeall(struct arena_t *, struct blkmem_program_t *);static void flash_amd16_write(struct arena_t *, unsigned long, unsigned long, char *);static void flash_amd16_erase(struct arena_t *, unsigned long);#define flash_erase flash_amd16_erase#define flash_write flash_amd16_write#define flash_writeall flash_amd16_writeall#endif /* !COFNIG_FLASH8BIT */#endif /* !CONFIG_INTELFLASH */void flash_eraseconfig(void);#endif /* CONFIG_LINEOHW */#if defined(CONFIG_CLEOPATRA)/* * Feith hardware with 16bit AMD FLASH (this is the default). */static void flash_amd16_writeall(struct arena_t *, struct blkmem_program_t *);static void flash_amd16_write(struct arena_t *, unsigned long, unsigned long, char *);static void flash_amd16_erase(struct arena_t *, unsigned long);#define flash_erase flash_amd16_erase#define flash_write flash_amd16_write#define flash_writeall flash_amd16_writeallvoid flash_eraseconfig(void);#endif/* This array of structures defines the actual set of memory arenas, including access functions (if the memory isn't part of the main address space) */struct arena_t { int rw; unsigned long address; /* Address of memory arena */ unsigned long length; /* Length of memory arena. If -1, try to get size from romfs header */ program_func_t program_func; /* Function to program in one go */ xfer_func_t read_func; /* Function to transfer data to main memory, or zero if none needed */ xfer_func_t write_func; /* Function to transfer data from main memory, zero if none needed */ erase_func_t erase_func; /* Function to erase a block of memory to zeros, or 0 if N/A */ unsigned long blksize; /* Size of block that can be erased at one time, or 0 if N/A */ unsigned long unitsize; unsigned char erasevalue; /* Contents of sectors when erased */ /*unsigned int auto_erase_bits; unsigned int did_erase_bits;*/ } arena[] = {#ifdef CONFIG_ARCH_SAMSUNG {0, romfs_data, -1},#endif#ifdef INTERNAL_ROMARRAY {0, (unsigned long)romarray, sizeof(romarray)},#endif#ifdef CAT_ROMARRAY {0, 0, -1},#endif#ifdef FIXED_ROMARRAY {0, (unsigned long) FIXED_ROMARRAY, -1},#endif#ifdef CONFIG_ARCH_CNXT /* AM29LV004T flash * rom0 -- root file-system */#ifdef DEVEL /* * rom0 currently in RAM */ {1, 0x800000, 0x100000,0,0, flash_write, flash_erase, 0x10000, 0x10000, 0xff},#else {1, 0x400000, 0x10000,0,0, flash_write, flash_erase, 0x10000, 0x10000, 0xff}, {1, 0x410000, 0xf0000,0,0, flash_write, flash_erase, 0x10000, 0x10000, 0xff}, {1, 0x500000,0x100000,0,0, flash_write, flash_erase, 0x10000,0x10000,0xff}, {1, 0x600000,0x200000,0,0, flash_write, flash_erase,0x10000,0x10000,0xff}, {1, 0x801000,0xff000,0,0, flash_write,flash_erase,0xff000,0xff000,0xff},#endif#endif /* CONFIG_ARCH_CNXT*/#ifdef CONFIG_COLDFIRE /* * The ROM file-system is RAM resident on the ColdFire eval boards. * This arena is defined for access to it. */ {0, 0, -1},#ifdef CONFIG_M5206 /* * The spare FLASH segment on the 5206 board. */ {1,0xffe20000,0x20000,0,0,write_pair,erase_pair,0x8000,0x20000,0xff},#endif#ifdef CONFIG_MOTOROLA /* pair of AM29LV004T flash for 1Mbyte total * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH SA0 128K boot * rom2 -- FLASH SA1-6 768k kernel & romfs * rom3 -- FLASH SA7 64k spare * rom4 -- FLASH SA8 16k spare * rom5 -- FLASH SA9 16k spare * rom6 -- FLASH SA10 32k spare */ {1,0xffe00000,0x20000,0,0,write_pair,erase_pair,0x20000,0x20000,0xff}, {1,0xffe20000,0xc0000,0,0,write_pair,erase_pair,0x20000,0xc0000,0xff}, {1,0xffee0000,0x10000,0,0,write_pair,erase_pair,0x10000,0x10000,0xff}, {1,0xffef0000,0x4000,0,0,write_pair,erase_pair,0x4000,0x4000,0xff}, {1,0xffef4000,0x4000,0,0,write_pair,erase_pair,0x4000,0x4000,0xff}, {1,0xffef8000,0x8000,0,0,write_pair,erase_pair,0x8000,0x8000,0xff},#endif /* CONFIG_MOTOROLA */#if defined(CONFIG_LINEOHW)#if defined(CONFIG_FLASH8MB)/* * Lineo hardware with 8MB FLASH. * The following devices are supported: * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH boot block (128k) * rom2 -- FLASH boot arguments (128k) * rom3 -- FLASH MAC addresses (128k) * rom4 -- FLASH kernel+file-system binary (7mb) * rom5 -- FLASH config file-system (512k) * rom6 -- FLASH the whole damn thing (8Mb)! * rom7 -- FLASH spare block (128k) */ {1,0xf0000000,0x020000,flash_writeall, 0, 0, 0, 0x20000,0x020000,0xff}, {1,0xf0020000,0x020000,0,0,flash_write,flash_erase,0x20000,0x020000,0xff}, {1,0xf0040000,0x020000,0,0,flash_write,flash_erase,0x20000,0x020000,0xff}, {1,0xf0100000,0x700000,flash_writeall, 0, 0, 0, 0x20000,0x700000,0xff}, {1,0xf0080000,0x080000,0,0,flash_write,flash_erase,0x20000,0x080000,0xff}, {1,0xf0000000,0x800000,flash_writeall, 0, 0, 0, 0x20000,0x800000,0xff}, {1,0xf0060000,0x020000,flash_writeall,0,flash_write,flash_erase,0x20000,0x02000,0xff},#elif defined(CONFIG_FLASH2MB) || defined(CONFIG_FLASH4MB)/* * Lineo hardware with 2MB/4MB FLASH. * The following devices are supported: * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH boot block (16k) * rom2 -- FLASH boot arguments (8k) * rom3 -- FLASH MAC addresses (8k) * rom4 -- FLASH kernel+file-system binary (1920k) * rom5 -- FLASH config file-system (64k) * rom6 -- FLASH the whole damn thing (2Mb)! * rom7 -- FLASH spare block (32k) * rom8 -- FLASH2 kernel+file-system binary (1920k) (4MB only) * rom9 -- FLASH2 the whole damn thing (2Mb)! */ {1,0xf0000000,0x004000,flash_writeall, 0, 0, 0, 0x04000,0x004000,0xff}, {1,0xf0004000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0006000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0020000,0x1e0000,flash_writeall, 0, 0, 0, 0x10000,0x1e0000,0xff}, {1,0xf0010000,0x010000,0,0,flash_write,flash_erase,0x10000,0x010000,0xff}, {1,0xf0000000,0x200000,flash_writeall, 0, 0, 0, 0x10000,0x200000,0xff}, {1,0xf0008000,0x08000,flash_writeall,0,flash_write,flash_erase,0x08000,0x08000,0xff},#if defined(CONFIG_FLASH4MB) {1,0xf0220000,0x1e0000,flash_writeall, 0, 0, 0, 0x10000,0x1e0000,0xff}, {1,0xf0200000,0x200000,flash_writeall, 0, 0, 0, 0x10000,0x200000,0xff},#endif#else/* * Lineo hardware FLASH erase/program entry points (1MB FLASH). * The following devices are supported: * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH boot block (16k) * rom2 -- FLASH boot arguments (8k) * rom3 -- FLASH MAC addresses (8k) * rom4 -- FLASH kernel+file-system binary (896k) * rom5 -- FLASH config file-system (64k) * rom6 -- FLASH the whole damn thing (1Mb)! * rom7 -- FLASH spare block (32k) */ {1,0xf0000000,0x04000,flash_writeall, 0, 0, 0, 0x04000,0x04000,0xff}, {1,0xf0004000,0x02000,0,0,flash_write,flash_erase,0x02000,0x02000,0xff}, {1,0xf0006000,0x02000,0,0,flash_write,flash_erase,0x02000,0x02000,0xff}, {1,0xf0010000,0xe0000,flash_writeall, 0, 0, 0, 0x10000,0xe0000,0xff}, {1,0xf00f0000,0x10000,0,0,flash_write,flash_erase,0x10000,0x10000,0xff}, {1,0xf0000000,0x100000,flash_writeall, 0, 0, 0, 0x10000,0x100000,0xff}, {1,0xf0008000,0x08000,flash_writeall,0,flash_write,flash_erase,0x08000,0x08000,0xff},#if defined(CONFIG_EXTRA_FLASH1MB)/* * rom8 -- FLASH extra. where the NETtel3540 stores the dsl image */ {1,0xf0100000,0x100000,flash_writeall, 0, 0, 0, 0x10000,0x100000,0xff},#endif /* CONFIG_EXTRA_FLASH1MB */#endif /* CONFIG_FLASH2MB */#endif /* CONFIG_LINEOHW */#if defined(CONFIG_CLEOPATRA)/* * CLEOPATRA with 2MB/4MB FLASH erase/program entry points. * The following devices are supported: * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH boot block (16k) * rom2 -- FLASH boot arguments (8k) * rom3 -- FLASH MAC addresses (8k) * rom4 -- FLASH kernel+file-system binary (1792k) * rom5 -- FLASH config file-system (64k) * rom6 -- FLASH the whole damn thing (2Mb)! * rom7 -- FLASH spare block (32k) * rom8 -- FLASH application config (128k) * rom9 -- FLASH user block (1536k) (4MB only) * rom10-- FLASH user block (512k) (4MB only) * rom11-- FLASH user block (2048k) (6MB only) */ {1,0xf0000000,0x004000,flash_writeall, 0, 0, 0, 0x04000,0x004000,0xff}, {1,0xf0004000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0006000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0020000,0x1c0000,flash_writeall, 0, 0, 0, 0x10000,0x1c0000,0xff}, {1,0xf0010000,0x010000,0,0,flash_write,flash_erase,0x10000,0x010000,0xff}, {1,0xf0000000,0x200000,flash_writeall, 0, 0, 0, 0x10000,0x200000,0xff}, {1,0xf0008000,0x08000,flash_writeall,0,flash_write,flash_erase,0x08000,0x08000,0xff}, {1,0xf01e0000,0x020000,0,0,flash_write,flash_erase,0x10000,0x020000,0xff},#if defined(CONFIG_FLASH4MB) {1,0xf0200000,0x180000,0,0,flash_write,flash_erase,0x10000,0x180000,0xff}, {1,0xf0380000,0x080000,0,0,flash_write,flash_erase,0x10000,0x080000,0xff},#endif#if defined(CONFIG_FLASH6MB) {1,0xf0200000,0x180000,0,0,flash_write,flash_erase,0x10000,0x180000,0xff}, {1,0xf0380000,0x080000,0,0,flash_write,flash_erase,0x10000,0x080000,0xff}, {1,0xf0400000,0x200000,0,0,flash_write,flash_erase,0x10000,0x200000,0xff},#endif#endif#endif /* CONFIG_COLDFIRE */#ifdef CONFIG_SHGLCORE#ifdef CONFIG_SHGLCORE_2MEG {0, 0x0A0000, 0x200000-0x0A0000}, /* ROM FS */ {1, SHGLCORE_FLASH_BANK_0_ADDR, 0x80000, 0, 0, write_spare, erase_spare, 0x10000, 0x80000, 0xff}, {1, 0x000000, 0x200000, program_main, 0,0,0, 0x20000, 0x100000}, /* All main FLASH */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?