htif.h revision 295041
1295041Sbr/*- 2295041Sbr * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com> 3295041Sbr * All rights reserved. 4295041Sbr * 5295041Sbr * Portions of this software were developed by SRI International and the 6295041Sbr * University of Cambridge Computer Laboratory under DARPA/AFRL contract 7295041Sbr * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. 8295041Sbr * 9295041Sbr * Portions of this software were developed by the University of Cambridge 10295041Sbr * Computer Laboratory as part of the CTSRD Project, with support from the 11295041Sbr * UK Higher Education Innovation Fund (HEIF). 12295041Sbr * 13295041Sbr * Redistribution and use in source and binary forms, with or without 14295041Sbr * modification, are permitted provided that the following conditions 15295041Sbr * are met: 16295041Sbr * 1. Redistributions of source code must retain the above copyright 17295041Sbr * notice, this list of conditions and the following disclaimer. 18295041Sbr * 2. Redistributions in binary form must reproduce the above copyright 19295041Sbr * notice, this list of conditions and the following disclaimer in the 20295041Sbr * documentation and/or other materials provided with the distribution. 21295041Sbr * 22295041Sbr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23295041Sbr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24295041Sbr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25295041Sbr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26295041Sbr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27295041Sbr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28295041Sbr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29295041Sbr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30295041Sbr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31295041Sbr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32295041Sbr * SUCH DAMAGE. 33295041Sbr * 34295041Sbr * $FreeBSD: head/sys/riscv/htif/htif.h 295041 2016-01-29 15:12:31Z br $ 35295041Sbr */ 36295041Sbr 37295041Sbr#define HTIF_DEV_ID_SHIFT (56) 38295041Sbr#define HTIF_DEV_ID_MASK (0xfful << HTIF_DEV_ID_SHIFT) 39295041Sbr#define HTIF_CMD_SHIFT (48) 40295041Sbr#define HTIF_CMD_MASK (0xfful << HTIF_CMD_SHIFT) 41295041Sbr#define HTIF_DATA_SHIFT (0) 42295041Sbr#define HTIF_DATA_MASK (0xffffffff << HTIF_DATA_SHIFT) 43295041Sbr 44295041Sbr#define HTIF_CMD_READ (0x00ul) 45295041Sbr#define HTIF_CMD_WRITE (0x01ul) 46295041Sbr#define HTIF_CMD_READ_CONTROL_REG (0x02ul) 47295041Sbr#define HTIF_CMD_WRITE_CONTROL_REG (0x03ul) 48295041Sbr#define HTIF_CMD_IDENTIFY (0xfful) 49295041Sbr#define IDENTIFY_PADDR_SHIFT 8 50295041Sbr#define IDENTIFY_IDENT 0xff 51295041Sbr 52295041Sbr#define HTIF_NDEV (256) 53295041Sbr#define HTIF_ID_LEN (64) 54295041Sbr#define HTIF_ALIGN (64) 55295041Sbr 56295041Sbr#define HTIF_DEV_CMD(entry) ((entry & HTIF_CMD_MASK) >> HTIF_CMD_SHIFT) 57295041Sbr#define HTIF_DEV_ID(entry) ((entry & HTIF_DEV_ID_MASK) >> HTIF_DEV_ID_SHIFT) 58295041Sbr#define HTIF_DEV_DATA(entry) ((entry & HTIF_DATA_MASK) >> HTIF_DATA_SHIFT) 59295041Sbr 60295041Sbr/* bus softc */ 61295041Sbrstruct htif_softc { 62295041Sbr struct resource *res[1]; 63295041Sbr void *ihl[1]; 64295041Sbr device_t dev; 65295041Sbr uint64_t identify_id; 66295041Sbr uint64_t identify_done; 67295041Sbr}; 68295041Sbr 69295041Sbr/* device private data */ 70295041Sbrstruct htif_dev_ivars { 71295041Sbr char *id; 72295041Sbr int index; 73295041Sbr device_t dev; 74295041Sbr struct htif_softc *sc; 75295041Sbr}; 76295041Sbr 77295041Sbruint64_t htif_command(uint64_t); 78295041Sbrint htif_setup_intr(int id, void *func, void *arg); 79295041Sbrint htif_read_ivar(device_t dev, device_t child, int which, uintptr_t *result); 80295041Sbr 81295041Sbrenum htif_device_ivars { 82295041Sbr HTIF_IVAR_INDEX, 83295041Sbr HTIF_IVAR_ID, 84295041Sbr}; 85295041Sbr 86295041Sbr/* 87295041Sbr * Simplified accessors for HTIF devices 88295041Sbr */ 89295041Sbr#define HTIF_ACCESSOR(var, ivar, type) \ 90295041Sbr __BUS_ACCESSOR(htif, var, HTIF, ivar, type) 91295041Sbr 92295041SbrHTIF_ACCESSOR(index, INDEX, int); 93295041SbrHTIF_ACCESSOR(id, ID, char *); 94