summaryrefslogtreecommitdiffstats
path: root/doc/bsp_howto/nvmem.t
blob: 2c1063b8c33b4882df95910258c3f7eff98a41ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@c
@c  COPYRIGHT (c) 1988-2002.
@c  On-Line Applications Research Corporation (OAR).
@c  All rights reserved.
@c
@c  $Id$
@c

@chapter Non-Volatile Memory Driver

The Non-Volatile driver is responsible for providing an
interface to various types of non-volatile memory.  These
types of memory include, but are not limited to, Flash, EEPROM,
and battery backed RAM.  The capabilities provided
by this class of device driver are:

@itemize @bullet
@item Initialize the Non-Volatile Memory Driver
@item Optional Disable Read and Write Handlers
@item Open a Particular Memory Partition
@item Close a Particular Memory Partition
@item Read from a Particular Memory Partition
@item Write to a Particular Memory Partition
@item Erase the Non-Volatile Memory Area
@end itemize

There is currently only one non-volatile device driver included in the
RTEMS source tree.  The information provided in this chapter
is based on drivers developed for applications using RTEMS.
It is hoped that this driver model information can form the
basis for a standard non-volatile memory driver model that
can be supported in future RTEMS distribution.

@section Major and Minor Numbers

The @b{major} number of a device driver is its index in the
RTEMS Device Address Table.

A @b{minor} number is associated with each device instance
managed by a particular device driver.  An RTEMS minor number
is an @code{unsigned32} entity.  Convention calls
dividing the bits in the minor number down into categories
that specify an area of non-volatile memory and a partition
with that area.  This results in categories
like the following:

@itemize @bullet

@item @b{area} - indicates a block of non-volatile memory
@item @b{partition} - indicates a particular address range with an area

@end itemize

From the above, it should be clear that a single device driver
can support multiple types of non-volatile memory in a single system.
The minor number is used to distinguish the types of memory and
blocks of memory used for different purposes.

@section Non-Volatile Memory Driver Configuration

There is not a standard non-volatile driver configuration table but some
fields are common across different drivers.  The non-volatile memory driver
configuration table is typically an array of structures with each
structure containing the information for a particular area of
non-volatile memory.
The following is a list of the type of information normally required
to configure each area of non-volatile memory.

@table @b
@item memory_type
is the type of memory device in this area.  Choices are battery backed RAM,
EEPROM, Flash, or an optional user-supplied type.  If the user-supplied type
is configured, then the user is responsible for providing a set of
routines to program the memory.

@item memory
is the base address of this memory area.

@item attributes
is a pointer to a memory type specific attribute block.  Some of
the fields commonly contained in this memory type specific attribute
structure area:

@table @b
@item use_protection_algorithm
is set to TRUE to indicate that the protection (i.e. locking) algorithm
should be used for this area of non-volatile memory.  A particular
type of non-volatile memory may not have a protection algorithm.

@item access
is an enumerated type to indicate the organization of the memory 
devices in this memory area.  The following is a list of the
access types supported by the current driver implementation:

@itemize @bullet
@item simple unsigned8
@item simple unsigned16 
@item simple unsigned32 
@item simple unsigned64
@item single unsigned8 at offset 0 in an unsigned16
@item single unsigned8 at offset 1 in an unsigned16 
@item single unsigned8 at offset 0 in an unsigned32
@item single unsigned8 at offset 1 in an unsigned32 
@item single unsigned8 at offset 2 in an unsigned32 
@item single unsigned8 at offset 3 in an unsigned32 
@end itemize

@item depth
is the depth of the progamming FIFO on this particular chip.  Some 
chips, particularly EEPROMs, have the same programming algorithm but
vary in the depth of the amount of data that can be programmed in a single
block.

@end table

@item number_of_partitions
is the number of logical partitions within this area.

@item Partitions
is the address of the table that contains an entry to describe each
partition in this area.  Fields within each element of this
table are defined as follows:

@table @b

@item offset
is the offset of this partition from the base address of this area.

@item length 
is the length of this partition.

@end table
@end table

By dividing an area of memory into multiple partitions, it is possible 
to easily divide the non-volatile memory for different purposes.

@section Initialize the Non-Volatile Memory Driver

At system initialization, the non-volatile memory driver's
initialization entry point will be invoked.  As part of
initialization, the driver will perform
whatever initializatin is required on each non-volatile memory area.

The discrete I/O driver may register device names for memory 
partitions of particular interest to the system.  Normally this
will be restricted to the device "/dev/nv_memory" to indicate
the entire device driver.

@section Disable Read and Write Handlers

Depending on the target's non-volatile memory configuration, it may be
possible to write to a status register and make the memory area completely 
inaccessible.  This is target dependent and beyond the standard capabilities
of any memory type.  The user has the optional capability to provide 
handlers to disable and enable access to a partiticular memory area.

@section Open a Particular Memory Partition

This is the driver open call.  Usually this call does nothing other than
validate the minor number.

With some drivers, it may be necessary to allocate memory when a particular
device is opened.  If that is the case, then this is often the place
to do this operation.

@section Close a Particular Memory Partition

This is the driver close call.  Usually this call does nothing.

With some drivers, it may be necessary to allocate memory when a particular
device is opened.  If that is the case, then this is the place
where that memory should be deallocated.

@section Read from a Particular Memory Partition

This corresponds to the driver read call.  After validating the minor
number and arguments, this call enables reads from the specified
memory area by invoking the user supplied "enable reads handler"
and then reads the indicated memory area.  When
invoked the @code{argument_block} is actually a pointer to the following
structure type:

@example
@group
typedef struct @{
  rtems_unsigned32   offset;
  void              *buffer;
  rtems_unsigned32   length;
  rtems_unsigned32   status;
@}   Non_volatile_memory_Driver_arguments;
@end group
@end example

The driver reads @code{length} bytes starting at @code{offset} into
the partition and places them at @code{buffer}.  The result is returned 
in @code{status}.

After the read operation is complete, the user supplied "disable reads handler"
is invoked to protect the memory area again.

@section Write to a Particular Memory Partition

This corresponds to the driver write call.   After validating the minor
number and arguments, this call enables writes to the specified
memory area by invoking the "enable writes handler", then unprotecting
the memory area, and finally actually writing to the indicated memory
area.  When invoked the @code{argument_block} is actually a pointer to
the following structure type:

@example
@group
typedef struct @{
  rtems_unsigned32   offset;
  void              *buffer;
  rtems_unsigned32   length;
  rtems_unsigned32   status;
@}   Non_volatile_memory_Driver_arguments;
@end group
@end example

The driver writes @code{length} bytes from @code{buffer} and 
writes them to the non-volatile memory starting at @code{offset} into
the partition.  The result is returned in @code{status}.

After the write operation is complete, the "disable writes handler"
is invoked to protect the memory area again.

@section Erase the Non-Volatile Memory Area

This is one of the IOCTL functions supported by the I/O control
device driver entry point.  When this IOCTL function is invoked,
the specified area of non-volatile memory is erased.