1 /* $NetBSD: elb.c,v 1.6 2008/04/28 20:23:17 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Juergen Hannken-Illjes. 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/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: elb.c,v 1.6 2008/04/28 20:23:17 martin Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/conf.h> 37 #include <sys/device.h> 38 #include <sys/systm.h> 39 #include <sys/extent.h> 40 41 #include <machine/explora.h> 42 #define _POWERPC_BUS_DMA_PRIVATE 43 #include <machine/bus.h> 44 45 #include <powerpc/ibm4xx/dcr403cgx.h> 46 47 #include <evbppc/explora/dev/elbvar.h> 48 49 struct elb_dev { 50 const char *elb_name; 51 int elb_addr; 52 int elb_addr2; 53 int elb_irq; 54 bus_space_tag_t elb_bt; 55 }; 56 57 static int elb_match(struct device *, struct cfdata *, void *); 58 static void elb_attach(struct device *, struct device *, void *); 59 static int elb_print(void *, const char *); 60 61 static struct powerpc_bus_space elb_tag = { 62 _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE | 1, /* stride 1 */ 63 0x00000000, 64 BASE_PCKBC, 65 BASE_PCKBC + 0x6ff 66 }; 67 static char elb_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)] 68 __attribute__((aligned(8))); 69 static int elb_tag_init_done; 70 71 static struct powerpc_bus_space elb_fb_tag = { 72 _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE, 73 0x00000000, 74 BASE_FB, 75 BASE_FB2 + SIZE_FB - 1 76 }; 77 static char elbfb_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)] 78 __attribute__((aligned(8))); 79 static int elbfb_tag_init_done; 80 81 /* 82 * DMA struct, nothing special. 83 */ 84 static struct powerpc_bus_dma_tag elb_bus_dma_tag = { 85 0, /* _bounce_thresh */ 86 _bus_dmamap_create, 87 _bus_dmamap_destroy, 88 _bus_dmamap_load, 89 _bus_dmamap_load_mbuf, 90 _bus_dmamap_load_uio, 91 _bus_dmamap_load_raw, 92 _bus_dmamap_unload, 93 _bus_dmamap_sync, 94 _bus_dmamem_alloc, 95 _bus_dmamem_free, 96 _bus_dmamem_map, 97 _bus_dmamem_unmap, 98 _bus_dmamem_mmap, 99 _bus_dma_phys_to_bus_mem_generic, 100 _bus_dma_bus_mem_to_phys_generic, 101 }; 102 103 static struct elb_dev elb_devs[] = { 104 { "cpu", 0, 0, -1, NULL }, 105 { "pckbc", BASE_PCKBC, BASE_PCKBC2, 31, &elb_tag }, 106 { "com", BASE_COM, 0, 30, &elb_tag }, 107 { "lpt", BASE_LPT, 0, -1, &elb_tag }, 108 { "fb", BASE_FB, BASE_FB2, -1, &elb_fb_tag }, 109 { "le", BASE_LE, 0, 28, &elb_fb_tag }, 110 }; 111 112 CFATTACH_DECL(elb, sizeof(struct device), 113 elb_match, elb_attach, NULL, NULL); 114 115 /* 116 * Probe for the elb; always succeeds. 117 */ 118 static int 119 elb_match(struct device *parent, struct cfdata *cf, void *aux) 120 { 121 return (1); 122 } 123 124 /* 125 * Attach the Explora local bus. 126 */ 127 static void 128 elb_attach(struct device *parent, struct device *self, void *aux) 129 { 130 struct elb_attach_args eaa; 131 int i; 132 133 printf("\n"); 134 for (i = 0; i < sizeof(elb_devs)/sizeof(elb_devs[0]); i++) { 135 eaa.elb_name = elb_devs[i].elb_name; 136 eaa.elb_bt = elb_get_bus_space_tag(elb_devs[i].elb_addr); 137 eaa.elb_dmat = &elb_bus_dma_tag; 138 eaa.elb_base = elb_devs[i].elb_addr; 139 eaa.elb_base2 = elb_devs[i].elb_addr2; 140 eaa.elb_irq = elb_devs[i].elb_irq; 141 142 (void) config_found(self, &eaa, elb_print); 143 } 144 } 145 146 static int 147 elb_print(void *aux, const char *pnp) 148 { 149 struct elb_attach_args *eaa = aux; 150 151 if (pnp) 152 aprint_normal("%s at %s", eaa->elb_name, pnp); 153 if (eaa->elb_irq != -1) 154 aprint_normal(" irq %d", eaa->elb_irq); 155 156 return (UNCONF); 157 } 158 159 bus_space_tag_t 160 elb_get_bus_space_tag(bus_addr_t addr) 161 { 162 163 if ((addr & 0xff000000) == 0x74000000) { 164 if (!elb_tag_init_done) { 165 if (bus_space_init(&elb_tag, "elbtag", 166 elb_ex_storage, sizeof(elb_ex_storage))) 167 panic("elb_get_bus_space_tag: elb_tag"); 168 169 elb_tag_init_done = 1; 170 } 171 return (&elb_tag); 172 } else { 173 if (!elbfb_tag_init_done) { 174 if (bus_space_init(&elb_fb_tag, "elbfbtag", 175 elbfb_ex_storage, sizeof(elbfb_ex_storage))) 176 panic("elb_get_bus_space_tag: elb_fb_tag"); 177 178 elbfb_tag_init_done = 1; 179 } 180 return (&elb_fb_tag); 181 } 182 } 183