RTEMS 6.1-rc1
flashdev.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (C) 2023 Aaron Nyholm
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _DEV_FLASHDEV_H
37#define _DEV_FLASHDEV_H
38
39#include <rtems/thread.h>
40#include <sys/types.h>
41
42typedef struct rtems_flashdev rtems_flashdev;
43
54/* IOCTL Calls */
55
61#define RTEMS_FLASHDEV_IOCTL_OBTAIN 0
67#define RTEMS_FLASHDEV_IOCTL_RELEASE 1
75#define RTEMS_FLASHDEV_IOCTL_JEDEC_ID 2
82#define RTEMS_FLASHDEV_IOCTL_ERASE 3
92#define RTEMS_FLASHDEV_IOCTL_REGION_SET 4
98#define RTEMS_FLASHDEV_IOCTL_REGION_UNSET 5
105#define RTEMS_FLASHDEV_IOCTL_TYPE 6
106
116#define RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_OFFSET 7
117
126#define RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_INDEX 8
127
133#define RTEMS_FLASHDEV_IOCTL_PAGE_COUNT 9
134
140#define RTEMS_FLASHDEV_IOCTL_WRITE_BLOCK_SIZE 10
141
146#define RTEMS_FLASHDEV_MAX_REGIONS 32
147
161
165typedef struct rtems_flashdev_region {
169 off_t offset;
173 size_t size;
175
184
190
195 uint32_t *bit_allocator;
197
205 off_t location;
206
213
229 int ( *read )(
230 rtems_flashdev *flash,
231 uintptr_t offset,
232 size_t count,
233 void *buffer
234 );
235
247 int ( *write )(
248 rtems_flashdev *flash,
249 uintptr_t offset,
250 size_t count,
251 const void *buffer
252 );
253
264 int ( *erase )(
265 rtems_flashdev *flash,
266 uintptr_t offset,
267 size_t count
268 );
269
277 uint32_t ( *jedec_id )(
278 rtems_flashdev *flash
279 );
280
290 int ( *flash_type )(
291 rtems_flashdev *flash,
293 );
294
309 rtems_flashdev *flash,
310 off_t search_offset,
311 off_t *page_offset,
312 size_t *page_size
313 );
314
328 rtems_flashdev *flashdev,
329 off_t search_index,
330 off_t *page_offset,
331 size_t *page_size
332 );
333
343 int ( *page_count )(
344 rtems_flashdev *flashdev,
345 int *page_count
346 );
347
358 rtems_flashdev *flashdev,
359 size_t *write_block_size
360 );
361
367 void ( *destroy )(
368 rtems_flashdev *flashdev
369 );
370
374 void *driver;
375
379 rtems_recursive_mutex mutex;
380
385};
386
399 size_t size
400);
401
417 rtems_flashdev *flash
418);
419
435 rtems_flashdev *flash,
436 const char *flash_path
437);
438
445 rtems_flashdev *flash
446);
447
454 rtems_flashdev *flash
455);
456
459#endif /* _DEV_FLASHDEV_H */
rtems_flashdev * rtems_flashdev_alloc_and_init(size_t size)
Allocate and initialize the flash device.
Definition: flashdev.c:529
rtems_flashdev_flash_type
Enum for flash type returned from IOCTL call.
Definition: flashdev.h:151
struct rtems_flashdev_region rtems_flashdev_region
General definition for on flash device.
int rtems_flashdev_register(rtems_flashdev *flash, const char *flash_path)
Register the flash device.
Definition: flashdev.c:458
struct rtems_flashdev_region_table rtems_flashdev_region_table
Struct holding region definitions.
struct rtems_flashdev_ioctl_page_info rtems_flashdev_ioctl_page_info
Page information returned from IOCTL calls.
void rtems_flashdev_destroy(rtems_flashdev *flash)
Destroys the flash device.
Definition: flashdev.c:506
int rtems_flashdev_init(rtems_flashdev *flash)
Initialize the flash device.
Definition: flashdev.c:522
void rtems_flashdev_destroy_and_free(rtems_flashdev *flash)
Destroys the flash device and frees its memory.
Definition: flashdev.c:511
@ RTEMS_FLASHDEV_NAND
The flash device is NAND flash.
Definition: flashdev.h:159
@ RTEMS_FLASHDEV_NOR
The flash device is NOR flash.
Definition: flashdev.h:155
Page information returned from IOCTL calls.
Definition: flashdev.h:201
off_t location
Offset or index to find page at.
Definition: flashdev.h:205
rtems_flashdev_region page_info
Information returned about the page. Including the base offset and size of page.
Definition: flashdev.h:211
Struct holding region definitions.
Definition: flashdev.h:179
int max_regions
The maximum regions that can be defined at once.
Definition: flashdev.h:183
rtems_flashdev_region * regions
Pointer to array of rtems_flashdev_region of length max_regions.
Definition: flashdev.h:189
uint32_t * bit_allocator
Array of uint32_t acting as bit allocator for regions array.
Definition: flashdev.h:195
General definition for on flash device.
Definition: flashdev.h:165
size_t size
Length of region.
Definition: flashdev.h:173
off_t offset
Base of region.
Definition: flashdev.h:169
Flash device.
Definition: flashdev.h:217
int(* erase)(rtems_flashdev *flash, uintptr_t offset, size_t count)
Call to the device driver to erase the flash device.
Definition: flashdev.h:264
int(* write_block_size)(rtems_flashdev *flashdev, size_t *write_block_size)
Call to device driver to return the minimum write size of the flash device.
Definition: flashdev.h:357
int(* page_info_by_offset)(rtems_flashdev *flash, off_t search_offset, off_t *page_offset, size_t *page_size)
Call to device driver to get size and offset of page at given offset.
Definition: flashdev.h:308
void * driver
Pointer to device driver.
Definition: flashdev.h:374
uint32_t(* jedec_id)(rtems_flashdev *flash)
Call to the device driver to return the JEDEC ID.
Definition: flashdev.h:277
int(* page_info_by_index)(rtems_flashdev *flashdev, off_t search_index, off_t *page_offset, size_t *page_size)
Call to device driver to get size and offset of page at given index.
Definition: flashdev.h:327
rtems_flashdev_region_table * region_table
Region table defining size and memory for region allocations.
Definition: flashdev.h:384
int(* write)(rtems_flashdev *flash, uintptr_t offset, size_t count, const void *buffer)
Call to the device driver to write to the flash device.
Definition: flashdev.h:247
int(* page_count)(rtems_flashdev *flashdev, int *page_count)
Call to device driver to return the number of pages on the flash device.
Definition: flashdev.h:343
void(* destroy)(rtems_flashdev *flashdev)
Destroys the flash device.
Definition: flashdev.h:367
int(* flash_type)(rtems_flashdev *flash, rtems_flashdev_flash_type *type)
Call to the device driver to return the flash type.
Definition: flashdev.h:290
int(* read)(rtems_flashdev *flash, uintptr_t offset, size_t count, void *buffer)
Call to the device driver to read the flash device.
Definition: flashdev.h:229
rtems_recursive_mutex mutex
Mutex to protect the flash device access.
Definition: flashdev.h:379
unsigned size
Definition: tte.h:1
This header file provides the API of Self-Contained Objects.