xref: /freebsd/sys/dev/bhnd/bhnd_eromvar.h (revision 8eb2bee6c0f4957c6c1cea826e59cda4d18a2a64)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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  * $FreeBSD$
33  */
34 
35 #ifndef _BHND_EROM_BHND_EROMVAR_H_
36 #define _BHND_EROM_BHND_EROMVAR_H_
37 
38 #include <sys/param.h>
39 
40 #include "bhnd_erom.h"
41 
42 /* forward declarations */
43 struct bhnd_erom_io;
44 struct bhnd_erom_iobus;
45 
46 /** @see bhnd_erom_io_map() */
47 typedef int		(bhnd_erom_io_map_t)(struct bhnd_erom_io *eio,
48 			     bhnd_addr_t addr, bhnd_size_t size);
49 
50 /** @see bhnd_erom_io_tell() */
51 typedef int		(bhnd_erom_io_tell_t)(struct bhnd_erom_io *eio,
52 			     bhnd_addr_t *addr, bhnd_size_t *size);
53 
54 /** @see bhnd_erom_io_read() */
55 typedef uint32_t	(bhnd_erom_io_read_t)(struct bhnd_erom_io *eio,
56 			     bhnd_size_t offset, u_int width);
57 
58 /** @see bhnd_erom_io_fini() */
59 typedef void		(bhnd_erom_io_fini_t)(struct bhnd_erom_io *eio);
60 
61 int			 bhnd_erom_read_chipid(struct bhnd_erom_io *eio,
62 			     struct bhnd_chipid *cid);
63 
64 /**
65  * Abstract EROM bus I/O support.
66  */
67 struct bhnd_erom_io {
68 	bhnd_erom_io_map_t	*map;	/**< @see bhnd_erom_io_map() */
69 	bhnd_erom_io_tell_t	*tell;	/**< @see bhnd_erom_io_tell() */
70 	bhnd_erom_io_read_t	*read;	/**< @see bhnd_erom_io_read() */
71 	bhnd_erom_io_fini_t	*fini;	/**< @see bhnd_erom_io_fini(). May be NULL */
72 };
73 
74 /**
75  * EROM bus handle/tag I/O instance state.
76  */
77 struct bhnd_erom_iobus {
78 	struct bhnd_erom_io	eio;
79 	bhnd_addr_t		addr;	/**< the address of @p bsh */
80 	bhnd_size_t		size;	/**< the size of @p bsh */
81 	bus_space_tag_t		bst;	/**< bus space tag */
82 	bus_space_handle_t	bsh;	/**< bus space handle mapping the full enumeration space */
83 	bool			mapped;	/**< if a mapping is active */
84 	bus_size_t		offset;	/**< the current mapped offset within bsh */
85 	bus_size_t		limit;	/**< the current mapped size relative to offset */
86 };
87 
88 #endif /* _BHND_EROM_BHND_EROMVAR_H_ */
89