/tools/perf/scripts/python/bin/

td/inftlcore.c?id=970343cd49048446da4189986cf960273588d71a'>inftlcore.c
blob: d8cf29c01cc46ce6d9c26e01f85dad1630f456b6 (plain) (tree)
1
2
3
4
5
6
7
8
9
  







                                                                          














                                                                            










                            
                           










                                                                  




                                                                            
                                                               













                                                                             
                                                    




                                                                                  


                               
 
                           
 
                                     


                                                                       
         






















                                                                                  
                                     





                                                                            
                                                                        




                                                                     

                                      



                             
                                                                                











                                                                           

                              







                                












                                                                 

                                                                     
                                
















                                                                  

                                                                      
                                
























                                                                      

















                                                                        
                                 


























                                                                                              
                                              


                               
                      













                                                                             
 



                                                                           
                          

                                                                                

                                                             

                                         


                                                                               

                                                       
                                                                      























                                                                              
 























                                                                               
                  


                                                                     

                                                 
 


                                                                           
                                                 



                                                                              
                                        





                                                                            


                                                                            























                                                                          



                                                           
                                                            



                                                                    
                        

                                                                
                                             
                 







                                                                                
                                                               

























































                                                                              
                                                                      






                                                                                
                                              


















                                                                      

                                                                           
 
                                                          

















                                                                               
                                      
                         

                                       

                                                                              
                                                 











                                                          
                                                                         









                                                                               
                                                                        











                                                                             

                                                                               









                                                                                
                         









                                                                          

                                                                        











                                                                   
 






                                                             

                                                                        








                                                             

                                                                                










                                                                            
                         






                                                                             
                                              


















                                                                           
 









                                                                               

                                                                               
                                                            

























                                                                              
 

































                                                                                                                  
                                                            



                                                                    
                        




















                                                                                       
                                              








                                                                    

                                                                           
































                                                                              
                                                                           

                                                          
                                                                            





                                                                                     
                                                                              































                                                                               
 


                                                                           
















                                                                                       
                                              
                            
                              
                             





                                                                            
                                                                      
                                                                          


































                                                                              
                              
                                                                     



                                                                           



















                                                                              
                              







                                           

                                  













                                                                                                                                              
/*
 * inftlcore.c -- Linux driver for Inverse Flash Translation Layer (INFTL)
 *
 * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
 *
 * Based heavily on the nftlcore.c code which is:
 * (c) 1999 Machine Vision Holdings, Inc.
 * Author: David Woodhouse <dwmw2@infradead.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/kmod.h>
#include <linux/hdreg.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/nftl.h>
#include <linux/mtd/inftl.h>
#include <linux/mtd/nand.h>
#include <asm/uaccess.h>
#include <asm/errno.h>
#include <asm/io.h>

/*
 * Maximum number of loops while examining next block, to have a
 * chance to detect consistency problems (they should never happen
 * because of the checks done in the mounting.
 */
#define MAX_LOOPS 10000

static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
{
	struct INFTLrecord *inftl;
	unsigned long temp;

	if (mtd->type != MTD_NANDFLASH || mtd->size > UINT_MAX)
		return;
	/* OK, this is moderately ugly.  But probably safe.  Alternatives? */
	if (memcmp(mtd->name, "DiskOnChip", 10))
		return;

	if (!mtd->block_isbad) {
		printk(KERN_ERR
"INFTL no longer supports the old DiskOnChip drivers loaded via docprobe.\n"
"Please use the new diskonchip driver under the NAND subsystem.\n");
		return;
	}

	DEBUG(MTD_DEBUG_LEVEL3, "INFTL: add_mtd for %s\n", mtd->name);

	inftl = kzalloc(sizeof(*inftl), GFP_KERNEL);

	if (!inftl) {
		printk(KERN_WARNING "INFTL: Out of memory for data structures\n");
		return;
	}

	inftl->mbd.mtd = mtd;
	inftl->mbd.devnum = -1;

	inftl->mbd.tr = tr;

	if (INFTL_mount(inftl) < 0) {
		printk(KERN_WARNING "INFTL: could not mount device\n");
		kfree(inftl);
		return;
	}

	/* OK, it's a new one. Set up all the data structures. */

	/* Calculate geometry */
	inftl->cylinders = 1024;
	inftl->heads = 16;

	temp = inftl->cylinders * inftl->heads;
	inftl->sectors = inftl->mbd.size / temp;
	if (inftl->mbd.size % temp) {
		inftl->sectors++;
		temp = inftl->cylinders * inftl->sectors;
		inftl->heads = inftl->mbd.size / temp;

		if (inftl->mbd.size % temp) {
			inftl->heads++;
			temp = inftl->heads * inftl->sectors;
			inftl->cylinders = inftl->mbd.size / temp;
		}
	}

	if (inftl->mbd.size != inftl->heads * inftl->cylinders * inftl->sectors) {
		/*
		  Oh no we don't have
		   mbd.size == heads * cylinders * sectors
		*/
		printk(KERN_WARNING "INFTL: cannot calculate a geometry to "
		       "match size of 0x%lx.\n", inftl->mbd.size);