1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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 * $FreeBSD$ 36 */ 37 38#ifndef _BHND_CORES_CHIPC_CHIPC_PRIVATE_H_ 39#define _BHND_CORES_CHIPC_CHIPC_PRIVATE_H_ 40 41#include <sys/param.h> 42#include <sys/kernel.h> 43#include <sys/bus.h> 44#include <sys/rman.h> 45 46#include <machine/bus.h> 47#include <machine/resource.h> 48 49#include <dev/bhnd/bhnd.h> 50#include <dev/bhnd/bhndvar.h> 51 52/* 53 * Private bhnd_chipc(4) driver definitions. 54 */ 55 56struct chipc_caps; 57struct chipc_region; 58struct chipc_softc; 59 60int chipc_init_child_resource(struct resource *r, 61 struct resource *parent, 62 bhnd_size_t offset, bhnd_size_t size); 63 64int chipc_set_irq_resource(struct chipc_softc *sc, 65 device_t child, int rid, u_int intr); 66int chipc_set_mem_resource(struct chipc_softc *sc, 67 device_t child, int rid, rman_res_t start, 68 rman_res_t count, u_int port, u_int region); 69 70struct chipc_region *chipc_alloc_region(struct chipc_softc *sc, 71 bhnd_port_type type, u_int port, 72 u_int region); 73void chipc_free_region(struct chipc_softc *sc, 74 struct chipc_region *cr); 75struct chipc_region *chipc_find_region(struct chipc_softc *sc, 76 rman_res_t start, rman_res_t end); 77struct chipc_region *chipc_find_region_by_rid(struct chipc_softc *sc, 78 int rid); 79 80int chipc_retain_region(struct chipc_softc *sc, 81 struct chipc_region *cr, int flags); 82int chipc_release_region(struct chipc_softc *sc, 83 struct chipc_region *cr, int flags); 84 85void chipc_print_caps(device_t dev, 86 struct chipc_caps *caps); 87 88/** 89 * chipc SYS_RES_MEMORY region allocation record. 90 */ 91struct chipc_region { 92 bhnd_port_type cr_port_type; /**< bhnd port type */ 93 u_int cr_port_num; /**< bhnd port number */ 94 u_int cr_region_num; /**< bhnd region number */ 95 96 bhnd_addr_t cr_addr; /**< region base address */ 97 bhnd_addr_t cr_end; /**< region end address */ 98 bhnd_size_t cr_count; /**< region count */ 99 int cr_rid; /**< rid to use when performing 100 resource allocation, or -1 101 if region has no assigned 102 resource ID */ 103 104 struct bhnd_resource *cr_res; /**< bus resource, or NULL */ 105 int cr_res_rid; /**< cr_res RID, if any. */ 106 u_int cr_refs; /**< RF_ALLOCATED refcount */ 107 u_int cr_act_refs; /**< RF_ACTIVE refcount */ 108 109 STAILQ_ENTRY(chipc_region) cr_link; 110}; 111 112#endif /* _BHND_CORES_CHIPC_CHIPC_PRIVATE_H_ */ 113