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