1262197Srwatson/*-
2262197Srwatson * Copyright (c) 2013 Robert N. M. Watson
3262197Srwatson * All rights reserved.
4262197Srwatson *
5262197Srwatson * This software was developed by SRI International and the University of
6262197Srwatson * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7262197Srwatson * ("CTSRD"), as part of the DARPA CRASH research programme.
8262197Srwatson *
9262197Srwatson * Redistribution and use in source and binary forms, with or without
10262197Srwatson * modification, are permitted provided that the following conditions
11262197Srwatson * are met:
12262197Srwatson * 1. Redistributions of source code must retain the above copyright
13262197Srwatson *    notice, this list of conditions and the following disclaimer.
14262197Srwatson * 2. Redistributions in binary form must reproduce the above copyright
15262197Srwatson *    notice, this list of conditions and the following disclaimer in the
16262197Srwatson *    documentation and/or other materials provided with the distribution.
17262197Srwatson *
18262197Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19262197Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20262197Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21262197Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22262197Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23262197Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24262197Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25262197Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26262197Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27262197Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28262197Srwatson * SUCH DAMAGE.
29262197Srwatson *
30262197Srwatson * $FreeBSD: stable/11/stand/mips/beri/common/cfi.c 329175 2018-02-12 17:44:35Z kevans $
31262197Srwatson */
32262197Srwatson
33329175Skevans#include "stand.h"
34262197Srwatson#include "mips.h"
35262197Srwatson#include "cfi.h"
36262197Srwatson
37262197Srwatson/*
38262197Srwatson * Memory-mapped Intel StrataFlash mini-driver.  Very mini.  Nothing fancy --
39262197Srwatson * and few seatbelts.
40262197Srwatson *
41262197Srwatson * XXXRW: Should we be making some effort to reset isf to a known-good state
42262197Srwatson * before starting, in case there was a soft reset mid-transaction.
43262197Srwatson *
44262197Srwatson * XXXRW: Would be nice to support multiple devices and also handle SD cards
45262197Srwatson * here ... and probably not too hard.
46262197Srwatson */
47262197Srwatsonextern void	*__cheri_flash_bootfs_vaddr__;
48262197Srwatsonextern void	*__cheri_flash_bootfs_len__;
49262197Srwatson
50262197Srwatson#define	CHERI_BOOTFS_BASE	((uintptr_t)&__cheri_flash_bootfs_vaddr__)
51262197Srwatson#define	CHERI_BOOTFS_LENGTH	((uintptr_t)&__cheri_flash_bootfs_len__)
52262197Srwatson
53262197Srwatsonint
54262197Srwatsoncfi_read(void *buf, unsigned lba, unsigned nblk)
55262197Srwatson{
56262197Srwatson
57262197Srwatson	if ((lba << 9) + (nblk << 9) > CHERI_BOOTFS_LENGTH)
58262197Srwatson		return (-1);
59262197Srwatson	memcpy(buf, (void *)(CHERI_BOOTFS_BASE + (lba << 9)), nblk << 9);
60262197Srwatson	return (0);
61262197Srwatson}
62262197Srwatson
63262197Srwatsonuint64_t
64262197Srwatsoncfi_get_mediasize(void)
65262197Srwatson{
66262197Srwatson
67262197Srwatson	return (CHERI_BOOTFS_LENGTH);
68262197Srwatson}
69262197Srwatson
70262197Srwatsonuint64_t
71262197Srwatsoncfi_get_sectorsize(void)
72262197Srwatson{
73262197Srwatson
74262197Srwatson	return (512);	/* Always a good sector size. */
75262197Srwatson}
76