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