xref: /inferno-os/os/port/flashif.h (revision 7ef44d652ae9e5e1f5b3465d73684e4a54de73c0)
1 typedef struct Flash Flash;
2 typedef struct Flashchip Flashchip;
3 typedef struct Flashpart Flashpart;
4 typedef struct Flashregion Flashregion;
5 
6 /*
7  * logical partitions
8  */
9 enum {
10 	Maxflashpart = 8
11 };
12 
13 struct Flashpart {
14 	char*	name;
15 	ulong	start;
16 	ulong	end;
17 };
18 
19 enum {
20 	Maxflashregion = 4
21 };
22 
23 /*
24  * physical erase block regions
25  */
26 struct Flashregion {
27 	int	n;	/* number of blocks in region */
28 	ulong	start;	/* physical base address (allowing for banks) */
29 	ulong	end;
30 	ulong	erasesize;
31 	ulong	pagesize;	/* if non-zero, the size of pages within the erase block */
32 };
33 
34 /*
35  * one of a set of chips in a given region
36  */
37 struct Flashchip {
38 	int	nr;
39 	Flashregion	regions[Maxflashregion];
40 
41 	uchar	id;	/* flash manufacturer ID */
42 	ushort	devid;	/* flash device ID */
43 	int	width;	/* bytes per flash line */
44 	int	maxwb;	/* max write buffer size */
45 	ulong	devsize;	/* physical device size */
46 	int	alg;	/* programming algorithm (if CFI) */
47 	int	protect;	/* software protection */
48 };
49 
50 /*
51  * structure defining a contiguous region of flash memory
52  */
53 struct Flash {
54 	QLock;	/* interlock on flash operations */
55 	Flash*	next;
56 
57 	/* the following are filled in before calling Flash.reset */
58 	char*	type;
59 	void*	addr;
60 	ulong	size;
61 	int	xip;	/* executing in place: don't query */
62 	int	(*reset)(Flash*);
63 
64 	/* the following are filled in by the reset routine */
65 	int	(*eraseall)(Flash*);
66 	int	(*erasezone)(Flash*, Flashregion*, ulong);
67 	int	(*read)(Flash*, ulong, void*, long);	/* (optional) reads of correct width and alignment */
68 	int	(*write)(Flash*, ulong, void*, long);	/* writes of correct width and alignment */
69 	int	(*suspend)(Flash*);
70 	int	(*resume)(Flash*);
71 	int	(*attach)(Flash*);
72 
73 	/* the following might be filled in by either archflashreset or the reset routine */
74 	int	nr;
75 	Flashregion	regions[Maxflashregion];
76 
77 	uchar	id;	/* flash manufacturer ID */
78 	ushort	devid;	/* flash device ID */
79 	int	width;	/* bytes per flash line */
80 	int	interleave;	/* addresses are interleaved across set of chips */
81 	int	bshift;	/* byte addresses are shifted */
82 	ulong	cmask;	/* command mask for interleaving */
83 	int	maxwb;	/* max write buffer size */
84 	ulong	devsize;	/* physical device size */
85 	int	alg;	/* programming algorithm (if CFI) */
86 	void*	data;		/* flash type routines' private storage, or nil */
87 	Flashpart	part[Maxflashpart];	/* logical partitions */
88 	int	protect;	/* software protection */
89 	char*	sort;	/* "nand", "nor", "serial", nil (unspecified) */
90 };
91 
92 /*
93  * called by link routine of driver for specific flash type: arguments are
94  * conventional name for card type/model, and card driver's reset routine.
95  */
96 void	addflashcard(char*, int (*)(Flash*));
97 
98 /*
99  * called by devflash.c:/^flashreset; if flash exists,
100  * sets type, address, and size in bytes of flash
101  * and returns 0; returns -1 if flash doesn't exist
102  */
103 int	archflashreset(int, Flash*);
104 
105 /*
106  * enable/disable write protect
107  */
108 void	archflashwp(Flash*, int);
109 
110 /*
111  * flash access taking width and interleave into account
112  */
113 int	flashget(Flash*, ulong);
114 void	flashput(Flash*, ulong, int);
115 
116 /*
117  * Architecture specific routines for managing nand devices
118  */
119 
120 /*
121  * do any device spcific initialisation
122  */
123 void archnand_init(Flash*);
124 
125 /*
126  * if claim is 1, claim device exclusively, and enable it (power it up)
127  * if claim is 0, release, and disable it (power it down)
128  * claiming may be as simple as a qlock per device
129  */
130 void archnand_claim(Flash*, int claim);
131 
132 /*
133  * set command latch enable (CLE) and address latch enable (ALE)
134  * appropriately
135  */
136 void archnand_setCLEandALE(Flash*, int cle, int ale);
137 
138 /*
139  * write a sequence of bytes to the device
140  */
141 void archnand_write(Flash*, void *buf, int len);
142 
143 /*
144  * read a sequence of bytes from the device
145  * if buf is 0, throw away the data
146  */
147 void archnand_read(Flash*, void *buf, int len);
148