1*60f78cd0Smickey /* $OpenBSD: i82365var.h,v 1.14 2005/11/23 11:39:37 mickey Exp $ */ 28088a9f7Sfgsch /* $NetBSD: i82365var.h,v 1.4 1998/05/23 18:32:29 matt Exp $ */ 38088a9f7Sfgsch 48088a9f7Sfgsch /* 58088a9f7Sfgsch * Copyright (c) 1997 Marc Horowitz. All rights reserved. 68088a9f7Sfgsch * 78088a9f7Sfgsch * Redistribution and use in source and binary forms, with or without 88088a9f7Sfgsch * modification, are permitted provided that the following conditions 98088a9f7Sfgsch * are met: 108088a9f7Sfgsch * 1. Redistributions of source code must retain the above copyright 118088a9f7Sfgsch * notice, this list of conditions and the following disclaimer. 128088a9f7Sfgsch * 2. Redistributions in binary form must reproduce the above copyright 138088a9f7Sfgsch * notice, this list of conditions and the following disclaimer in the 148088a9f7Sfgsch * documentation and/or other materials provided with the distribution. 158088a9f7Sfgsch * 3. All advertising materials mentioning features or use of this software 168088a9f7Sfgsch * must display the following acknowledgement: 178088a9f7Sfgsch * This product includes software developed by Marc Horowitz. 188088a9f7Sfgsch * 4. The name of the author may not be used to endorse or promote products 198088a9f7Sfgsch * derived from this software without specific prior written permission. 208088a9f7Sfgsch * 218088a9f7Sfgsch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 228088a9f7Sfgsch * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 238088a9f7Sfgsch * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 248088a9f7Sfgsch * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 258088a9f7Sfgsch * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 268088a9f7Sfgsch * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 278088a9f7Sfgsch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 288088a9f7Sfgsch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 298088a9f7Sfgsch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 308088a9f7Sfgsch * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 318088a9f7Sfgsch */ 328088a9f7Sfgsch 338088a9f7Sfgsch #include <sys/device.h> 34d4766543Saaron #include <sys/timeout.h> 358088a9f7Sfgsch 368088a9f7Sfgsch #include <dev/pcmcia/pcmciareg.h> 378088a9f7Sfgsch #include <dev/pcmcia/pcmciachip.h> 388088a9f7Sfgsch 398088a9f7Sfgsch #include <dev/ic/i82365reg.h> 408088a9f7Sfgsch 413c38068dSniklas struct proc; 423c38068dSniklas 433c38068dSniklas struct pcic_event { 443c38068dSniklas SIMPLEQ_ENTRY(pcic_event) pe_q; 453c38068dSniklas int pe_type; 463c38068dSniklas }; 473c38068dSniklas 483c38068dSniklas /* pe_type */ 493c38068dSniklas #define PCIC_EVENT_INSERTION 0 503c38068dSniklas #define PCIC_EVENT_REMOVAL 1 513c38068dSniklas 528088a9f7Sfgsch struct pcic_handle { 53e77beeccSaaron struct device *ph_parent; 54e77beeccSaaron bus_space_tag_t ph_bus_t; 55e77beeccSaaron bus_space_handle_t ph_bus_h; 56c4071fd1Smillert u_int8_t (*ph_read)(struct pcic_handle *, int); 57c4071fd1Smillert void (*ph_write)(struct pcic_handle *, int, int); 58e77beeccSaaron 598088a9f7Sfgsch int vendor; 608088a9f7Sfgsch int sock; 618088a9f7Sfgsch int flags; 623c38068dSniklas int laststate; 638088a9f7Sfgsch int memalloc; 648088a9f7Sfgsch struct { 658088a9f7Sfgsch bus_addr_t addr; 668088a9f7Sfgsch bus_size_t size; 678088a9f7Sfgsch long offset; 688088a9f7Sfgsch int kind; 698088a9f7Sfgsch } mem[PCIC_MEM_WINS]; 708088a9f7Sfgsch int ioalloc; 718088a9f7Sfgsch struct { 728088a9f7Sfgsch bus_addr_t addr; 738088a9f7Sfgsch bus_size_t size; 748088a9f7Sfgsch int width; 758088a9f7Sfgsch } io[PCIC_IO_WINS]; 768088a9f7Sfgsch int ih_irq; 778088a9f7Sfgsch struct device *pcmcia; 783c38068dSniklas 793c38068dSniklas int shutdown; 803c38068dSniklas struct proc *event_thread; 813c38068dSniklas SIMPLEQ_HEAD(, pcic_event) events; 828088a9f7Sfgsch }; 838088a9f7Sfgsch 848088a9f7Sfgsch #define PCIC_FLAG_SOCKETP 0x0001 858088a9f7Sfgsch #define PCIC_FLAG_CARDP 0x0002 868088a9f7Sfgsch 873c38068dSniklas #define PCIC_LASTSTATE_PRESENT 0x0002 883c38068dSniklas #define PCIC_LASTSTATE_HALF 0x0001 893c38068dSniklas #define PCIC_LASTSTATE_EMPTY 0x0000 903c38068dSniklas 918088a9f7Sfgsch #define C0SA PCIC_CHIP0_BASE+PCIC_SOCKETA_INDEX 928088a9f7Sfgsch #define C0SB PCIC_CHIP0_BASE+PCIC_SOCKETB_INDEX 938088a9f7Sfgsch #define C1SA PCIC_CHIP1_BASE+PCIC_SOCKETA_INDEX 948088a9f7Sfgsch #define C1SB PCIC_CHIP1_BASE+PCIC_SOCKETB_INDEX 958088a9f7Sfgsch 968088a9f7Sfgsch /* 978088a9f7Sfgsch * This is sort of arbitrary. It merely needs to be "enough". It can be 988088a9f7Sfgsch * overridden in the conf file, anyway. 998088a9f7Sfgsch */ 1008088a9f7Sfgsch 1018088a9f7Sfgsch #define PCIC_MEM_PAGES 4 1028088a9f7Sfgsch #define PCIC_MEMSIZE PCIC_MEM_PAGES*PCIC_MEM_PAGESIZE 1038088a9f7Sfgsch 1048088a9f7Sfgsch #define PCIC_NSLOTS 4 1058088a9f7Sfgsch 106957c80edSderaadt struct pcic_ranges { 107957c80edSderaadt u_short start; 108957c80edSderaadt u_short len; 109957c80edSderaadt }; 110957c80edSderaadt 1118088a9f7Sfgsch struct pcic_softc { 1128088a9f7Sfgsch struct device dev; 1138088a9f7Sfgsch 1148088a9f7Sfgsch bus_space_tag_t memt; 1158088a9f7Sfgsch bus_space_handle_t memh; 1168088a9f7Sfgsch bus_space_tag_t iot; 1178088a9f7Sfgsch bus_space_handle_t ioh; 1188088a9f7Sfgsch 1198088a9f7Sfgsch /* XXX isa_chipset_tag_t, pci_chipset_tag_t, etc. */ 1208088a9f7Sfgsch void *intr_est; 1218088a9f7Sfgsch 1228088a9f7Sfgsch pcmcia_chipset_tag_t pct; 1238088a9f7Sfgsch 1248088a9f7Sfgsch /* this needs to be large enough to hold PCIC_MEM_PAGES bits */ 1258088a9f7Sfgsch int subregionmask; 1264ede623dSfgsch #define PCIC_MAX_MEM_PAGES (8 * sizeof(int)) 1278088a9f7Sfgsch 1288088a9f7Sfgsch /* used by memory window mapping functions */ 1298088a9f7Sfgsch bus_addr_t membase; 1308088a9f7Sfgsch 1318088a9f7Sfgsch /* 1328088a9f7Sfgsch * used by io window mapping functions. These can actually overlap 1338088a9f7Sfgsch * with another pcic, since the underlying extent mapper will deal 1348088a9f7Sfgsch * with individual allocations. This is here to deal with the fact 1358088a9f7Sfgsch * that different busses have different real widths (different pc 1368088a9f7Sfgsch * hardware seems to use 10 or 12 bits for the I/O bus). 1378088a9f7Sfgsch */ 1388088a9f7Sfgsch bus_addr_t iobase; 1398088a9f7Sfgsch bus_addr_t iosize; 140957c80edSderaadt struct pcic_ranges *ranges; 1418088a9f7Sfgsch 1428088a9f7Sfgsch int irq; 1438088a9f7Sfgsch void *ih; 1448088a9f7Sfgsch 145d4766543Saaron /* used by socket event polling */ 146d4766543Saaron struct timeout poll_timeout; 147d4766543Saaron int poll_established; 148d4766543Saaron 1498088a9f7Sfgsch struct pcic_handle handle[PCIC_NSLOTS]; 1508088a9f7Sfgsch }; 1518088a9f7Sfgsch 1528088a9f7Sfgsch 153c4071fd1Smillert int pcic_ident_ok(int); 154c4071fd1Smillert int pcic_vendor(struct pcic_handle *); 1558088a9f7Sfgsch 156c4071fd1Smillert void pcic_attach(struct pcic_softc *); 157c4071fd1Smillert void pcic_attach_sockets(struct pcic_softc *); 158c4071fd1Smillert int pcic_intr(void *arg); 159c4071fd1Smillert void pcic_poll_intr(void *arg); 1608088a9f7Sfgsch 161c4071fd1Smillert int pcic_chip_mem_alloc(pcmcia_chipset_handle_t, bus_size_t, 162c4071fd1Smillert struct pcmcia_mem_handle *); 163c4071fd1Smillert void pcic_chip_mem_free(pcmcia_chipset_handle_t, 164c4071fd1Smillert struct pcmcia_mem_handle *); 165c4071fd1Smillert int pcic_chip_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t, 166*60f78cd0Smickey bus_size_t, struct pcmcia_mem_handle *, bus_size_t *, int *); 167c4071fd1Smillert void pcic_chip_mem_unmap(pcmcia_chipset_handle_t, int); 1688088a9f7Sfgsch 169c4071fd1Smillert int pcic_chip_io_alloc(pcmcia_chipset_handle_t, bus_addr_t, 170c4071fd1Smillert bus_size_t, bus_size_t, struct pcmcia_io_handle *); 171c4071fd1Smillert void pcic_chip_io_free(pcmcia_chipset_handle_t, 172c4071fd1Smillert struct pcmcia_io_handle *); 173c4071fd1Smillert int pcic_chip_io_map(pcmcia_chipset_handle_t, int, bus_addr_t, 174c4071fd1Smillert bus_size_t, struct pcmcia_io_handle *, int *); 175c4071fd1Smillert void pcic_chip_io_unmap(pcmcia_chipset_handle_t, int); 1768088a9f7Sfgsch 177c4071fd1Smillert void pcic_chip_socket_enable(pcmcia_chipset_handle_t); 178c4071fd1Smillert void pcic_chip_socket_disable(pcmcia_chipset_handle_t); 1798088a9f7Sfgsch 180c4071fd1Smillert void pcic_power(int, void *); 181aa92a072Saaron 182e77beeccSaaron #define pcic_read(h, idx) \ 183e77beeccSaaron (*(h)->ph_read)((h), (idx)) 1848088a9f7Sfgsch 185e77beeccSaaron #define pcic_write(h, idx, data) \ 186e77beeccSaaron (*(h)->ph_write)((h), (idx), (data)) 187