1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2017 The FreeBSD Foundation 5 * All rights reserved. 6 * 7 * This software was developed by Landon Fuller under sponsorship from 8 * the FreeBSD Foundation. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer, 15 * without modification. 16 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 17 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 18 * redistribution must be conditioned upon including a substantially 19 * similar Disclaimer requirement for further binary redistribution. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 24 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 25 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 26 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * THE POSSIBILITY OF SUCH DAMAGES. 32 * 33 * $FreeBSD$ 34 */ 35 36 #ifndef _BHND_EROM_BHND_EROMVAR_H_ 37 #define _BHND_EROM_BHND_EROMVAR_H_ 38 39 #include <sys/param.h> 40 41 #include "bhnd_erom.h" 42 43 /* forward declarations */ 44 struct bhnd_erom_io; 45 struct bhnd_erom_iobus; 46 47 /** @see bhnd_erom_io_map() */ 48 typedef int (bhnd_erom_io_map_t)(struct bhnd_erom_io *eio, 49 bhnd_addr_t addr, bhnd_size_t size); 50 51 /** @see bhnd_erom_io_tell() */ 52 typedef int (bhnd_erom_io_tell_t)(struct bhnd_erom_io *eio, 53 bhnd_addr_t *addr, bhnd_size_t *size); 54 55 /** @see bhnd_erom_io_read() */ 56 typedef uint32_t (bhnd_erom_io_read_t)(struct bhnd_erom_io *eio, 57 bhnd_size_t offset, u_int width); 58 59 /** @see bhnd_erom_io_fini() */ 60 typedef void (bhnd_erom_io_fini_t)(struct bhnd_erom_io *eio); 61 62 63 int bhnd_erom_read_chipid(struct bhnd_erom_io *eio, 64 struct bhnd_chipid *cid); 65 66 67 /** 68 * Abstract EROM bus I/O support. 69 */ 70 struct bhnd_erom_io { 71 bhnd_erom_io_map_t *map; /**< @see bhnd_erom_io_map() */ 72 bhnd_erom_io_tell_t *tell; /**< @see bhnd_erom_io_tell() */ 73 bhnd_erom_io_read_t *read; /**< @see bhnd_erom_io_read() */ 74 bhnd_erom_io_fini_t *fini; /**< @see bhnd_erom_io_fini(). May be NULL */ 75 }; 76 77 /** 78 * EROM bus handle/tag I/O instance state. 79 */ 80 struct bhnd_erom_iobus { 81 struct bhnd_erom_io eio; 82 bhnd_addr_t addr; /**< the address of @p bsh */ 83 bhnd_size_t size; /**< the size of @p bsh */ 84 bus_space_tag_t bst; /**< bus space tag */ 85 bus_space_handle_t bsh; /**< bus space handle mapping the full enumeration space */ 86 bool mapped; /**< if a mapping is active */ 87 bus_size_t offset; /**< the current mapped offset within bsh */ 88 bus_size_t limit; /**< the current mapped size relative to offset */ 89 }; 90 91 #endif /* _BHND_EROM_BHND_EROMVAR_H_ */ 92