2010-08-17 21:28:51 +02:00
|
|
|
/****************************************************************************
|
2015-03-21 21:12:58 +01:00
|
|
|
* configs/ea3131/src/lpc31_fillpage.c
|
2010-08-17 21:28:51 +02:00
|
|
|
*
|
2013-02-04 19:46:28 +01:00
|
|
|
* Copyright (C) 2010, 2012-2013 Gregory Nutt. All rights reserved.
|
2012-09-07 00:25:51 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2010-08-17 21:28:51 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2010-08-18 02:35:53 +02:00
|
|
|
#include <errno.h>
|
2010-08-17 21:28:51 +02:00
|
|
|
#include <debug.h>
|
|
|
|
|
2010-08-18 02:35:53 +02:00
|
|
|
#include <nuttx/sched.h>
|
|
|
|
#include <nuttx/page.h>
|
2010-08-17 21:28:51 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_PAGING
|
2010-09-08 19:38:44 +02:00
|
|
|
#ifdef CONFIG_PAGING_BINPATH
|
|
|
|
# include <sys/stat.h>
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <stdbool.h>
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <fcntl.h>
|
2014-03-05 21:25:49 +01:00
|
|
|
# ifdef CONFIG_EA3131_PAGING_SDSLOT
|
2010-09-09 00:06:38 +02:00
|
|
|
# include <stdio.h>
|
|
|
|
# include <sys/mount.h>
|
|
|
|
# include <nuttx/sdio.h>
|
|
|
|
# include <nuttx/mmcsd.h>
|
2015-12-30 01:07:27 +01:00
|
|
|
# include "lpc31.h"
|
2010-09-09 00:06:38 +02:00
|
|
|
# endif
|
2010-09-08 19:38:44 +02:00
|
|
|
#endif
|
2010-08-17 21:28:51 +02:00
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
#if defined(CONFIG_PAGING_M25PX) || defined(CONFIG_PAGING_AT45DB)
|
2010-09-11 03:58:26 +02:00
|
|
|
# include <sys/ioctl.h>
|
2012-03-21 19:01:07 +01:00
|
|
|
# include <nuttx/fs/ioctl.h>
|
2013-07-01 16:11:54 +02:00
|
|
|
# include <nuttx/spi/spi.h>
|
2013-11-15 18:22:23 +01:00
|
|
|
# include <nuttx/mtd/mtd.h>
|
2010-09-11 03:58:26 +02:00
|
|
|
#endif
|
|
|
|
|
2010-08-17 21:28:51 +02:00
|
|
|
/****************************************************************************
|
2015-03-21 21:12:58 +01:00
|
|
|
* Pre-processor Definitions
|
2010-08-17 21:28:51 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2010-09-09 00:06:38 +02:00
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
|
|
|
/* SD SLOT number might depend on the board configuration */
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_BOARD_EA3131
|
2010-09-11 03:58:26 +02:00
|
|
|
# define HAVE_SD 1
|
|
|
|
# define HAVE_SPINOR 1
|
2014-03-05 21:25:49 +01:00
|
|
|
# if defined(CONFIG_EA3131_PAGING_SDSLOT) && CONFIG_EA3131_PAGING_SDSLOT != 0
|
2010-09-09 00:06:38 +02:00
|
|
|
# error "Only one SD slot"
|
2014-03-05 21:25:49 +01:00
|
|
|
# undef CONFIG_EA3131_PAGING_SDSLOT
|
2010-09-09 00:06:38 +02:00
|
|
|
# endif
|
|
|
|
#else
|
2011-05-27 17:26:52 +02:00
|
|
|
/* Add configuration for new LPC31XX boards here */
|
|
|
|
# error "Unrecognized LPC31XX board"
|
2014-03-05 21:25:49 +01:00
|
|
|
# undef CONFIG_EA3131_PAGING_SDSLOT
|
2010-09-09 00:06:38 +02:00
|
|
|
# undef HAVE_SD
|
2010-09-11 03:58:26 +02:00
|
|
|
# undef HAVE_SPINOR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Sanity check: We can only perform paging using a single source device */
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
#if defined(CONFIG_PAGING_M25PX) && defined(CONFIG_PAGING_AT45DB)
|
|
|
|
# error "Both CONFIG_PAGING_M25PX and CONFIG_PAGING_AT45DB are defined"
|
2014-04-14 00:22:22 +02:00
|
|
|
# undef CONFIG_PAGING_M25PX
|
2010-09-12 04:22:13 +02:00
|
|
|
#endif
|
2010-09-11 03:58:26 +02:00
|
|
|
#if defined(CONFIG_PAGING_BINPATH) && defined(CONFIG_PAGING_M25PX)
|
|
|
|
# error "Both CONFIG_PAGING_BINPATH and CONFIG_PAGING_M25PX are defined"
|
2014-04-14 00:22:22 +02:00
|
|
|
# undef CONFIG_PAGING_BINPATH
|
2010-09-09 00:06:38 +02:00
|
|
|
#endif
|
2010-09-12 04:22:13 +02:00
|
|
|
#if defined(CONFIG_PAGING_BINPATH) && defined(CONFIG_PAGING_AT45DB)
|
|
|
|
# error "Both CONFIG_PAGING_BINPATH and CONFIG_PAGING_AT45DB are defined"
|
2014-04-14 00:22:22 +02:00
|
|
|
# undef CONFIG_PAGING_BINPATH
|
2010-09-12 04:22:13 +02:00
|
|
|
#endif
|
2010-09-09 00:06:38 +02:00
|
|
|
|
|
|
|
/* Are we accessing the page source data through a file path? */
|
|
|
|
|
|
|
|
#ifdef CONFIG_PAGING_BINPATH
|
|
|
|
|
|
|
|
/* Can't support SD if the board does not support SD (duh) */
|
|
|
|
|
2014-03-05 21:25:49 +01:00
|
|
|
# if defined(CONFIG_EA3131_PAGING_SDSLOT) && !defined(HAVE_SD)
|
2010-09-09 00:06:38 +02:00
|
|
|
# error "This board does not support SD"
|
2014-03-05 21:25:49 +01:00
|
|
|
# undef CONFIG_EA3131_PAGING_SDSLOT
|
2010-09-09 00:06:38 +02:00
|
|
|
# endif
|
|
|
|
|
|
|
|
/* Can't support SD if mountpoints are disabled or if SDIO support
|
|
|
|
* is not enabled.
|
|
|
|
*/
|
|
|
|
|
2012-09-07 00:25:51 +02:00
|
|
|
# if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_LPC31_MCI)
|
2014-03-05 21:25:49 +01:00
|
|
|
# ifdef CONFIG_EA3131_PAGING_SDSLOT
|
2010-09-09 00:06:38 +02:00
|
|
|
# error "Mountpoints and/or MCI disabled"
|
|
|
|
# endif
|
2014-03-05 21:25:49 +01:00
|
|
|
# undef CONFIG_EA3131_PAGING_SDSLOT
|
2010-09-09 00:06:38 +02:00
|
|
|
# undef HAVE_SD
|
|
|
|
# endif
|
|
|
|
|
|
|
|
/* A mountpoint for the FAT file system must be provided */
|
|
|
|
|
2014-03-05 21:25:49 +01:00
|
|
|
# if !defined(CONFIG_EA3131_PAGING_MOUNTPT) && defined(CONFIG_EA3131_PAGING_SDSLOT)
|
|
|
|
# error "No CONFIG_EA3131_PAGING_MOUNTPT provided"
|
|
|
|
# undef CONFIG_EA3131_PAGING_SDSLOT
|
2010-09-09 00:06:38 +02:00
|
|
|
# undef HAVE_SD
|
|
|
|
# endif
|
|
|
|
|
|
|
|
/* If no minor number is provided, default to zero */
|
|
|
|
|
2014-03-05 21:25:49 +01:00
|
|
|
# ifndef CONFIG_EA3131_PAGING_MINOR
|
|
|
|
# define CONFIG_EA3131_PAGING_MINOR 0
|
2010-09-09 00:06:38 +02:00
|
|
|
# endif
|
|
|
|
|
|
|
|
#endif /* CONFIG_PAGING_BINPATH */
|
|
|
|
|
2010-09-11 03:58:26 +02:00
|
|
|
/* Are we accessing the page source data through the M25P* MTD device? */
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
#if defined(CONFIG_PAGING_M25PX) || defined(CONFIG_PAGING_AT45DB)
|
2010-09-11 03:58:26 +02:00
|
|
|
|
|
|
|
/* Verify that SPI support is enabld */
|
|
|
|
|
2012-09-07 00:25:51 +02:00
|
|
|
#ifndef CONFIG_LPC31_SPI
|
2010-09-11 03:58:26 +02:00
|
|
|
# error "SPI support is not enabled"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Make sure that some value is defined for the offset into the FLASH
|
|
|
|
* of the NuttX binary image.
|
|
|
|
*/
|
|
|
|
|
2014-03-05 21:25:49 +01:00
|
|
|
# ifndef CONFIG_EA3131_PAGING_BINOFFSET
|
|
|
|
# define CONFIG_EA3131_PAGING_BINOFFSET 0
|
2010-09-11 03:58:26 +02:00
|
|
|
# endif
|
|
|
|
|
|
|
|
/* Make sure that some value is defined for the SPI port number */
|
|
|
|
|
2014-03-05 21:25:49 +01:00
|
|
|
# ifndef CONFIG_EA3131_PAGING_SPIPORT
|
|
|
|
# define CONFIG_EA3131_PAGING_SPIPORT 0
|
2010-09-11 03:58:26 +02:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2010-09-08 19:38:44 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-09-11 03:58:26 +02:00
|
|
|
/* State structure needed to support paging from a file */
|
|
|
|
|
2010-09-08 19:38:44 +02:00
|
|
|
#ifdef CONFIG_PAGING_BINPATH
|
|
|
|
struct pg_source_s
|
|
|
|
{
|
|
|
|
bool initialized; /* TRUE: we are initialized */
|
|
|
|
int fd; /* File descriptor of the nuttx.bin file */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-09-11 03:58:26 +02:00
|
|
|
/* State structured needd to support paging through the M25P* MTD interface. */
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
#if defined(CONFIG_PAGING_M25PX) || defined(CONFIG_PAGING_AT45DB)
|
2010-09-11 03:58:26 +02:00
|
|
|
struct pg_source_s
|
|
|
|
{
|
|
|
|
/* If interrupts or DMA are used, then we will have to defer initialization */
|
|
|
|
|
|
|
|
bool initialized; /* TRUE: we are initialized */
|
|
|
|
|
2010-09-11 05:24:26 +02:00
|
|
|
/* This is the M25P* device state structure */
|
2010-09-11 03:58:26 +02:00
|
|
|
|
|
|
|
FAR struct mtd_dev_s *mtd;
|
|
|
|
|
2013-08-27 17:40:19 +02:00
|
|
|
/* This the device geometry */
|
2010-09-11 03:58:26 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG
|
|
|
|
FAR struct mtd_geometry_s geo;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-08-17 21:28:51 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
#if defined(CONFIG_PAGING_BINPATH) || defined(CONFIG_PAGING_M25PX) || defined(CONFIG_PAGING_AT45DB)
|
2010-09-08 19:38:44 +02:00
|
|
|
static struct pg_source_s g_pgsrc;
|
|
|
|
#endif
|
|
|
|
|
2010-08-17 21:28:51 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-09-09 00:06:38 +02:00
|
|
|
/****************************************************************************
|
2011-05-27 17:26:52 +02:00
|
|
|
* Name: lpc31_initsrc()
|
2010-09-09 00:06:38 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the source device that will support paging.
|
|
|
|
* If BINPATH is defined, then it is the full path to a file on a mounted file
|
|
|
|
* system. In this case initialization will be deferred until the first
|
|
|
|
* time that up_fillpage() is called.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-09-11 03:58:26 +02:00
|
|
|
#if defined(CONFIG_PAGING_BINPATH)
|
2011-05-27 17:26:52 +02:00
|
|
|
static inline void lpc31_initsrc(void)
|
2010-09-09 00:06:38 +02:00
|
|
|
{
|
2014-03-05 21:25:49 +01:00
|
|
|
#ifdef CONFIG_EA3131_PAGING_SDSLOT
|
2010-09-09 00:06:38 +02:00
|
|
|
FAR struct sdio_dev_s *sdio;
|
|
|
|
int ret;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Are we already initialized? */
|
|
|
|
|
|
|
|
if (!g_pgsrc.initialized)
|
|
|
|
{
|
2014-03-05 21:25:49 +01:00
|
|
|
#ifdef CONFIG_EA3131_PAGING_SDSLOT
|
2010-09-09 00:06:38 +02:00
|
|
|
char devname[16];
|
|
|
|
#endif
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
pgllinfo("Initializing %s\n", CONFIG_PAGING_BINPATH);
|
2010-09-09 00:06:38 +02:00
|
|
|
|
|
|
|
/* No, do we need to mount an SD device? */
|
|
|
|
|
2014-03-05 21:25:49 +01:00
|
|
|
#ifdef CONFIG_EA3131_PAGING_SDSLOT
|
2010-09-09 00:06:38 +02:00
|
|
|
|
|
|
|
/* Yes.. First, get an instance of the SDIO interface */
|
|
|
|
|
2014-03-05 21:25:49 +01:00
|
|
|
sdio = sdio_initialize(CONFIG_EA3131_PAGING_SDSLOT);
|
2010-09-09 00:06:38 +02:00
|
|
|
DEBUGASSERT(sdio != NULL);
|
|
|
|
|
|
|
|
/* Then bind the SDIO interface to the SD driver */
|
|
|
|
|
2014-03-05 21:25:49 +01:00
|
|
|
ret = mmcsd_slotinitialize(CONFIG_EA3131_PAGING_MINOR, sdio);
|
2010-09-09 00:06:38 +02:00
|
|
|
DEBUGASSERT(ret == OK);
|
2014-04-14 00:22:22 +02:00
|
|
|
|
2010-09-09 00:06:38 +02:00
|
|
|
/* Then let's guess and say that there is a card in the slot.
|
|
|
|
* (We are basically jodido anyway if there is no card in the slot).
|
|
|
|
*/
|
|
|
|
|
|
|
|
sdio_mediachange(sdio, true);
|
|
|
|
|
|
|
|
/* Now mount the file system */
|
|
|
|
|
2014-03-05 21:25:49 +01:00
|
|
|
snprintf(devname, 16, "/dev/mmcsd%d", CONFIG_EA3131_PAGING_MINOR);
|
|
|
|
ret = mount(devname, CONFIG_EA3131_PAGING_MOUNTPT, "vfat", MS_RDONLY, NULL);
|
2010-09-09 00:06:38 +02:00
|
|
|
DEBUGASSERT(ret == OK);
|
|
|
|
|
2014-03-05 21:25:49 +01:00
|
|
|
#endif /* CONFIG_EA3131_PAGING_SDSLOT */
|
2010-09-09 00:06:38 +02:00
|
|
|
|
|
|
|
/* Open the selected path for read-only access */
|
|
|
|
|
|
|
|
g_pgsrc.fd = open(CONFIG_PAGING_BINPATH, O_RDONLY);
|
|
|
|
DEBUGASSERT(g_pgsrc.fd >= 0);
|
2010-09-12 16:35:25 +02:00
|
|
|
|
|
|
|
/* Then we are initialized */
|
|
|
|
|
2010-09-09 00:06:38 +02:00
|
|
|
g_pgsrc.initialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
#elif defined(CONFIG_PAGING_M25PX) || defined(CONFIG_PAGING_AT45DB)
|
2011-05-27 17:26:52 +02:00
|
|
|
static inline void lpc31_initsrc(void)
|
2010-09-11 03:58:26 +02:00
|
|
|
{
|
2010-09-12 16:35:25 +02:00
|
|
|
FAR struct spi_dev_s *spi;
|
2010-09-11 03:58:26 +02:00
|
|
|
#ifdef CONFIG_DEBUG
|
|
|
|
uint32_t capacity;
|
|
|
|
int ret;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Are we already initialized? */
|
|
|
|
|
2015-10-04 22:59:44 +02:00
|
|
|
if (!g_pgsrc.initialized)
|
|
|
|
{
|
2010-09-12 16:35:25 +02:00
|
|
|
/* No... the initialize now */
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
pgllinfo("Initializing\n");
|
2010-09-11 03:58:26 +02:00
|
|
|
|
|
|
|
/* First get an instance of the SPI device interface */
|
|
|
|
|
2016-01-26 23:56:13 +01:00
|
|
|
spi = lpc31_spibus_initialize(CONFIG_EA3131_PAGING_SPIPORT);
|
2010-09-11 03:58:26 +02:00
|
|
|
DEBUGASSERT(spi != NULL);
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
/* Then bind the SPI interface to the MTD driver */
|
2010-09-11 03:58:26 +02:00
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
#ifdef CONFIG_PAGING_M25PX
|
2010-09-11 03:58:26 +02:00
|
|
|
g_pgsrc.mtd = m25p_initialize(spi);
|
2010-09-12 04:22:13 +02:00
|
|
|
#else
|
|
|
|
g_pgsrc.mtd = at45db_initialize(spi);
|
|
|
|
#endif
|
2010-09-11 03:58:26 +02:00
|
|
|
DEBUGASSERT(g_pgsrc.mtd != NULL);
|
|
|
|
|
|
|
|
/* Verify that we can use the device */
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG
|
|
|
|
/* Get the device geometry. (casting to uintptr_t first eliminates
|
|
|
|
* complaints on some architectures where the sizeof long is different
|
|
|
|
* from the size of a pointer).
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = MTD_IOCTL(g_pgsrc.mtd, MTDIOC_GEOMETRY, (unsigned long)&g_pgsrc.geo);
|
|
|
|
DEBUGASSERT(ret >= 0);
|
|
|
|
capacity = g_pgsrc.geo.erasesize*g_pgsrc.geo.neraseblocks;
|
2016-06-11 19:59:51 +02:00
|
|
|
pgllinfo("capacity: %d\n", capacity);
|
2014-03-05 21:25:49 +01:00
|
|
|
DEBUGASSERT(capacity >= (CONFIG_EA3131_PAGING_BINOFFSET + PG_TEXT_VSIZE));
|
2010-09-11 03:58:26 +02:00
|
|
|
#endif
|
|
|
|
|
2010-09-12 16:35:25 +02:00
|
|
|
/* We are now initialized */
|
|
|
|
|
2010-09-11 03:58:26 +02:00
|
|
|
g_pgsrc.initialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2011-05-27 17:26:52 +02:00
|
|
|
# define lpc31_initsrc()
|
2010-09-11 03:58:26 +02:00
|
|
|
#endif
|
2010-09-09 00:06:38 +02:00
|
|
|
|
2010-08-17 21:28:51 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-09-09 00:06:38 +02:00
|
|
|
/****************************************************************************
|
2010-08-17 21:28:51 +02:00
|
|
|
* Name: up_fillpage()
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* After a page is allocated and mapped by up_allocpage(), the actual
|
|
|
|
* filling of the page with data from the non-volatile, must be performed
|
|
|
|
* by a separate call to the architecture-specific function, up_fillpage().
|
|
|
|
* This function is non-blocking, it will start an asynchronous page fill.
|
|
|
|
* The common paging logic will provide a callback function, pg_callback,
|
|
|
|
* that will be called when the page fill is finished (or an error occurs).
|
|
|
|
* This callback is assumed to occur from an interrupt level when the
|
|
|
|
* device driver completes the fill operation.
|
|
|
|
*
|
2010-09-02 01:52:38 +02:00
|
|
|
* NOTE 1: Allocating and filling a page is a two step process. up_allocpage()
|
2010-08-17 21:28:51 +02:00
|
|
|
* allocates the page, and up_fillpage() fills it with data from some non-
|
|
|
|
* volatile storage device. This distinction is made because up_allocpage()
|
|
|
|
* can probably be implemented in board-independent logic whereas up_fillpage()
|
|
|
|
* probably must be implemented as board-specific logic.
|
|
|
|
*
|
2010-09-02 01:52:38 +02:00
|
|
|
* NOTE 2: The initial mapping of vpage will be read-able, write-able,
|
|
|
|
* but non-cacheable. No special actions will be required of
|
|
|
|
* up_fillpage() in order to write into this allocated page. If the
|
|
|
|
* virtual address maps to a text region, however, this function should
|
|
|
|
* remap the region so that is is read/execute only. It should be made
|
|
|
|
* cache-able in any case.
|
|
|
|
|
2010-08-17 21:28:51 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* tcb - A reference to the task control block of the task that needs to
|
|
|
|
* have a page fill. Architecture-specific logic can retrieve page
|
|
|
|
* fault information from the architecture-specific context
|
|
|
|
* information in this TCB to perform the fill.
|
|
|
|
* pg_callbck - The function to be called when the page fill is complete.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* This function will return zero (OK) if the page fill was successfully
|
|
|
|
* started (the result of the page fill is passed to the callback function
|
|
|
|
* as the result argument). A negated errno value may be returned if an
|
|
|
|
* error occurs. All errors, however, are fatal.
|
|
|
|
*
|
|
|
|
* NOTE: -EBUSY has a special meaning. It is used internally to mean that
|
|
|
|
* the callback function has not executed. Therefore, -EBUSY should
|
|
|
|
* never be provided in the result argument of pg_callback.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* - This function is called from the normal tasking context (but
|
|
|
|
* interrupts siabled). The implementation must take whatever actions
|
|
|
|
* are necessary to assure that the operation is safe within this context.
|
|
|
|
* - Upon return, the caller will sleep waiting for the page fill callback
|
|
|
|
* to occur. The callback function will perform the wakeup.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_PAGING_BLOCKINGFILL
|
2010-09-08 19:38:44 +02:00
|
|
|
|
|
|
|
/* Version 1: Supports blocking fill operations */
|
|
|
|
|
2013-02-04 19:46:28 +01:00
|
|
|
int up_fillpage(FAR struct tcb_s *tcb, FAR void *vpage)
|
2010-08-17 21:28:51 +02:00
|
|
|
{
|
2010-09-11 03:58:26 +02:00
|
|
|
#if defined(CONFIG_PAGING_BINPATH)
|
2010-09-08 19:38:44 +02:00
|
|
|
ssize_t nbytes;
|
|
|
|
off_t offset;
|
|
|
|
off_t pos;
|
2010-09-12 04:22:13 +02:00
|
|
|
#elif defined(CONFIG_PAGING_M25PX) || defined(CONFIG_PAGING_AT45DB)
|
2010-09-11 03:58:26 +02:00
|
|
|
ssize_t nbytes;
|
|
|
|
off_t offset;
|
2010-09-08 19:38:44 +02:00
|
|
|
#endif
|
|
|
|
|
2010-09-12 16:35:25 +02:00
|
|
|
pglldbg("TCB: %p vpage: %p far: %08x\n", tcb, vpage, tcb->xcp.far);
|
2010-09-08 19:38:44 +02:00
|
|
|
DEBUGASSERT(tcb->xcp.far >= PG_PAGED_VBASE && tcb->xcp.far < PG_PAGED_VEND);
|
|
|
|
|
|
|
|
/* If BINPATH is defined, then it is the full path to a file on a mounted file
|
2010-09-09 00:06:38 +02:00
|
|
|
* system. In this case initialization will be deferred until the first
|
2010-09-08 19:38:44 +02:00
|
|
|
* time that up_fillpage() is called. Are we initialized?
|
|
|
|
*/
|
|
|
|
|
2010-09-11 03:58:26 +02:00
|
|
|
#if defined(CONFIG_PAGING_BINPATH)
|
2010-09-08 19:38:44 +02:00
|
|
|
|
2010-09-12 16:35:25 +02:00
|
|
|
/* Perform initialization of the paging source device (if necessary) */
|
2010-09-08 19:38:44 +02:00
|
|
|
|
2011-05-27 17:26:52 +02:00
|
|
|
lpc31_initsrc();
|
2010-09-08 19:38:44 +02:00
|
|
|
|
2014-04-14 00:22:22 +02:00
|
|
|
/* Create an offset into the binary image that corresponds to the
|
2010-09-08 19:38:44 +02:00
|
|
|
* virtual address. File offset 0 corresponds to PG_LOCKED_VBASE.
|
|
|
|
*/
|
|
|
|
|
2010-09-11 03:58:26 +02:00
|
|
|
offset = (off_t)tcb->xcp.far - PG_LOCKED_VBASE;
|
2010-09-08 19:38:44 +02:00
|
|
|
|
|
|
|
/* Seek to that position */
|
|
|
|
|
|
|
|
pos = lseek(g_pgsrc.fd, offset, SEEK_SET);
|
|
|
|
DEBUGASSERT(pos != (off_t)-1);
|
2014-04-14 00:22:22 +02:00
|
|
|
|
2010-09-08 19:38:44 +02:00
|
|
|
/* And read the page data from that offset */
|
|
|
|
|
|
|
|
nbytes = read(g_pgsrc.fd, vpage, PAGESIZE);
|
|
|
|
DEBUGASSERT(nbytes == PAGESIZE);
|
|
|
|
return OK;
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
#elif defined(CONFIG_PAGING_M25PX) || defined(CONFIG_PAGING_AT45DB) /* !CONFIG_PAGING_BINPATH */
|
2010-09-11 03:58:26 +02:00
|
|
|
|
2010-09-12 16:35:25 +02:00
|
|
|
/* Perform initialization of the paging source device (if necessary) */
|
2010-09-11 03:58:26 +02:00
|
|
|
|
2011-05-27 17:26:52 +02:00
|
|
|
lpc31_initsrc();
|
2010-09-11 03:58:26 +02:00
|
|
|
|
2014-04-14 00:22:22 +02:00
|
|
|
/* Create an offset into the binary image that corresponds to the
|
2010-09-11 03:58:26 +02:00
|
|
|
* virtual address. File offset 0 corresponds to PG_LOCKED_VBASE.
|
|
|
|
*/
|
|
|
|
|
2014-03-05 21:25:49 +01:00
|
|
|
offset = (off_t)tcb->xcp.far - PG_LOCKED_VBASE + CONFIG_EA3131_PAGING_BINOFFSET;
|
2010-09-11 03:58:26 +02:00
|
|
|
|
|
|
|
/* Read the page at the correct offset into the SPI FLASH device */
|
|
|
|
|
|
|
|
nbytes = MTD_READ(g_pgsrc.mtd, offset, PAGESIZE, (FAR uint8_t *)vpage);
|
|
|
|
DEBUGASSERT(nbytes == PAGESIZE);
|
|
|
|
return OK;
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
#else /* !CONFIG_PAGING_BINPATH && !CONFIG_PAGING_M25PX && !CONFIG_PAGING_AT45DB */
|
2010-09-08 19:38:44 +02:00
|
|
|
|
2010-08-17 21:28:51 +02:00
|
|
|
# warning "Not implemented"
|
|
|
|
return -ENOSYS;
|
2010-09-08 19:38:44 +02:00
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
#endif /* !CONFIG_PAGING_BINPATH && !CONFIG_PAGING_M25PX && !CONFIG_PAGING_AT45DB */
|
2010-08-17 21:28:51 +02:00
|
|
|
}
|
2010-09-08 19:38:44 +02:00
|
|
|
|
2010-09-11 03:58:26 +02:00
|
|
|
#else /* CONFIG_PAGING_BLOCKINGFILL */
|
2010-09-08 19:38:44 +02:00
|
|
|
|
|
|
|
/* Version 2: Supports non-blocking, asynchronous fill operations */
|
|
|
|
|
2013-02-04 19:46:28 +01:00
|
|
|
int up_fillpage(FAR struct tcb_s *tcb, FAR void *vpage, up_pgcallback_t pg_callback)
|
2010-08-17 21:28:51 +02:00
|
|
|
{
|
2010-09-12 16:35:25 +02:00
|
|
|
pglldbg("TCB: %p vpage: %d far: %08x\n", tcb, vpage, tcb->xcp.far);
|
2010-09-08 19:38:44 +02:00
|
|
|
DEBUGASSERT(tcb->xcp.far >= PG_PAGED_VBASE && tcb->xcp.far < PG_PAGED_VEND);
|
|
|
|
|
2010-09-11 03:58:26 +02:00
|
|
|
#if defined(CONFIG_PAGING_BINPATH)
|
2010-09-08 19:38:44 +02:00
|
|
|
# error "File system-based paging must always be implemented with blocking calls"
|
2010-09-12 04:22:13 +02:00
|
|
|
#elif defined(CONFIG_PAGING_M25PX) || defined(CONFIG_PAGING_AT45DB)
|
2010-09-11 03:58:26 +02:00
|
|
|
# error "SPI FLASH paging must always be implemented with blocking calls"
|
2010-09-08 19:38:44 +02:00
|
|
|
#else
|
|
|
|
# warning "Not implemented"
|
|
|
|
#endif
|
|
|
|
|
2010-08-17 21:28:51 +02:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2010-09-08 19:38:44 +02:00
|
|
|
|
|
|
|
#endif /* CONFIG_PAGING_BLOCKINGFILL */
|
2010-08-17 21:28:51 +02:00
|
|
|
|
2010-09-02 22:52:55 +02:00
|
|
|
/************************************************************************************
|
2011-05-27 17:26:52 +02:00
|
|
|
* Name: lpc31_pginitialize
|
2010-09-02 22:52:55 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set up mass storage device to support on demand paging.
|
|
|
|
*
|
|
|
|
************************************************************************************/
|
|
|
|
|
2011-05-27 17:26:52 +02:00
|
|
|
void weak_function lpc31_pginitialize(void)
|
2010-09-02 22:52:55 +02:00
|
|
|
{
|
|
|
|
/* This initialization does nothing in this example setup. But this function is
|
|
|
|
* where you might, for example:
|
|
|
|
*
|
|
|
|
* - Initialize and configure a mass storage device to support on-demand paging.
|
|
|
|
* This might be, perhaps an SD card or NAND memory. An SPI FLASH would probably
|
2016-01-26 23:56:13 +01:00
|
|
|
* already have been configured by lpc31_spidev_intialize(void);
|
2010-09-02 22:52:55 +02:00
|
|
|
* - Set up resources to support up_fillpage() operation. For example, perhaps the
|
|
|
|
* the text image is stored in a named binary file. In this case, the virtual
|
|
|
|
* text addresses might map to offsets into that file.
|
|
|
|
* - Do whatever else is necessary to make up_fillpage() ready for the first time
|
|
|
|
* that it is called.
|
2010-09-11 03:58:26 +02:00
|
|
|
*
|
2010-09-12 16:35:25 +02:00
|
|
|
* In reality, however, this function is not very useful: This function is called
|
|
|
|
* from a low level (before os_start() is even called), it may not be possible to
|
|
|
|
* perform file system operations or even to get debug output yet. Therefore,
|
|
|
|
* to keep life simple, initialization will be deferred in all cases until the first
|
|
|
|
* time that up_fillpage() is called.
|
2010-09-11 03:58:26 +02:00
|
|
|
*/
|
2010-09-02 22:52:55 +02:00
|
|
|
}
|
|
|
|
|
2010-08-17 21:28:51 +02:00
|
|
|
#endif /* CONFIG_PAGING */
|