RTEMS 6.2-rc2
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
174#define RTEMS_FLASHDEV_IOCTL_REGION_SECTORINFO_BY_OFFSET 13
175
184#define RTEMS_FLASHDEV_IOCTL_OOB_BYTES_PER_PAGE 14
185
195#define RTEMS_FLASHDEV_IOCTL_REGION_OOB_READ 15
196
206#define RTEMS_FLASHDEV_IOCTL_REGION_OOB_WRITE 16
207
217#define RTEMS_FLASHDEV_IOCTL_REGION_SECTOR_MARK_BAD 17
218
228#define RTEMS_FLASHDEV_IOCTL_REGION_SECTOR_HEALTH 18
229
234#define RTEMS_FLASHDEV_MAX_REGIONS 32
235
249
253typedef struct rtems_flashdev_region {
257 off_t offset;
261 size_t size;
263
272
278
283 uint32_t *bit_allocator;
285
293 off_t location;
294
301
309 off_t location;
310
317
325 off_t location;
326
332 uint8_t sector_bad;
334
342 off_t offset;
343
347 void *buffer;
348
352 size_t count;
354
370 int ( *read )(
371 rtems_flashdev *flash,
372 uintptr_t offset,
373 size_t count,
374 void *buffer
375 );
376
388 int ( *write )(
389 rtems_flashdev *flash,
390 uintptr_t offset,
391 size_t count,
392 const void *buffer
393 );
394
405 int ( *erase )(
406 rtems_flashdev *flash,
407 uintptr_t offset,
408 size_t count
409 );
410
418 uint32_t ( *jedec_id )(
419 rtems_flashdev *flash
420 );
421
431 int ( *flash_type )(
432 rtems_flashdev *flash,
434 );
435
450 rtems_flashdev *flash,
451 off_t search_offset,
452 off_t *page_offset,
453 size_t *page_size
454 );
455
469 rtems_flashdev *flashdev,
470 off_t search_index,
471 off_t *page_offset,
472 size_t *page_size
473 );
474
484 int ( *page_count )(
485 rtems_flashdev *flashdev,
486 int *page_count
487 );
488
499 rtems_flashdev *flashdev,
500 size_t *write_block_size
501 );
502
517 rtems_flashdev *flash,
518 off_t search_offset,
519 off_t *sector_offset,
520 size_t *sector_size
521 );
522
532 int ( *sector_count )(
533 rtems_flashdev *flashdev,
534 int *page_count
535 );
536
547 rtems_flashdev *flashdev,
548 size_t *oob_bytes_per_page
549 );
550
563 int ( *oob_read )(
564 rtems_flashdev *flash,
565 uintptr_t offset,
566 size_t count,
567 void *buffer
568 );
569
582 int ( *oob_write )(
583 rtems_flashdev *flash,
584 uintptr_t offset,
585 size_t count,
586 const void *buffer
587 );
588
602 rtems_flashdev *flash,
603 off_t offset
604 );
605
618 rtems_flashdev *flash,
619 off_t search_offset,
620 uint8_t *sector_bad
621 );
622
628 void ( *destroy )(
629 rtems_flashdev *flashdev
630 );
631
638 void ( *priv_destroy )(
639 rtems_flashdev *flashdev
640 );
641
645 void *driver;
646
650 rtems_recursive_mutex mutex;
651
656};
657
670 size_t size
671);
672
688 rtems_flashdev *flash
689);
690
707 rtems_flashdev *flash,
708 const char *flash_path
709);
710
720 const char *flash_path
721);
722
732 rtems_flashdev *flash
733);
734
744 rtems_flashdev *flash
745);
746
747#ifdef __cplusplus
748}
749#endif
750
753#endif /* _DEV_FLASHDEV_H */
int rtems_flashdev_unregister(const char *flash_path)
Unregister the flash device.
Definition: flashdev.c:564
rtems_flashdev * rtems_flashdev_alloc_and_init(size_t size)
Allocate and initialize the flash device.
Definition: flashdev.c:627
rtems_flashdev_flash_type
Enum for flash type returned from IOCTL call.
Definition: flashdev.h:239
int rtems_flashdev_register(rtems_flashdev *flash, const char *flash_path)
Register the flash device.
Definition: flashdev.c:536
void rtems_flashdev_destroy(rtems_flashdev *flash)
Destroys the flash device.
Definition: flashdev.c:591
int rtems_flashdev_init(rtems_flashdev *flash)
Initialize the flash device.
Definition: flashdev.c:620
void rtems_flashdev_destroy_and_free(rtems_flashdev *flash)
Destroys the flash device and frees its memory.
Definition: flashdev.c:596
@ RTEMS_FLASHDEV_NAND
The flash device is NAND flash.
Definition: flashdev.h:247
@ RTEMS_FLASHDEV_NOR
The flash device is NOR flash.
Definition: flashdev.h:243
Read/write information used with OOB IOCTL calls.
Definition: flashdev.h:338
void * buffer
Buffer on which to operate.
Definition: flashdev.h:347
size_t count
Number of bytes to transfer.
Definition: flashdev.h:352
off_t offset
Offset at which to operate.
Definition: flashdev.h:342
Page information returned from IOCTL calls.
Definition: flashdev.h:289
off_t location
Offset or index to find page at.
Definition: flashdev.h:293
rtems_flashdev_region page_info
Information returned about the page. Including the base offset and size of page.
Definition: flashdev.h:299
Sector information returned from IOCTL calls.
Definition: flashdev.h:321
off_t location
Offset or index to find sector at.
Definition: flashdev.h:325
uint8_t sector_bad
Health information returned about the sector.
Definition: flashdev.h:332
Sector information returned from IOCTL calls.
Definition: flashdev.h:305
off_t location
Offset or index to find sector at.
Definition: flashdev.h:309
rtems_flashdev_region sector_info
Information returned about the sector. Including the base offset and size of sector.
Definition: flashdev.h:315
Struct holding region definitions.
Definition: flashdev.h:267
int max_regions
The maximum regions that can be defined at once.
Definition: flashdev.h:271
rtems_flashdev_region * regions
Pointer to array of rtems_flashdev_region of length max_regions.
Definition: flashdev.h:277
uint32_t * bit_allocator
Array of uint32_t acting as bit allocator for regions array.
Definition: flashdev.h:283
General definition for on flash device.
Definition: flashdev.h:253
size_t size
Length of region.
Definition: flashdev.h:261
off_t offset
Base of region.
Definition: flashdev.h:257
Flash device.
Definition: flashdev.h:358
int(* sector_health)(rtems_flashdev *flash, off_t search_offset, uint8_t *sector_bad)
Call to device driver to get health of sector at given offset.
Definition: flashdev.h:617
void(* priv_destroy)(rtems_flashdev *flashdev)
Callback to destroy private data not owned directly by the flashdev framework.
Definition: flashdev.h:638
int(* erase)(rtems_flashdev *flash, uintptr_t offset, size_t count)
Call to the device driver to erase the flash device.
Definition: flashdev.h:405
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:498
int(* oob_read)(rtems_flashdev *flash, uintptr_t offset, size_t count, void *buffer)
Call to the device driver to read the out of band space of the flash device.
Definition: flashdev.h:563
int(* oob_bytes_per_page)(rtems_flashdev *flashdev, size_t *oob_bytes_per_page)
Call to device driver to return the size of the out of band space.
Definition: flashdev.h:546
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:449
void * driver
Pointer to device driver.
Definition: flashdev.h:645
int(* oob_write)(rtems_flashdev *flash, uintptr_t offset, size_t count, const void *buffer)
Call to the device driver to write to the out of band space of the flash device.
Definition: flashdev.h:582
uint32_t(* jedec_id)(rtems_flashdev *flash)
Call to the device driver to return the JEDEC ID.
Definition: flashdev.h:418
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:468
rtems_flashdev_region_table * region_table
Region table defining size and memory for region allocations.
Definition: flashdev.h:655
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:388
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:484
void(* destroy)(rtems_flashdev *flashdev)
Destroys the flash device.
Definition: flashdev.h:628
int(* flash_type)(rtems_flashdev *flash, rtems_flashdev_flash_type *type)
Call to the device driver to return the flash type.
Definition: flashdev.h:431
int(* sector_mark_bad)(rtems_flashdev *flash, off_t offset)
Call to the device driver to mark a sector as being bad.
Definition: flashdev.h:601
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:370
rtems_recursive_mutex mutex
Mutex to protect the flash device access.
Definition: flashdev.h:650
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:516
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:532
This header file provides the API of Self-Contained Objects.