1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org> 5 * Copyright (c) 2017 The FreeBSD Foundation 6 * All rights reserved. 7 * 8 * Portions of this software were developed by Landon Fuller 9 * under sponsorship from the FreeBSD Foundation. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 19 * redistribution must be conditioned upon including a substantially 20 * similar Disclaimer requirement for further binary redistribution. 21 * 22 * NO WARRANTY 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 26 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 27 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 28 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 31 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 * THE POSSIBILITY OF SUCH DAMAGES. 34 * 35 */ 36 37 #ifndef _BHND_CORES_CHIPC_CHIPC_PRIVATE_H_ 38 #define _BHND_CORES_CHIPC_CHIPC_PRIVATE_H_ 39 40 #include <sys/param.h> 41 #include <sys/kernel.h> 42 #include <sys/bus.h> 43 #include <sys/rman.h> 44 45 #include <machine/bus.h> 46 #include <machine/resource.h> 47 48 #include <dev/bhnd/bhnd.h> 49 #include <dev/bhnd/bhndvar.h> 50 51 /* 52 * Private bhnd_chipc(4) driver definitions. 53 */ 54 55 struct chipc_caps; 56 struct chipc_region; 57 struct chipc_softc; 58 59 int chipc_init_child_resource(struct resource *r, 60 struct resource *parent, 61 bhnd_size_t offset, bhnd_size_t size); 62 63 int chipc_set_irq_resource(struct chipc_softc *sc, 64 device_t child, int rid, u_int intr); 65 int chipc_set_mem_resource(struct chipc_softc *sc, 66 device_t child, int rid, rman_res_t start, 67 rman_res_t count, u_int port, u_int region); 68 69 struct chipc_region *chipc_alloc_region(struct chipc_softc *sc, 70 bhnd_port_type type, u_int port, 71 u_int region); 72 void chipc_free_region(struct chipc_softc *sc, 73 struct chipc_region *cr); 74 struct chipc_region *chipc_find_region(struct chipc_softc *sc, 75 rman_res_t start, rman_res_t end); 76 struct chipc_region *chipc_find_region_by_rid(struct chipc_softc *sc, 77 int rid); 78 79 int chipc_retain_region(struct chipc_softc *sc, 80 struct chipc_region *cr, int flags); 81 int chipc_release_region(struct chipc_softc *sc, 82 struct chipc_region *cr, int flags); 83 84 void chipc_print_caps(device_t dev, 85 struct chipc_caps *caps); 86 87 /** 88 * chipc SYS_RES_MEMORY region allocation record. 89 */ 90 struct chipc_region { 91 bhnd_port_type cr_port_type; /**< bhnd port type */ 92 u_int cr_port_num; /**< bhnd port number */ 93 u_int cr_region_num; /**< bhnd region number */ 94 95 bhnd_addr_t cr_addr; /**< region base address */ 96 bhnd_addr_t cr_end; /**< region end address */ 97 bhnd_size_t cr_count; /**< region count */ 98 int cr_rid; /**< rid to use when performing 99 resource allocation, or -1 100 if region has no assigned 101 resource ID */ 102 103 struct bhnd_resource *cr_res; /**< bus resource, or NULL */ 104 int cr_res_rid; /**< cr_res RID, if any. */ 105 u_int cr_refs; /**< RF_ALLOCATED refcount */ 106 u_int cr_act_refs; /**< RF_ACTIVE refcount */ 107 108 STAILQ_ENTRY(chipc_region) cr_link; 109 }; 110 111 #endif /* _BHND_CORES_CHIPC_CHIPC_PRIVATE_H_ */ 112