? tcic2.c ? tcic2reg.h ? pcic.c- ? tcic2var.h ? tcic2_isa.c ? pccard.c- Index: pcic_pci.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/sys/pccard/pcic_pci.c,v retrieving revision 1.36 diff -u -r1.36 pcic_pci.c --- pcic_pci.c 2001/05/14 06:15:24 1.36 +++ pcic_pci.c 2001/05/23 04:07:56 @@ -30,19 +30,44 @@ */ #include +#include #include +#include #include -#include + #include #include + #include #include -#include -#include +#include +#include +#include + +#include +#include "card_if.h" #define PRVERB(x) if (bootverbose) device_printf x /* + * Read a register from the PCIC. + */ +static unsigned char +getb2(struct pcic_slot *sp, int reg) +{ + return (*(sp->regs + reg)); +} + +/* + * Write a register on the PCIC + */ +static void +putb2(struct pcic_slot *sp, int reg, unsigned char val) +{ + *(sp->regs + reg) = val; +} + +/* * Set up the CL-PD6832 to look like a ISA based PCMCIA chip (a * PD672X). This routine is called once per PCMCIA socket. */ @@ -51,12 +76,12 @@ { u_long bcr; /* to set interrupts */ u_short io_port; /* the io_port to map this slot on */ - static int num6832; /* The number of 6832s initialized */ int unit; - num6832 = 0; unit = device_get_unit(dev); +/* XXX */ + /* * Some BIOS leave the legacy address uninitialized. This * insures that the PD6832 puts itself where the driver will @@ -64,10 +89,9 @@ * sequentially. We only initialize the first socket's legacy port, * the other is a dummy. */ - io_port = PCIC_INDEX_0 + num6832 * CLPD6832_NUM_REGS; - if (unit == 0) - pci_write_config(dev, CLPD6832_LEGACY_16BIT_IOADDR, - io_port & ~CLPD6832_LEGACY_16BIT_IOENABLE, 4); + io_port = 0; + pci_write_config(dev, CLPD6832_LEGACY_16BIT_IOADDR, + io_port & ~CLPD6832_LEGACY_16BIT_IOENABLE, 4); /* * I think this should be a call to pci_map_port, but that @@ -78,18 +102,6 @@ ~CLPD6832_LEGACY_16BIT_IOENABLE; /* - * Configure the first I/O window to contain CLPD6832_NUM_REGS - * words and deactivate the second by setting the limit lower - * than the base. - */ - pci_write_config(dev, CLPD6832_IO_BASE0, io_port | 1, 4); - pci_write_config(dev, CLPD6832_IO_LIMIT0, - (io_port + CLPD6832_NUM_REGS) | 1, 4); - - pci_write_config(dev, CLPD6832_IO_BASE1, (io_port + 0x20) | 1, 4); - pci_write_config(dev, CLPD6832_IO_LIMIT1, io_port | 1, 4); - - /* * Set default operating mode (I/O port space) and allocate * this socket to the current unit. */ @@ -104,10 +116,6 @@ bcr |= (CLPD6832_BCR_ISA_IRQ|CLPD6832_BCR_MGMT_IRQ_ENA); pci_write_config(dev, CLPD6832_BRIDGE_CONTROL, bcr, 4); - /* After initializing 2 sockets, the chip is fully configured */ - if (unit == 1) - num6832++; - PRVERB((dev, "CardBus: Legacy PC-card 16bit I/O address [0x%x]\n", io_port)); } @@ -184,7 +192,6 @@ generic_cardbus_attach(device_t dev) { u_int16_t brgcntl; - u_int32_t iobase; int unit; unit = device_get_unit(dev); @@ -194,19 +201,8 @@ brgcntl |= CB_BCR_INT_EXCA; pci_write_config(dev, CB_PCI_BRIDGE_CTRL, brgcntl, 2); - /* 16bit Legacy Mode Base Address */ - if (unit != 0) - return; - - iobase = pci_read_config(dev, CB_PCI_LEGACY16_IOADDR, 2) & - ~CB_PCI_LEGACY16_IOENABLE; - if (!iobase) { - iobase = 0x3e0 | CB_PCI_LEGACY16_IOENABLE; - pci_write_config(dev, CB_PCI_LEGACY16_IOADDR, iobase, 2); - iobase = pci_read_config(dev, CB_PCI_LEGACY16_IOADDR, 2) - & ~CB_PCI_LEGACY16_IOENABLE; - } - PRVERB((dev, "Legacy address set to %#x\n", iobase)); + /* Turn off legacy address */ + pci_write_config(dev, CB_PCI_LEGACY16_IOADDR, 0, 2); return; } @@ -273,6 +269,9 @@ case PCI_DEVICE_ID_TOSHIBA_TOPIC97: desc = "Toshiba ToPIC97 PCI-CardBus Bridge"; break; + case PCI_DEVICE_ID_TOSHIBA_TOPIC100: + desc = "Toshiba ToPIC100 PCI-CardBus Bridge"; + break; case PCI_DEVICE_ID_RICOH_RL5C465: desc = "Ricoh RL5C465 PCI-CardBus Bridge"; break; @@ -324,8 +323,7 @@ * datasheet for them that has register definitions. */ brgcntl = pci_read_config(dev, CB_PCI_BRIDGE_CTRL, 2); - brgcntl |= CB_BCR_RL_3E0_EN; - brgcntl &= ~CB_BCR_RL_3E2_EN; + brgcntl &= ~(CB_BCR_RL_3E2_EN | CB_BCR_RL_3E0_EN); pci_write_config(dev, CLPD6832_BRIDGE_CONTROL, brgcntl, 4); } @@ -339,9 +337,9 @@ { u_int32_t device_id = pci_get_devid(dev); u_long command; + struct pcic_slot *sp; + struct pcic_softc *sc; - /* Init. CardBus/PC-card controllers as 16-bit PC-card controllers */ - /* Place any per "slot" initialization here */ /* @@ -353,12 +351,59 @@ command |= PCIM_CMD_PORTEN | PCIM_CMD_MEMEN; pci_write_config(dev, PCIR_COMMAND, command, 4); + sc = (struct pcic_softc *) device_get_softc(dev); + sc->memrid = 0x10; + sc->memres = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->memrid, + 0, ~0, 1, RF_ACTIVE); + if (sc->memres == NULL) { + u_int32_t sockbase; + + sockbase = pci_read_config(dev, sc->memrid, 4); + if (sockbase >= 0x100000 && sockbase < 0xfffffff0) { + device_printf(dev, "Could not map register memory\n"); + return (ENOMEM); + } + pci_write_config(dev, sc->memrid, 0xffffffff, 4); + sockbase = pci_read_config(dev, sc->memrid, 4); + sockbase = (sockbase & 0xfffffff0) & -(sockbase & 0xfffffff0); +#define CARDBUS_SYS_RES_MEMORY_START 0x44000000 +#define CARDBUS_SYS_RES_MEMORY_END 0xEFFFFFFF + sc->memres = bus_generic_alloc_resource(device_get_parent(dev), + dev, SYS_RES_MEMORY, &sc->memrid, + CARDBUS_SYS_RES_MEMORY_START, CARDBUS_SYS_RES_MEMORY_END, + sockbase, RF_ACTIVE | rman_make_alignment_flags(sockbase)); + if (sc->memres == NULL) { + device_printf(dev, "Could not grab register memory\n"); + return (ENOMEM); + } + sockbase = rman_get_start(sc->memres); + pci_write_config(dev, sc->memrid, sockbase, 4); + device_printf(dev, "PCI Memory allocated: 0x%08x\n", sockbase); + } +#if 0 + sc->cb_bt = rman_get_bustag(sc->memres); + sc->cb_bh = rman_get_bushandle(sc->memres); +#endif + sc->unit = device_get_unit(dev); + sp = &sc->slots[0]; + /* + * Initialise the PCIC slot table. + */ + sp->getb = getb2; + sp->putb = putb2; + sp->regs = (u_char *) rman_get_virtual(sc->memres) + 0x800; + if ((sp->getb(sp, PCIC_ID_REV) & 0xc0) == 0x80) { + sp->controller = PCIC_I82365SL_DF; + sp->slt = (struct slot *) 1; + } + switch (device_id) { case PCI_DEVICE_ID_RICOH_RL5C465: case PCI_DEVICE_ID_RICOH_RL5C466: ricoh_init(dev); generic_cardbus_attach(dev); break; + case PCI_DEVICE_ID_PCIC_TI1031: case PCI_DEVICE_ID_PCIC_TI1130: case PCI_DEVICE_ID_PCIC_TI1131: case PCI_DEVICE_ID_PCIC_TI1211: @@ -378,39 +423,11 @@ generic_cardbus_attach(dev); break; case PCI_DEVICE_ID_PCIC_CLPD6832: - case PCI_DEVICE_ID_PCIC_TI1031: /* 1031 is like 6832 */ pd6832_legacy_init(dev); break; } - - if (bootverbose) { - int i, j; - u_char *p; - u_long *pl; - - printf("PCI Config space:\n"); - for (j = 0; j < 0x98; j += 16) { - printf("%02x: ", j); - for (i = 0; i < 16; i += 4) - printf(" %08x", pci_read_config(dev, i+j, 4)); - printf("\n"); - } - p = (u_char *)pmap_mapdev(pci_read_config(dev, 0x10, 4), - 0x1000); - pl = (u_long *)p; - printf("Cardbus Socket registers:\n"); - printf("00: "); - for (i = 0; i < 4; i += 1) - printf(" %08lx:", pl[i]); - printf("\n10: "); - for (i = 4; i < 8; i += 1) - printf(" %08lx:", pl[i]); - printf("\nExCa registers:\n"); - for (i = 0; i < 0x40; i += 16) - printf("%02x: %16D\n", i, p + 0x800 + i, " "); - } - return (0); + return (pcic_attach(dev)); } static int @@ -428,15 +445,28 @@ DEVMETHOD(device_resume, bus_generic_resume), DEVMETHOD(device_shutdown, bus_generic_shutdown), + /* Bus interface */ + DEVMETHOD(bus_print_child, bus_generic_print_child), + DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource), + DEVMETHOD(bus_release_resource, bus_generic_release_resource), + DEVMETHOD(bus_activate_resource, pcic_activate_resource), + DEVMETHOD(bus_deactivate_resource, pcic_deactivate_resource), + DEVMETHOD(bus_setup_intr, pcic_setup_intr), + DEVMETHOD(bus_teardown_intr, pcic_teardown_intr), + + /* Card interface */ + DEVMETHOD(card_set_res_flags, pcic_set_res_flags), + DEVMETHOD(card_get_res_flags, pcic_get_res_flags), + DEVMETHOD(card_set_memory_offset, pcic_set_memory_offset), + DEVMETHOD(card_get_memory_offset, pcic_get_memory_offset), + {0, 0} }; static driver_t pcic_pci_driver = { - "pcic-pci", + "pcic", pcic_pci_methods, - 0 /* no softc */ + sizeof(struct pcic_softc) }; - -static devclass_t pcic_pci_devclass; -DRIVER_MODULE(pcic_pci, pci, pcic_pci_driver, pcic_pci_devclass, 0, 0); +DRIVER_MODULE(pcic, pci, pcic_pci_driver, pcic_devclass, 0, 0); Index: pcic_pci.h =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/sys/pccard/pcic_pci.h,v retrieving revision 1.18 diff -u -r1.18 pcic_pci.h --- pcic_pci.h 2001/05/08 02:06:03 1.18 +++ pcic_pci.h 2001/05/23 04:07:56 @@ -51,6 +51,7 @@ #define PCI_DEVICE_ID_PCIC_TI1451 0xac52104cul #define PCI_DEVICE_ID_TOSHIBA_TOPIC95 0x060a1179ul #define PCI_DEVICE_ID_TOSHIBA_TOPIC97 0x060f1179ul +#define PCI_DEVICE_ID_TOSHIBA_TOPIC100 0x06171179ul #define PCI_DEVICE_ID_RICOH_RL5C465 0x04651180ul #define PCI_DEVICE_ID_RICOH_RL5C466 0x04661180ul #define PCI_DEVICE_ID_RICOH_RL5C475 0x04751180ul