linux/include/linux/mtd/map.h

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright © 2000-2010 David Woodhouse <[email protected]> et al.
 */

/* Overhauled routines for dealing with different mmap regions of flash */

#ifndef __LINUX_MTD_MAP_H__
#define __LINUX_MTD_MAP_H__

#include <linux/types.h>
#include <linux/list.h>
#include <linux/string.h>
#include <linux/bug.h>
#include <linux/kernel.h>
#include <linux/io.h>

#include <asm/unaligned.h>
#include <asm/barrier.h>

#ifdef CONFIG_MTD_MAP_BANK_WIDTH_1
#define map_bankwidth(map)
#define map_bankwidth_is_1(map)
#define map_bankwidth_is_large(map)
#define map_words(map)
#define MAX_MAP_BANKWIDTH
#else
#define map_bankwidth_is_1
#endif

#ifdef CONFIG_MTD_MAP_BANK_WIDTH_2
# ifdef map_bankwidth
#  undef map_bankwidth
#define map_bankwidth(map)
# else
#define map_bankwidth
#define map_bankwidth_is_large
#define map_words
# endif
#define map_bankwidth_is_2(map)
#undef MAX_MAP_BANKWIDTH
#define MAX_MAP_BANKWIDTH
#else
#define map_bankwidth_is_2
#endif

#ifdef CONFIG_MTD_MAP_BANK_WIDTH_4
# ifdef map_bankwidth
#  undef map_bankwidth
#define map_bankwidth(map)
# else
#define map_bankwidth
#define map_bankwidth_is_large
#define map_words
# endif
#define map_bankwidth_is_4(map)
#undef MAX_MAP_BANKWIDTH
#define MAX_MAP_BANKWIDTH
#else
#define map_bankwidth_is_4
#endif

/* ensure we never evaluate anything shorted than an unsigned long
 * to zero, and ensure we'll never miss the end of an comparison (bjd) */

#define map_calc_words(map)

#ifdef CONFIG_MTD_MAP_BANK_WIDTH_8
# ifdef map_bankwidth
#  undef map_bankwidth
#define map_bankwidth(map)
#  if BITS_PER_LONG < 64
#   undef map_bankwidth_is_large
#define map_bankwidth_is_large
#   undef map_words
#define map_words
#  endif
# else
#define map_bankwidth
#define map_bankwidth_is_large
#define map_words
# endif
#define map_bankwidth_is_8(map)
#undef MAX_MAP_BANKWIDTH
#define MAX_MAP_BANKWIDTH
#else
#define map_bankwidth_is_8
#endif

#ifdef CONFIG_MTD_MAP_BANK_WIDTH_16
# ifdef map_bankwidth
#  undef map_bankwidth
#define map_bankwidth(map)
#  undef map_bankwidth_is_large
#define map_bankwidth_is_large(map)
#  undef map_words
#define map_words(map)
# else
#define map_bankwidth
#define map_bankwidth_is_large
#define map_words
# endif
#define map_bankwidth_is_16(map)
#undef MAX_MAP_BANKWIDTH
#define MAX_MAP_BANKWIDTH
#else
#define map_bankwidth_is_16
#endif

#ifdef CONFIG_MTD_MAP_BANK_WIDTH_32
/* always use indirect access for 256-bit to preserve kernel stack */
# undef map_bankwidth
#define map_bankwidth(map)
# undef map_bankwidth_is_large
#define map_bankwidth_is_large(map)
# undef map_words
#define map_words(map)
#define map_bankwidth_is_32(map)
#undef MAX_MAP_BANKWIDTH
#define MAX_MAP_BANKWIDTH
#else
#define map_bankwidth_is_32
#endif

#ifndef map_bankwidth
#ifdef CONFIG_MTD
#warning "No CONFIG_MTD_MAP_BANK_WIDTH_xx selected. No NOR chip support can work"
#endif
static inline int map_bankwidth(void *map)
{
	BUG();
	return 0;
}
#define map_bankwidth_is_large
#define map_words
#define MAX_MAP_BANKWIDTH
#endif

static inline int map_bankwidth_supported(int w)
{}

#define MAX_MAP_LONGS

map_word;

/* The map stuff is very simple. You fill in your struct map_info with
   a handful of routines for accessing the device, making sure they handle
   paging etc. correctly if your device needs it. Then you pass it off
   to a chip probe routine -- either JEDEC or CFI probe or both -- via
   do_map_probe(). If a chip is recognised, the probe code will invoke the
   appropriate chip driver (if present) and return a struct mtd_info.
   At which point, you fill in the mtd->module with your own module
   address, and register it with the MTD core code. Or you could partition
   it and register the partitions instead, or keep it for your own private
   use; whatever.

   The mtd->priv field will point to the struct map_info, and any further
   private data required by the chip driver is linked from the
   mtd->priv->fldrv_priv field. This allows the map driver to get at
   the destructor function map->fldrv_destroy() when it's tired
   of living.
*/

struct map_info {};

struct mtd_chip_driver {};

void register_mtd_chip_driver(struct mtd_chip_driver *);
void unregister_mtd_chip_driver(struct mtd_chip_driver *);

struct mtd_info *do_map_probe(const char *name, struct map_info *map);
void map_destroy(struct mtd_info *mtd);

#define ENABLE_VPP(map)
#define DISABLE_VPP(map)

#define INVALIDATE_CACHED_RANGE(map, from, size)

#define map_word_equal(map, val1, val2)

#define map_word_and(map, val1, val2)

#define map_word_clr(map, val1, val2)

#define map_word_or(map, val1, val2)

#define map_word_andequal(map, val1, val2, val3)

#define map_word_bitsset(map, val1, val2)

static inline map_word map_word_load(struct map_info *map, const void *ptr)
{}

static inline map_word map_word_load_partial(struct map_info *map, map_word orig, const unsigned char *buf, int start, int len)
{}

#if BITS_PER_LONG < 64
#define MAP_FF_LIMIT
#else
#define MAP_FF_LIMIT
#endif

static inline map_word map_word_ff(struct map_info *map)
{}

static inline map_word inline_map_read(struct map_info *map, unsigned long ofs)
{}

static inline void inline_map_write(struct map_info *map, const map_word datum, unsigned long ofs)
{}

static inline void inline_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
{}

static inline void inline_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
{}

#ifdef CONFIG_MTD_COMPLEX_MAPPINGS
#define map_read(map, ofs)
#define map_copy_from(map, to, from, len)
#define map_write(map, datum, ofs)
#define map_copy_to(map, to, from, len)

extern void simple_map_init(struct map_info *);
#define map_is_linear(map)

#else
#define map_read
#define map_copy_from
#define map_write
#define map_copy_to


#define simple_map_init
#define map_is_linear

#endif /* !CONFIG_MTD_COMPLEX_MAPPINGS */

#endif /* __LINUX_MTD_MAP_H__ */