#ifndef _FLASH_H_
#define _FLASH_H_
#include <sys/param.h>
#include <sys/device.h>
#include <sys/module.h>
#include <sys/buf.h>
#include <sys/flashio.h>
#ifdef FLASH_DEBUG
#define FLDPRINTF(x) if (flashdebug) printf x
#define FLDPRINTFN(n,x) if (flashdebug>(n)) printf x
#else
#define FLDPRINTF(x)
#define FLDPRINTFN(n,x)
#endif
struct flash_partition {
flash_off_t part_offset;
flash_size_t part_size;
int part_flags;
const char *part_name;
};
struct flash_softc {
device_t sc_dev;
device_t sc_parent_dev;
void *hw_softc;
struct flash_interface *flash_if;
struct flash_partition sc_partinfo;
bool sc_readonly;
};
struct flash_attach_args {
struct flash_interface *flash_if;
struct flash_partition partinfo;
};
struct flash_erase_instruction {
flash_off_t ei_addr;
flash_off_t ei_len;
void (*ei_callback)(struct flash_erase_instruction *);
u_long ei_priv;
u_char ei_state;
};
enum {
FLASH_PART_READONLY = (1<<0),
FLASH_PART_FILESYSTEM = (1<<2)
};
struct flash_interface {
int (*erase)(device_t, struct flash_erase_instruction *);
int (*read)(device_t, flash_off_t, size_t, size_t *, uint8_t *);
int (*write)(device_t, flash_off_t, size_t, size_t *, const uint8_t *);
int (*block_markbad)(device_t, flash_off_t);
int (*block_isbad)(device_t, flash_off_t, bool *);
int (*sync)(device_t);
int (*submit)(device_t, struct buf *);
uint32_t page_size;
uint32_t erasesize;
uint32_t writesize;
uint32_t minor;
uint8_t type;
};
struct flash_cache {
size_t fc_len;
flash_off_t fc_block;
uint8_t *fc_data;
};
device_t flash_attach_mi(struct flash_interface *, device_t);
void flash_attach_mtdparts(struct flash_interface *, device_t, flash_size_t, const char *, const char *);
const struct flash_interface *flash_get_interface(dev_t);
const struct flash_softc *flash_get_softc(dev_t);
device_t flash_get_device(dev_t);
flash_size_t flash_get_size(dev_t);
int flash_erase(device_t, struct flash_erase_instruction *);
int flash_read(device_t, flash_off_t, size_t, size_t *, uint8_t *);
int flash_write(device_t, flash_off_t, size_t, size_t *, const uint8_t *);
int flash_block_markbad(device_t, flash_off_t);
int flash_block_isbad(device_t, flash_off_t, bool *);
int flash_sync(device_t);
static __inline int
check_pattern(const void *buf, uint8_t patt, size_t offset, size_t size)
{
size_t i;
for (i = offset; i < size; i++) {
if (((const uint8_t *)buf)[i] != patt)
return 0;
}
return 1;
}
#endif