1 /* $NetBSD: pvbus.c,v 1.2 2025/01/14 08:03:40 riastradh Exp $ */ 2 3 /*- 4 * Copyright (c) 2024 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Emile 'iMil' Heitor. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * 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 IN 27 * 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 THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/param.h> 33 34 #include <sys/bus.h> 35 #include <sys/cdefs.h> 36 #include <sys/device.h> 37 #include <sys/kernel.h> 38 #include <sys/systm.h> 39 40 #include <machine/bus_private.h> 41 42 #include <arch/x86/pv/pvvar.h> 43 44 static int _pv_dma_may_bounce(bus_dma_tag_t, bus_dmamap_t, int, int *); 45 static int pv_match(device_t, cfdata_t, void *); 46 static void pv_attach(device_t, device_t, void *); 47 static int pv_submatch(device_t, cfdata_t, const int *, void *); 48 49 struct x86_bus_dma_tag pvbus_bus_dma_tag = { 50 ._tag_needs_free = 0, 51 ._bounce_thresh = 0, 52 ._bounce_alloc_lo = 0, 53 ._bounce_alloc_hi = 0, 54 ._may_bounce = _pv_dma_may_bounce, 55 }; 56 57 CFATTACH_DECL_NEW(pv, sizeof(struct pv_softc), 58 pv_match, pv_attach, NULL, NULL); 59 60 static int 61 _pv_dma_may_bounce(bus_dma_tag_t t, bus_dmamap_t map, int flags, 62 int *cookieflagsp) 63 { 64 65 if ((map->_dm_size / PAGE_SIZE) > map->_dm_segcnt) 66 *cookieflagsp |= X86_DMA_MIGHT_NEED_BOUNCE; 67 68 return 0; 69 } 70 71 static int 72 pv_match(device_t parent, cfdata_t match, void *aux) 73 { 74 75 return 1; 76 } 77 78 static void 79 pv_attach(device_t parent, device_t self, void *aux) 80 { 81 struct pv_attach_args pvaa; 82 83 pvaa.pvaa_memt = x86_bus_space_mem; 84 pvaa.pvaa_dmat = &pvbus_bus_dma_tag; 85 86 aprint_naive("\n"); 87 aprint_normal("\n"); 88 89 config_found(self, &pvaa, NULL, CFARGS(.search = pv_submatch)); 90 } 91 92 static int 93 pv_submatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux) 94 { 95 struct pv_attach_args *pvaa = aux; 96 97 if (config_probe(parent, cf, pvaa)) { 98 config_attach(parent, cf, pvaa, NULL, CFARGS_NONE); 99 return 0; 100 } 101 return 0; 102 } 103