RTEMS 6.1-rc5
Loading...
Searching...
No Matches
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
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46
47typedef struct rtems_flashdev rtems_flashdev;
48
59/* IOCTL Calls */
60
66#define RTEMS_FLASHDEV_IOCTL_OBTAIN 0
72#define RTEMS_FLASHDEV_IOCTL_RELEASE 1
80#define RTEMS_FLASHDEV_IOCTL_JEDEC_ID 2
87#define RTEMS_FLASHDEV_IOCTL_ERASE 3
97#define RTEMS_FLASHDEV_IOCTL_REGION_SET 4
103#define RTEMS_FLASHDEV_IOCTL_REGION_UNSET 5
110#define RTEMS_FLASHDEV_IOCTL_TYPE 6
111
121#define RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_OFFSET 7
122
131#define RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_INDEX 8
132
138#define RTEMS_FLASHDEV_IOCTL_PAGE_COUNT 9
139
145#define RTEMS_FLASHDEV_IOCTL_WRITE_BLOCK_SIZE 10
146
156#define RTEMS_FLASHDEV_IOCTL_SECTORINFO_BY_OFFSET 11
157
163#define RTEMS_FLASHDEV_IOCTL_SECTOR_COUNT 12
164
169#define RTEMS_FLASHDEV_MAX_REGIONS 32
170
184
188typedef struct rtems_flashdev_region {
192 off_t offset;
196 size_t size;
198
207
213
218 uint32_t *bit_allocator;
220
228 off_t location;
229
236
244 off_t location;
245
252
268 int ( *read )(
269 rtems_flashdev *flash,
270 uintptr_t offset,
271 size_t count,
272 void *buffer
273 );
274
286 int ( *write )(
287 rtems_flashdev *flash,
288 uintptr_t offset,
289 size_t count,
290 const void *buffer
291 );
292
303 int ( *erase )(
304 rtems_flashdev *flash,
305 uintptr_t offset,
306 size_t count
307 );
308
316 uint32_t ( *jedec_id )(
317 rtems_flashdev *flash
318 );
319
329 int ( *flash_type )(
330 rtems_flashdev *flash,
332 );
333
348 rtems_flashdev *flash,
349 off_t search_offset,
350 off_t *page_offset,
351 size_t *page_size
352 );
353
367 rtems_flashdev *flashdev,
368 off_t search_index,
369 off_t *page_offset,
370 size_t *page_size
371 );
372
382 int ( *page_count )(
383 rtems_flashdev *flashdev,
384 int *page_count
385 );
386
397 rtems_flashdev *flashdev,
398 size_t *write_block_size
399 );
400
415 rtems_flashdev *flash,
416 off_t search_offset,
417 off_t *sector_offset,
418 size_t *sector_size
419 );
420
430 int ( *sector_count )(
431 rtems_flashdev *flashdev,
432 int *page_count
433 );
434
440 void ( *destroy )(
441 rtems_flashdev *flashdev
442 );
443
447 void *driver;
448
452 rtems_recursive_mutex mutex;
453
458};
459
472 size_t size
473);
474
490 rtems_flashdev *flash
491);
492
508 rtems_flashdev *flash,
509 const char *flash_path
510);
511
518 rtems_flashdev *flash
519);
520
527 rtems_flashdev *flash
528);
529
530#ifdef __cplusplus
531}
532#endif
533
536#endif /* _DEV_FLASHDEV_H */
rtems_flashdev * rtems_flashdev_alloc_and_init(size_t size)
Allocate and initialize the flash device.
Definition: flashdev.c:547
rtems_flashdev_flash_type
Enum for flash type returned from IOCTL call.
Definition: flashdev.h:174
int rtems_flashdev_register(rtems_flashdev *flash, const char *flash_path)
Register the flash device.
Definition: flashdev.c:476
void rtems_flashdev_destroy(rtems_flashdev *flash)
Destroys the flash device.
Definition: flashdev.c:524
int rtems_flashdev_init(rtems_flashdev *flash)
Initialize the flash device.
Definition: flashdev.c:540
void rtems_flashdev_destroy_and_free(rtems_flashdev *flash)
Destroys the flash device and frees its memory.
Definition: flashdev.c:529
@ RTEMS_FLASHDEV_NAND
The flash device is NAND flash.
Definition: flashdev.h:182
@ RTEMS_FLASHDEV_NOR
The flash device is NOR flash.
Definition: flashdev.h:178
Page information returned from IOCTL calls.
Definition: flashdev.h:224
off_t location
Offset or index to find page at.
Definition: flashdev.h:228
rtems_flashdev_region page_info
Information returned about the page. Including the base offset and size of page.
Definition: flashdev.h:234
Sector information returned from IOCTL calls.
Definition: flashdev.h:240
off_t location
Offset or index to find sector at.
Definition: flashdev.h:244
rtems_flashdev_region sector_info
Information returned about the sector. Including the base offset and size of sector.
Definition: flashdev.h:250
Struct holding region definitions.
Definition: flashdev.h:202
int max_regions
The maximum regions that can be defined at once.
Definition: flashdev.h:206
rtems_flashdev_region * regions
Pointer to array of rtems_flashdev_region of length max_regions.
Definition: flashdev.h:212
uint32_t * bit_allocator
Array of uint32_t acting as bit allocator for regions array.
Definition: flashdev.h:218
General definition for on flash device.
Definition: flashdev.h:188
size_t size
Length of region.
Definition: flashdev.h:196
off_t offset
Base of region.
Definition: flashdev.h:192
Flash device.
Definition: flashdev.h:256
int(* erase)(rtems_flashdev *flash, uintptr_t offset, size_t count)
Call to the device driver to erase the flash device.
Definition: flashdev.h:303
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:396
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:347
void * driver
Pointer to device driver.
Definition: flashdev.h:447
uint32_t(* jedec_id)(rtems_flashdev *flash)
Call to the device driver to return the JEDEC ID.
Definition: flashdev.h:316
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:366
rtems_flashdev_region_table * region_table
Region table defining size and memory for region allocations.
Definition: flashdev.h:457
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:286
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:382
void(* destroy)(rtems_flashdev *flashdev)
Destroys the flash device.
Definition: flashdev.h:440
int(* flash_type)(rtems_flashdev *flash, rtems_flashdev_flash_type *type)
Call to the device driver to return the flash type.
Definition: flashdev.h:329
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:268
rtems_recursive_mutex mutex
Mutex to protect the flash device access.
Definition: flashdev.h:452
int(* sector_info_by_offset)(rtems_flashdev *flash, off_t search_offset, off_t *sector_offset, size_t *sector_size)
Call to device driver to get size and offset of sector at given offset.
Definition: flashdev.h:414
int(* sector_count)(rtems_flashdev *flashdev, int *page_count)
Call to device driver to return the number of sectors on the flash device.
Definition: flashdev.h:430
This header file provides the API of Self-Contained Objects.