1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * linux/arch/alpha/kernel/core_titan.c
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Code common to all TITAN core logic chips.
61da177e4SLinus Torvalds */
71da177e4SLinus Torvalds
81da177e4SLinus Torvalds #define __EXTERN_INLINE inline
91da177e4SLinus Torvalds #include <asm/io.h>
101da177e4SLinus Torvalds #include <asm/core_titan.h>
111da177e4SLinus Torvalds #undef __EXTERN_INLINE
121da177e4SLinus Torvalds
131da177e4SLinus Torvalds #include <linux/module.h>
141da177e4SLinus Torvalds #include <linux/types.h>
151da177e4SLinus Torvalds #include <linux/pci.h>
161da177e4SLinus Torvalds #include <linux/sched.h>
171da177e4SLinus Torvalds #include <linux/init.h>
181da177e4SLinus Torvalds #include <linux/vmalloc.h>
1957c8a661SMike Rapoport #include <linux/memblock.h>
201da177e4SLinus Torvalds
211da177e4SLinus Torvalds #include <asm/ptrace.h>
221da177e4SLinus Torvalds #include <asm/smp.h>
231da177e4SLinus Torvalds #include <asm/tlbflush.h>
24025a2215SJay Estabrook #include <asm/vga.h>
251da177e4SLinus Torvalds
261da177e4SLinus Torvalds #include "proto.h"
271da177e4SLinus Torvalds #include "pci_impl.h"
281da177e4SLinus Torvalds
291da177e4SLinus Torvalds /* Save Titan configuration data as the console had it set up. */
301da177e4SLinus Torvalds
311da177e4SLinus Torvalds struct
321da177e4SLinus Torvalds {
331da177e4SLinus Torvalds unsigned long wsba[4];
341da177e4SLinus Torvalds unsigned long wsm[4];
351da177e4SLinus Torvalds unsigned long tba[4];
361da177e4SLinus Torvalds } saved_config[4] __attribute__((common));
371da177e4SLinus Torvalds
381da177e4SLinus Torvalds /*
39025a2215SJay Estabrook * Is PChip 1 present? No need to query it more than once.
40025a2215SJay Estabrook */
41025a2215SJay Estabrook static int titan_pchip1_present;
42025a2215SJay Estabrook
43025a2215SJay Estabrook /*
441da177e4SLinus Torvalds * BIOS32-style PCI interface:
451da177e4SLinus Torvalds */
461da177e4SLinus Torvalds
471da177e4SLinus Torvalds #define DEBUG_CONFIG 0
481da177e4SLinus Torvalds
491da177e4SLinus Torvalds #if DEBUG_CONFIG
501da177e4SLinus Torvalds # define DBG_CFG(args) printk args
511da177e4SLinus Torvalds #else
521da177e4SLinus Torvalds # define DBG_CFG(args)
531da177e4SLinus Torvalds #endif
541da177e4SLinus Torvalds
551da177e4SLinus Torvalds
561da177e4SLinus Torvalds /*
571da177e4SLinus Torvalds * Routines to access TIG registers.
581da177e4SLinus Torvalds */
591da177e4SLinus Torvalds static inline volatile unsigned long *
mk_tig_addr(int offset)601da177e4SLinus Torvalds mk_tig_addr(int offset)
611da177e4SLinus Torvalds {
621da177e4SLinus Torvalds return (volatile unsigned long *)(TITAN_TIG_SPACE + (offset << 6));
631da177e4SLinus Torvalds }
641da177e4SLinus Torvalds
651da177e4SLinus Torvalds static inline u8
titan_read_tig(int offset,u8 value)661da177e4SLinus Torvalds titan_read_tig(int offset, u8 value)
671da177e4SLinus Torvalds {
681da177e4SLinus Torvalds volatile unsigned long *tig_addr = mk_tig_addr(offset);
691da177e4SLinus Torvalds return (u8)(*tig_addr & 0xff);
701da177e4SLinus Torvalds }
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds static inline void
titan_write_tig(int offset,u8 value)731da177e4SLinus Torvalds titan_write_tig(int offset, u8 value)
741da177e4SLinus Torvalds {
751da177e4SLinus Torvalds volatile unsigned long *tig_addr = mk_tig_addr(offset);
761da177e4SLinus Torvalds *tig_addr = (unsigned long)value;
771da177e4SLinus Torvalds }
781da177e4SLinus Torvalds
791da177e4SLinus Torvalds
801da177e4SLinus Torvalds /*
811da177e4SLinus Torvalds * Given a bus, device, and function number, compute resulting
821da177e4SLinus Torvalds * configuration space address
831da177e4SLinus Torvalds * accordingly. It is therefore not safe to have concurrent
841da177e4SLinus Torvalds * invocations to configuration space access routines, but there
851da177e4SLinus Torvalds * really shouldn't be any need for this.
861da177e4SLinus Torvalds *
871da177e4SLinus Torvalds * Note that all config space accesses use Type 1 address format.
881da177e4SLinus Torvalds *
891da177e4SLinus Torvalds * Note also that type 1 is determined by non-zero bus number.
901da177e4SLinus Torvalds *
911da177e4SLinus Torvalds * Type 1:
921da177e4SLinus Torvalds *
931da177e4SLinus Torvalds * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
941da177e4SLinus Torvalds * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0
951da177e4SLinus Torvalds * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
961da177e4SLinus Torvalds * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
971da177e4SLinus Torvalds * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
981da177e4SLinus Torvalds *
991da177e4SLinus Torvalds * 31:24 reserved
1001da177e4SLinus Torvalds * 23:16 bus number (8 bits = 128 possible buses)
1011da177e4SLinus Torvalds * 15:11 Device number (5 bits)
1021da177e4SLinus Torvalds * 10:8 function number
1031da177e4SLinus Torvalds * 7:2 register number
1041da177e4SLinus Torvalds *
1051da177e4SLinus Torvalds * Notes:
1061da177e4SLinus Torvalds * The function number selects which function of a multi-function device
1071da177e4SLinus Torvalds * (e.g., SCSI and Ethernet).
1081da177e4SLinus Torvalds *
1091da177e4SLinus Torvalds * The register selects a DWORD (32 bit) register offset. Hence it
1101da177e4SLinus Torvalds * doesn't get shifted by 2 bits as we want to "drop" the bottom two
1111da177e4SLinus Torvalds * bits.
1121da177e4SLinus Torvalds */
1131da177e4SLinus Torvalds
1141da177e4SLinus Torvalds static int
mk_conf_addr(struct pci_bus * pbus,unsigned int device_fn,int where,unsigned long * pci_addr,unsigned char * type1)1151da177e4SLinus Torvalds mk_conf_addr(struct pci_bus *pbus, unsigned int device_fn, int where,
1161da177e4SLinus Torvalds unsigned long *pci_addr, unsigned char *type1)
1171da177e4SLinus Torvalds {
1181da177e4SLinus Torvalds struct pci_controller *hose = pbus->sysdata;
1191da177e4SLinus Torvalds unsigned long addr;
1201da177e4SLinus Torvalds u8 bus = pbus->number;
1211da177e4SLinus Torvalds
1221da177e4SLinus Torvalds DBG_CFG(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, "
1231da177e4SLinus Torvalds "pci_addr=0x%p, type1=0x%p)\n",
1241da177e4SLinus Torvalds bus, device_fn, where, pci_addr, type1));
1251da177e4SLinus Torvalds
1261da177e4SLinus Torvalds if (!pbus->parent) /* No parent means peer PCI bus. */
1271da177e4SLinus Torvalds bus = 0;
1281da177e4SLinus Torvalds *type1 = (bus != 0);
1291da177e4SLinus Torvalds
1301da177e4SLinus Torvalds addr = (bus << 16) | (device_fn << 8) | where;
1311da177e4SLinus Torvalds addr |= hose->config_space_base;
1321da177e4SLinus Torvalds
1331da177e4SLinus Torvalds *pci_addr = addr;
1341da177e4SLinus Torvalds DBG_CFG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr));
1351da177e4SLinus Torvalds return 0;
1361da177e4SLinus Torvalds }
1371da177e4SLinus Torvalds
1381da177e4SLinus Torvalds static int
titan_read_config(struct pci_bus * bus,unsigned int devfn,int where,int size,u32 * value)1391da177e4SLinus Torvalds titan_read_config(struct pci_bus *bus, unsigned int devfn, int where,
1401da177e4SLinus Torvalds int size, u32 *value)
1411da177e4SLinus Torvalds {
1421da177e4SLinus Torvalds unsigned long addr;
1431da177e4SLinus Torvalds unsigned char type1;
1441da177e4SLinus Torvalds
1451da177e4SLinus Torvalds if (mk_conf_addr(bus, devfn, where, &addr, &type1))
1461da177e4SLinus Torvalds return PCIBIOS_DEVICE_NOT_FOUND;
1471da177e4SLinus Torvalds
1481da177e4SLinus Torvalds switch (size) {
1491da177e4SLinus Torvalds case 1:
1501da177e4SLinus Torvalds *value = __kernel_ldbu(*(vucp)addr);
1511da177e4SLinus Torvalds break;
1521da177e4SLinus Torvalds case 2:
1531da177e4SLinus Torvalds *value = __kernel_ldwu(*(vusp)addr);
1541da177e4SLinus Torvalds break;
1551da177e4SLinus Torvalds case 4:
1561da177e4SLinus Torvalds *value = *(vuip)addr;
1571da177e4SLinus Torvalds break;
1581da177e4SLinus Torvalds }
1591da177e4SLinus Torvalds
1601da177e4SLinus Torvalds return PCIBIOS_SUCCESSFUL;
1611da177e4SLinus Torvalds }
1621da177e4SLinus Torvalds
1631da177e4SLinus Torvalds static int
titan_write_config(struct pci_bus * bus,unsigned int devfn,int where,int size,u32 value)1641da177e4SLinus Torvalds titan_write_config(struct pci_bus *bus, unsigned int devfn, int where,
1651da177e4SLinus Torvalds int size, u32 value)
1661da177e4SLinus Torvalds {
1671da177e4SLinus Torvalds unsigned long addr;
1681da177e4SLinus Torvalds unsigned char type1;
1691da177e4SLinus Torvalds
1701da177e4SLinus Torvalds if (mk_conf_addr(bus, devfn, where, &addr, &type1))
1711da177e4SLinus Torvalds return PCIBIOS_DEVICE_NOT_FOUND;
1721da177e4SLinus Torvalds
1731da177e4SLinus Torvalds switch (size) {
1741da177e4SLinus Torvalds case 1:
1751da177e4SLinus Torvalds __kernel_stb(value, *(vucp)addr);
1761da177e4SLinus Torvalds mb();
1771da177e4SLinus Torvalds __kernel_ldbu(*(vucp)addr);
1781da177e4SLinus Torvalds break;
1791da177e4SLinus Torvalds case 2:
1801da177e4SLinus Torvalds __kernel_stw(value, *(vusp)addr);
1811da177e4SLinus Torvalds mb();
1821da177e4SLinus Torvalds __kernel_ldwu(*(vusp)addr);
1831da177e4SLinus Torvalds break;
1841da177e4SLinus Torvalds case 4:
1851da177e4SLinus Torvalds *(vuip)addr = value;
1861da177e4SLinus Torvalds mb();
1871da177e4SLinus Torvalds *(vuip)addr;
1881da177e4SLinus Torvalds break;
1891da177e4SLinus Torvalds }
1901da177e4SLinus Torvalds
1911da177e4SLinus Torvalds return PCIBIOS_SUCCESSFUL;
1921da177e4SLinus Torvalds }
1931da177e4SLinus Torvalds
1941da177e4SLinus Torvalds struct pci_ops titan_pci_ops =
1951da177e4SLinus Torvalds {
1961da177e4SLinus Torvalds .read = titan_read_config,
1971da177e4SLinus Torvalds .write = titan_write_config,
1981da177e4SLinus Torvalds };
1991da177e4SLinus Torvalds
2001da177e4SLinus Torvalds
2011da177e4SLinus Torvalds void
titan_pci_tbi(struct pci_controller * hose,dma_addr_t start,dma_addr_t end)2021da177e4SLinus Torvalds titan_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end)
2031da177e4SLinus Torvalds {
2041da177e4SLinus Torvalds titan_pachip *pachip =
2051da177e4SLinus Torvalds (hose->index & 1) ? TITAN_pachip1 : TITAN_pachip0;
2061da177e4SLinus Torvalds titan_pachip_port *port;
2071da177e4SLinus Torvalds volatile unsigned long *csr;
2081da177e4SLinus Torvalds unsigned long value;
2091da177e4SLinus Torvalds
2101da177e4SLinus Torvalds /* Get the right hose. */
2111da177e4SLinus Torvalds port = &pachip->g_port;
2121da177e4SLinus Torvalds if (hose->index & 2)
2131da177e4SLinus Torvalds port = &pachip->a_port;
2141da177e4SLinus Torvalds
2151da177e4SLinus Torvalds /* We can invalidate up to 8 tlb entries in a go. The flush
2161da177e4SLinus Torvalds matches against <31:16> in the pci address.
2171da177e4SLinus Torvalds Note that gtlbi* and atlbi* are in the same place in the g_port
2181da177e4SLinus Torvalds and a_port, respectively, so the g_port offset can be used
2191da177e4SLinus Torvalds even if hose is an a_port */
2201da177e4SLinus Torvalds csr = &port->port_specific.g.gtlbia.csr;
2211da177e4SLinus Torvalds if (((start ^ end) & 0xffff0000) == 0)
2221da177e4SLinus Torvalds csr = &port->port_specific.g.gtlbiv.csr;
2231da177e4SLinus Torvalds
2241da177e4SLinus Torvalds /* For TBIA, it doesn't matter what value we write. For TBI,
2251da177e4SLinus Torvalds it's the shifted tag bits. */
2261da177e4SLinus Torvalds value = (start & 0xffff0000) >> 12;
2271da177e4SLinus Torvalds
2281da177e4SLinus Torvalds wmb();
2291da177e4SLinus Torvalds *csr = value;
2301da177e4SLinus Torvalds mb();
2311da177e4SLinus Torvalds *csr;
2321da177e4SLinus Torvalds }
2331da177e4SLinus Torvalds
2341da177e4SLinus Torvalds static int
titan_query_agp(titan_pachip_port * port)2351da177e4SLinus Torvalds titan_query_agp(titan_pachip_port *port)
2361da177e4SLinus Torvalds {
2371da177e4SLinus Torvalds union TPAchipPCTL pctl;
2381da177e4SLinus Torvalds
2391da177e4SLinus Torvalds /* set up APCTL */
2401da177e4SLinus Torvalds pctl.pctl_q_whole = port->pctl.csr;
2411da177e4SLinus Torvalds
2421da177e4SLinus Torvalds return pctl.pctl_r_bits.apctl_v_agp_present;
2431da177e4SLinus Torvalds
2441da177e4SLinus Torvalds }
2451da177e4SLinus Torvalds
2461da177e4SLinus Torvalds static void __init
titan_init_one_pachip_port(titan_pachip_port * port,int index)2471da177e4SLinus Torvalds titan_init_one_pachip_port(titan_pachip_port *port, int index)
2481da177e4SLinus Torvalds {
2491da177e4SLinus Torvalds struct pci_controller *hose;
2501da177e4SLinus Torvalds
2511da177e4SLinus Torvalds hose = alloc_pci_controller();
2521da177e4SLinus Torvalds if (index == 0)
2531da177e4SLinus Torvalds pci_isa_hose = hose;
2541da177e4SLinus Torvalds hose->io_space = alloc_resource();
2551da177e4SLinus Torvalds hose->mem_space = alloc_resource();
2561da177e4SLinus Torvalds
2571da177e4SLinus Torvalds /*
2581da177e4SLinus Torvalds * This is for userland consumption. The 40-bit PIO bias that we
2591da177e4SLinus Torvalds * use in the kernel through KSEG doesn't work in the page table
2601da177e4SLinus Torvalds * based user mappings. (43-bit KSEG sign extends the physical
2611da177e4SLinus Torvalds * address from bit 40 to hit the I/O bit - mapped addresses don't).
2621da177e4SLinus Torvalds * So make sure we get the 43-bit PIO bias.
2631da177e4SLinus Torvalds */
2641da177e4SLinus Torvalds hose->sparse_mem_base = 0;
2651da177e4SLinus Torvalds hose->sparse_io_base = 0;
2661da177e4SLinus Torvalds hose->dense_mem_base
2671da177e4SLinus Torvalds = (TITAN_MEM(index) & 0xffffffffffUL) | 0x80000000000UL;
2681da177e4SLinus Torvalds hose->dense_io_base
2691da177e4SLinus Torvalds = (TITAN_IO(index) & 0xffffffffffUL) | 0x80000000000UL;
2701da177e4SLinus Torvalds
2711da177e4SLinus Torvalds hose->config_space_base = TITAN_CONF(index);
2721da177e4SLinus Torvalds hose->index = index;
2731da177e4SLinus Torvalds
2741da177e4SLinus Torvalds hose->io_space->start = TITAN_IO(index) - TITAN_IO_BIAS;
2751da177e4SLinus Torvalds hose->io_space->end = hose->io_space->start + TITAN_IO_SPACE - 1;
2761da177e4SLinus Torvalds hose->io_space->name = pci_io_names[index];
2771da177e4SLinus Torvalds hose->io_space->flags = IORESOURCE_IO;
2781da177e4SLinus Torvalds
2791da177e4SLinus Torvalds hose->mem_space->start = TITAN_MEM(index) - TITAN_MEM_BIAS;
2801da177e4SLinus Torvalds hose->mem_space->end = hose->mem_space->start + 0xffffffff;
2811da177e4SLinus Torvalds hose->mem_space->name = pci_mem_names[index];
2821da177e4SLinus Torvalds hose->mem_space->flags = IORESOURCE_MEM;
2831da177e4SLinus Torvalds
2841da177e4SLinus Torvalds if (request_resource(&ioport_resource, hose->io_space) < 0)
2851da177e4SLinus Torvalds printk(KERN_ERR "Failed to request IO on hose %d\n", index);
2861da177e4SLinus Torvalds if (request_resource(&iomem_resource, hose->mem_space) < 0)
2871da177e4SLinus Torvalds printk(KERN_ERR "Failed to request MEM on hose %d\n", index);
2881da177e4SLinus Torvalds
2891da177e4SLinus Torvalds /*
2901da177e4SLinus Torvalds * Save the existing PCI window translations. SRM will
2911da177e4SLinus Torvalds * need them when we go to reboot.
2921da177e4SLinus Torvalds */
2931da177e4SLinus Torvalds saved_config[index].wsba[0] = port->wsba[0].csr;
2941da177e4SLinus Torvalds saved_config[index].wsm[0] = port->wsm[0].csr;
2951da177e4SLinus Torvalds saved_config[index].tba[0] = port->tba[0].csr;
2961da177e4SLinus Torvalds
2971da177e4SLinus Torvalds saved_config[index].wsba[1] = port->wsba[1].csr;
2981da177e4SLinus Torvalds saved_config[index].wsm[1] = port->wsm[1].csr;
2991da177e4SLinus Torvalds saved_config[index].tba[1] = port->tba[1].csr;
3001da177e4SLinus Torvalds
3011da177e4SLinus Torvalds saved_config[index].wsba[2] = port->wsba[2].csr;
3021da177e4SLinus Torvalds saved_config[index].wsm[2] = port->wsm[2].csr;
3031da177e4SLinus Torvalds saved_config[index].tba[2] = port->tba[2].csr;
3041da177e4SLinus Torvalds
3051da177e4SLinus Torvalds saved_config[index].wsba[3] = port->wsba[3].csr;
3061da177e4SLinus Torvalds saved_config[index].wsm[3] = port->wsm[3].csr;
3071da177e4SLinus Torvalds saved_config[index].tba[3] = port->tba[3].csr;
3081da177e4SLinus Torvalds
3091da177e4SLinus Torvalds /*
3101da177e4SLinus Torvalds * Set up the PCI to main memory translation windows.
3111da177e4SLinus Torvalds *
3121da177e4SLinus Torvalds * Note: Window 3 on Titan is Scatter-Gather ONLY.
3131da177e4SLinus Torvalds *
3141da177e4SLinus Torvalds * Window 0 is scatter-gather 8MB at 8MB (for isa)
3151da177e4SLinus Torvalds * Window 1 is direct access 1GB at 2GB
3161da177e4SLinus Torvalds * Window 2 is scatter-gather 1GB at 3GB
3171da177e4SLinus Torvalds */
318*7e1c4e27SMike Rapoport hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000,
319*7e1c4e27SMike Rapoport SMP_CACHE_BYTES);
3201da177e4SLinus Torvalds hose->sg_isa->align_entry = 8; /* 64KB for ISA */
3211da177e4SLinus Torvalds
322*7e1c4e27SMike Rapoport hose->sg_pci = iommu_arena_new(hose, 0xc0000000, 0x40000000,
323*7e1c4e27SMike Rapoport SMP_CACHE_BYTES);
3241da177e4SLinus Torvalds hose->sg_pci->align_entry = 4; /* Titan caches 4 PTEs at a time */
3251da177e4SLinus Torvalds
3261da177e4SLinus Torvalds port->wsba[0].csr = hose->sg_isa->dma_base | 3;
3271da177e4SLinus Torvalds port->wsm[0].csr = (hose->sg_isa->size - 1) & 0xfff00000;
3281da177e4SLinus Torvalds port->tba[0].csr = virt_to_phys(hose->sg_isa->ptes);
3291da177e4SLinus Torvalds
3301da177e4SLinus Torvalds port->wsba[1].csr = __direct_map_base | 1;
3311da177e4SLinus Torvalds port->wsm[1].csr = (__direct_map_size - 1) & 0xfff00000;
3321da177e4SLinus Torvalds port->tba[1].csr = 0;
3331da177e4SLinus Torvalds
3341da177e4SLinus Torvalds port->wsba[2].csr = hose->sg_pci->dma_base | 3;
3351da177e4SLinus Torvalds port->wsm[2].csr = (hose->sg_pci->size - 1) & 0xfff00000;
3361da177e4SLinus Torvalds port->tba[2].csr = virt_to_phys(hose->sg_pci->ptes);
3371da177e4SLinus Torvalds
3381da177e4SLinus Torvalds port->wsba[3].csr = 0;
3391da177e4SLinus Torvalds
3401da177e4SLinus Torvalds /* Enable the Monster Window to make DAC pci64 possible. */
3411da177e4SLinus Torvalds port->pctl.csr |= pctl_m_mwin;
3421da177e4SLinus Torvalds
3431da177e4SLinus Torvalds /*
3441da177e4SLinus Torvalds * If it's an AGP port, initialize agplastwr.
3451da177e4SLinus Torvalds */
3461da177e4SLinus Torvalds if (titan_query_agp(port))
3471da177e4SLinus Torvalds port->port_specific.a.agplastwr.csr = __direct_map_base;
3481da177e4SLinus Torvalds
3491da177e4SLinus Torvalds titan_pci_tbi(hose, 0, -1);
3501da177e4SLinus Torvalds }
3511da177e4SLinus Torvalds
3521da177e4SLinus Torvalds static void __init
titan_init_pachips(titan_pachip * pachip0,titan_pachip * pachip1)3531da177e4SLinus Torvalds titan_init_pachips(titan_pachip *pachip0, titan_pachip *pachip1)
3541da177e4SLinus Torvalds {
355025a2215SJay Estabrook titan_pchip1_present = TITAN_cchip->csc.csr & 1L<<14;
3561da177e4SLinus Torvalds
3571da177e4SLinus Torvalds /* Init the ports in hose order... */
3581da177e4SLinus Torvalds titan_init_one_pachip_port(&pachip0->g_port, 0); /* hose 0 */
359025a2215SJay Estabrook if (titan_pchip1_present)
3601da177e4SLinus Torvalds titan_init_one_pachip_port(&pachip1->g_port, 1);/* hose 1 */
3611da177e4SLinus Torvalds titan_init_one_pachip_port(&pachip0->a_port, 2); /* hose 2 */
362025a2215SJay Estabrook if (titan_pchip1_present)
3631da177e4SLinus Torvalds titan_init_one_pachip_port(&pachip1->a_port, 3);/* hose 3 */
3641da177e4SLinus Torvalds }
3651da177e4SLinus Torvalds
3661da177e4SLinus Torvalds void __init
titan_init_arch(void)3671da177e4SLinus Torvalds titan_init_arch(void)
3681da177e4SLinus Torvalds {
3691da177e4SLinus Torvalds #if 0
370bbb8d343SHarvey Harrison printk("%s: titan_init_arch()\n", __func__);
371bbb8d343SHarvey Harrison printk("%s: CChip registers:\n", __func__);
372bbb8d343SHarvey Harrison printk("%s: CSR_CSC 0x%lx\n", __func__, TITAN_cchip->csc.csr);
373bbb8d343SHarvey Harrison printk("%s: CSR_MTR 0x%lx\n", __func__, TITAN_cchip->mtr.csr);
374bbb8d343SHarvey Harrison printk("%s: CSR_MISC 0x%lx\n", __func__, TITAN_cchip->misc.csr);
375bbb8d343SHarvey Harrison printk("%s: CSR_DIM0 0x%lx\n", __func__, TITAN_cchip->dim0.csr);
376bbb8d343SHarvey Harrison printk("%s: CSR_DIM1 0x%lx\n", __func__, TITAN_cchip->dim1.csr);
377bbb8d343SHarvey Harrison printk("%s: CSR_DIR0 0x%lx\n", __func__, TITAN_cchip->dir0.csr);
378bbb8d343SHarvey Harrison printk("%s: CSR_DIR1 0x%lx\n", __func__, TITAN_cchip->dir1.csr);
379bbb8d343SHarvey Harrison printk("%s: CSR_DRIR 0x%lx\n", __func__, TITAN_cchip->drir.csr);
3801da177e4SLinus Torvalds
381bbb8d343SHarvey Harrison printk("%s: DChip registers:\n", __func__);
382bbb8d343SHarvey Harrison printk("%s: CSR_DSC 0x%lx\n", __func__, TITAN_dchip->dsc.csr);
383bbb8d343SHarvey Harrison printk("%s: CSR_STR 0x%lx\n", __func__, TITAN_dchip->str.csr);
384bbb8d343SHarvey Harrison printk("%s: CSR_DREV 0x%lx\n", __func__, TITAN_dchip->drev.csr);
3851da177e4SLinus Torvalds #endif
3861da177e4SLinus Torvalds
3871da177e4SLinus Torvalds boot_cpuid = __hard_smp_processor_id();
3881da177e4SLinus Torvalds
3891da177e4SLinus Torvalds /* With multiple PCI busses, we play with I/O as physical addrs. */
3901da177e4SLinus Torvalds ioport_resource.end = ~0UL;
391025a2215SJay Estabrook iomem_resource.end = ~0UL;
3921da177e4SLinus Torvalds
3931da177e4SLinus Torvalds /* PCI DMA Direct Mapping is 1GB at 2GB. */
3941da177e4SLinus Torvalds __direct_map_base = 0x80000000;
3951da177e4SLinus Torvalds __direct_map_size = 0x40000000;
3961da177e4SLinus Torvalds
3971da177e4SLinus Torvalds /* Init the PA chip(s). */
3981da177e4SLinus Torvalds titan_init_pachips(TITAN_pachip0, TITAN_pachip1);
3991da177e4SLinus Torvalds
4001da177e4SLinus Torvalds /* Check for graphic console location (if any). */
401025a2215SJay Estabrook find_console_vga_hose();
4021da177e4SLinus Torvalds }
4031da177e4SLinus Torvalds
4041da177e4SLinus Torvalds static void
titan_kill_one_pachip_port(titan_pachip_port * port,int index)4051da177e4SLinus Torvalds titan_kill_one_pachip_port(titan_pachip_port *port, int index)
4061da177e4SLinus Torvalds {
4071da177e4SLinus Torvalds port->wsba[0].csr = saved_config[index].wsba[0];
4081da177e4SLinus Torvalds port->wsm[0].csr = saved_config[index].wsm[0];
4091da177e4SLinus Torvalds port->tba[0].csr = saved_config[index].tba[0];
4101da177e4SLinus Torvalds
4111da177e4SLinus Torvalds port->wsba[1].csr = saved_config[index].wsba[1];
4121da177e4SLinus Torvalds port->wsm[1].csr = saved_config[index].wsm[1];
4131da177e4SLinus Torvalds port->tba[1].csr = saved_config[index].tba[1];
4141da177e4SLinus Torvalds
4151da177e4SLinus Torvalds port->wsba[2].csr = saved_config[index].wsba[2];
4161da177e4SLinus Torvalds port->wsm[2].csr = saved_config[index].wsm[2];
4171da177e4SLinus Torvalds port->tba[2].csr = saved_config[index].tba[2];
4181da177e4SLinus Torvalds
4191da177e4SLinus Torvalds port->wsba[3].csr = saved_config[index].wsba[3];
4201da177e4SLinus Torvalds port->wsm[3].csr = saved_config[index].wsm[3];
4211da177e4SLinus Torvalds port->tba[3].csr = saved_config[index].tba[3];
4221da177e4SLinus Torvalds }
4231da177e4SLinus Torvalds
4241da177e4SLinus Torvalds static void
titan_kill_pachips(titan_pachip * pachip0,titan_pachip * pachip1)4251da177e4SLinus Torvalds titan_kill_pachips(titan_pachip *pachip0, titan_pachip *pachip1)
4261da177e4SLinus Torvalds {
427025a2215SJay Estabrook if (titan_pchip1_present) {
4281da177e4SLinus Torvalds titan_kill_one_pachip_port(&pachip1->g_port, 1);
4291da177e4SLinus Torvalds titan_kill_one_pachip_port(&pachip1->a_port, 3);
4301da177e4SLinus Torvalds }
4311da177e4SLinus Torvalds titan_kill_one_pachip_port(&pachip0->g_port, 0);
4321da177e4SLinus Torvalds titan_kill_one_pachip_port(&pachip0->a_port, 2);
4331da177e4SLinus Torvalds }
4341da177e4SLinus Torvalds
4351da177e4SLinus Torvalds void
titan_kill_arch(int mode)4361da177e4SLinus Torvalds titan_kill_arch(int mode)
4371da177e4SLinus Torvalds {
4381da177e4SLinus Torvalds titan_kill_pachips(TITAN_pachip0, TITAN_pachip1);
4391da177e4SLinus Torvalds }
4401da177e4SLinus Torvalds
4411da177e4SLinus Torvalds
4421da177e4SLinus Torvalds /*
4431da177e4SLinus Torvalds * IO map support.
4441da177e4SLinus Torvalds */
4451da177e4SLinus Torvalds
4461da177e4SLinus Torvalds void __iomem *
titan_ioportmap(unsigned long addr)447025a2215SJay Estabrook titan_ioportmap(unsigned long addr)
448025a2215SJay Estabrook {
449025a2215SJay Estabrook FIXUP_IOADDR_VGA(addr);
450025a2215SJay Estabrook return (void __iomem *)(addr + TITAN_IO_BIAS);
451025a2215SJay Estabrook }
452025a2215SJay Estabrook
453025a2215SJay Estabrook
454025a2215SJay Estabrook void __iomem *
titan_ioremap(unsigned long addr,unsigned long size)4551da177e4SLinus Torvalds titan_ioremap(unsigned long addr, unsigned long size)
4561da177e4SLinus Torvalds {
4571da177e4SLinus Torvalds int h = (addr & TITAN_HOSE_MASK) >> TITAN_HOSE_SHIFT;
4581da177e4SLinus Torvalds unsigned long baddr = addr & ~TITAN_HOSE_MASK;
4591da177e4SLinus Torvalds unsigned long last = baddr + size - 1;
4601da177e4SLinus Torvalds struct pci_controller *hose;
4611da177e4SLinus Torvalds struct vm_struct *area;
4621da177e4SLinus Torvalds unsigned long vaddr;
4631da177e4SLinus Torvalds unsigned long *ptes;
4641da177e4SLinus Torvalds unsigned long pfn;
4651da177e4SLinus Torvalds
466e42faf55SMatt Turner #ifdef CONFIG_VGA_HOSE
4671da177e4SLinus Torvalds /*
468025a2215SJay Estabrook * Adjust the address and hose, if necessary.
4691da177e4SLinus Torvalds */
470025a2215SJay Estabrook if (pci_vga_hose && __is_mem_vga(addr)) {
4711da177e4SLinus Torvalds h = pci_vga_hose->index;
4721da177e4SLinus Torvalds addr += pci_vga_hose->mem_space->start;
4731da177e4SLinus Torvalds }
474e42faf55SMatt Turner #endif
4751da177e4SLinus Torvalds
4761da177e4SLinus Torvalds /*
4771da177e4SLinus Torvalds * Find the hose.
4781da177e4SLinus Torvalds */
4791da177e4SLinus Torvalds for (hose = hose_head; hose; hose = hose->next)
4801da177e4SLinus Torvalds if (hose->index == h)
4811da177e4SLinus Torvalds break;
4821da177e4SLinus Torvalds if (!hose)
4831da177e4SLinus Torvalds return NULL;
4841da177e4SLinus Torvalds
4851da177e4SLinus Torvalds /*
4861da177e4SLinus Torvalds * Is it direct-mapped?
4871da177e4SLinus Torvalds */
4881da177e4SLinus Torvalds if ((baddr >= __direct_map_base) &&
4891da177e4SLinus Torvalds ((baddr + size - 1) < __direct_map_base + __direct_map_size)) {
4901da177e4SLinus Torvalds vaddr = addr - __direct_map_base + TITAN_MEM_BIAS;
4911da177e4SLinus Torvalds return (void __iomem *) vaddr;
4921da177e4SLinus Torvalds }
4931da177e4SLinus Torvalds
4941da177e4SLinus Torvalds /*
4951da177e4SLinus Torvalds * Check the scatter-gather arena.
4961da177e4SLinus Torvalds */
4971da177e4SLinus Torvalds if (hose->sg_pci &&
4981da177e4SLinus Torvalds baddr >= (unsigned long)hose->sg_pci->dma_base &&
4991da177e4SLinus Torvalds last < (unsigned long)hose->sg_pci->dma_base + hose->sg_pci->size){
5001da177e4SLinus Torvalds
5011da177e4SLinus Torvalds /*
5021da177e4SLinus Torvalds * Adjust the limits (mappings must be page aligned)
5031da177e4SLinus Torvalds */
5041da177e4SLinus Torvalds baddr -= hose->sg_pci->dma_base;
5051da177e4SLinus Torvalds last -= hose->sg_pci->dma_base;
5061da177e4SLinus Torvalds baddr &= PAGE_MASK;
5071da177e4SLinus Torvalds size = PAGE_ALIGN(last) - baddr;
5081da177e4SLinus Torvalds
5091da177e4SLinus Torvalds /*
5101da177e4SLinus Torvalds * Map it
5111da177e4SLinus Torvalds */
5121da177e4SLinus Torvalds area = get_vm_area(size, VM_IOREMAP);
513025a2215SJay Estabrook if (!area) {
514025a2215SJay Estabrook printk("ioremap failed... no vm_area...\n");
5151da177e4SLinus Torvalds return NULL;
516025a2215SJay Estabrook }
5171da177e4SLinus Torvalds
5181da177e4SLinus Torvalds ptes = hose->sg_pci->ptes;
5191da177e4SLinus Torvalds for (vaddr = (unsigned long)area->addr;
5201da177e4SLinus Torvalds baddr <= last;
5211da177e4SLinus Torvalds baddr += PAGE_SIZE, vaddr += PAGE_SIZE) {
5221da177e4SLinus Torvalds pfn = ptes[baddr >> PAGE_SHIFT];
5231da177e4SLinus Torvalds if (!(pfn & 1)) {
5241da177e4SLinus Torvalds printk("ioremap failed... pte not valid...\n");
5251da177e4SLinus Torvalds vfree(area->addr);
5261da177e4SLinus Torvalds return NULL;
5271da177e4SLinus Torvalds }
5281da177e4SLinus Torvalds pfn >>= 1; /* make it a true pfn */
5291da177e4SLinus Torvalds
5301da177e4SLinus Torvalds if (__alpha_remap_area_pages(vaddr,
5311da177e4SLinus Torvalds pfn << PAGE_SHIFT,
5321da177e4SLinus Torvalds PAGE_SIZE, 0)) {
533025a2215SJay Estabrook printk("FAILED to remap_area_pages...\n");
5341da177e4SLinus Torvalds vfree(area->addr);
5351da177e4SLinus Torvalds return NULL;
5361da177e4SLinus Torvalds }
5371da177e4SLinus Torvalds }
5381da177e4SLinus Torvalds
5391da177e4SLinus Torvalds flush_tlb_all();
5401da177e4SLinus Torvalds
5411da177e4SLinus Torvalds vaddr = (unsigned long)area->addr + (addr & ~PAGE_MASK);
5421da177e4SLinus Torvalds return (void __iomem *) vaddr;
5431da177e4SLinus Torvalds }
5441da177e4SLinus Torvalds
545025a2215SJay Estabrook /* Assume a legacy (read: VGA) address, and return appropriately. */
546025a2215SJay Estabrook return (void __iomem *)(addr + TITAN_MEM_BIAS);
5471da177e4SLinus Torvalds }
5481da177e4SLinus Torvalds
5491da177e4SLinus Torvalds void
titan_iounmap(volatile void __iomem * xaddr)5501da177e4SLinus Torvalds titan_iounmap(volatile void __iomem *xaddr)
5511da177e4SLinus Torvalds {
5521da177e4SLinus Torvalds unsigned long addr = (unsigned long) xaddr;
5531da177e4SLinus Torvalds if (addr >= VMALLOC_START)
5541da177e4SLinus Torvalds vfree((void *)(PAGE_MASK & addr));
5551da177e4SLinus Torvalds }
5561da177e4SLinus Torvalds
5571da177e4SLinus Torvalds int
titan_is_mmio(const volatile void __iomem * xaddr)5581da177e4SLinus Torvalds titan_is_mmio(const volatile void __iomem *xaddr)
5591da177e4SLinus Torvalds {
5601da177e4SLinus Torvalds unsigned long addr = (unsigned long) xaddr;
5611da177e4SLinus Torvalds
5621da177e4SLinus Torvalds if (addr >= VMALLOC_START)
5631da177e4SLinus Torvalds return 1;
5641da177e4SLinus Torvalds else
5651da177e4SLinus Torvalds return (addr & 0x100000000UL) == 0;
5661da177e4SLinus Torvalds }
5671da177e4SLinus Torvalds
5681da177e4SLinus Torvalds #ifndef CONFIG_ALPHA_GENERIC
569025a2215SJay Estabrook EXPORT_SYMBOL(titan_ioportmap);
5701da177e4SLinus Torvalds EXPORT_SYMBOL(titan_ioremap);
5711da177e4SLinus Torvalds EXPORT_SYMBOL(titan_iounmap);
5721da177e4SLinus Torvalds EXPORT_SYMBOL(titan_is_mmio);
5731da177e4SLinus Torvalds #endif
5741da177e4SLinus Torvalds
5751da177e4SLinus Torvalds /*
5761da177e4SLinus Torvalds * AGP GART Support.
5771da177e4SLinus Torvalds */
5781da177e4SLinus Torvalds #include <linux/agp_backend.h>
5791da177e4SLinus Torvalds #include <asm/agp_backend.h>
5801da177e4SLinus Torvalds #include <linux/slab.h>
5811da177e4SLinus Torvalds #include <linux/delay.h>
5821da177e4SLinus Torvalds
5831da177e4SLinus Torvalds struct titan_agp_aperture {
5841da177e4SLinus Torvalds struct pci_iommu_arena *arena;
5851da177e4SLinus Torvalds long pg_start;
5861da177e4SLinus Torvalds long pg_count;
5871da177e4SLinus Torvalds };
5881da177e4SLinus Torvalds
5891da177e4SLinus Torvalds static int
titan_agp_setup(alpha_agp_info * agp)5901da177e4SLinus Torvalds titan_agp_setup(alpha_agp_info *agp)
5911da177e4SLinus Torvalds {
5921da177e4SLinus Torvalds struct titan_agp_aperture *aper;
5931da177e4SLinus Torvalds
5941da177e4SLinus Torvalds if (!alpha_agpgart_size)
5951da177e4SLinus Torvalds return -ENOMEM;
5961da177e4SLinus Torvalds
5971da177e4SLinus Torvalds aper = kmalloc(sizeof(struct titan_agp_aperture), GFP_KERNEL);
5981da177e4SLinus Torvalds if (aper == NULL)
5991da177e4SLinus Torvalds return -ENOMEM;
6001da177e4SLinus Torvalds
6011da177e4SLinus Torvalds aper->arena = agp->hose->sg_pci;
6021da177e4SLinus Torvalds aper->pg_count = alpha_agpgart_size / PAGE_SIZE;
6031da177e4SLinus Torvalds aper->pg_start = iommu_reserve(aper->arena, aper->pg_count,
6041da177e4SLinus Torvalds aper->pg_count - 1);
6051da177e4SLinus Torvalds if (aper->pg_start < 0) {
6061da177e4SLinus Torvalds printk(KERN_ERR "Failed to reserve AGP memory\n");
6071da177e4SLinus Torvalds kfree(aper);
6081da177e4SLinus Torvalds return -ENOMEM;
6091da177e4SLinus Torvalds }
6101da177e4SLinus Torvalds
6111da177e4SLinus Torvalds agp->aperture.bus_base =
6121da177e4SLinus Torvalds aper->arena->dma_base + aper->pg_start * PAGE_SIZE;
6131da177e4SLinus Torvalds agp->aperture.size = aper->pg_count * PAGE_SIZE;
6141da177e4SLinus Torvalds agp->aperture.sysdata = aper;
6151da177e4SLinus Torvalds
6161da177e4SLinus Torvalds return 0;
6171da177e4SLinus Torvalds }
6181da177e4SLinus Torvalds
6191da177e4SLinus Torvalds static void
titan_agp_cleanup(alpha_agp_info * agp)6201da177e4SLinus Torvalds titan_agp_cleanup(alpha_agp_info *agp)
6211da177e4SLinus Torvalds {
6221da177e4SLinus Torvalds struct titan_agp_aperture *aper = agp->aperture.sysdata;
6231da177e4SLinus Torvalds int status;
6241da177e4SLinus Torvalds
6251da177e4SLinus Torvalds status = iommu_release(aper->arena, aper->pg_start, aper->pg_count);
6261da177e4SLinus Torvalds if (status == -EBUSY) {
6271da177e4SLinus Torvalds printk(KERN_WARNING
6281da177e4SLinus Torvalds "Attempted to release bound AGP memory - unbinding\n");
6291da177e4SLinus Torvalds iommu_unbind(aper->arena, aper->pg_start, aper->pg_count);
6301da177e4SLinus Torvalds status = iommu_release(aper->arena, aper->pg_start,
6311da177e4SLinus Torvalds aper->pg_count);
6321da177e4SLinus Torvalds }
6331da177e4SLinus Torvalds if (status < 0)
6341da177e4SLinus Torvalds printk(KERN_ERR "Failed to release AGP memory\n");
6351da177e4SLinus Torvalds
6361da177e4SLinus Torvalds kfree(aper);
6371da177e4SLinus Torvalds kfree(agp);
6381da177e4SLinus Torvalds }
6391da177e4SLinus Torvalds
6401da177e4SLinus Torvalds static int
titan_agp_configure(alpha_agp_info * agp)6411da177e4SLinus Torvalds titan_agp_configure(alpha_agp_info *agp)
6421da177e4SLinus Torvalds {
6431da177e4SLinus Torvalds union TPAchipPCTL pctl;
6441da177e4SLinus Torvalds titan_pachip_port *port = agp->private;
6451da177e4SLinus Torvalds pctl.pctl_q_whole = port->pctl.csr;
6461da177e4SLinus Torvalds
6471da177e4SLinus Torvalds /* Side-Band Addressing? */
6481da177e4SLinus Torvalds pctl.pctl_r_bits.apctl_v_agp_sba_en = agp->mode.bits.sba;
6491da177e4SLinus Torvalds
6501da177e4SLinus Torvalds /* AGP Rate? */
6511da177e4SLinus Torvalds pctl.pctl_r_bits.apctl_v_agp_rate = 0; /* 1x */
6521da177e4SLinus Torvalds if (agp->mode.bits.rate & 2)
6531da177e4SLinus Torvalds pctl.pctl_r_bits.apctl_v_agp_rate = 1; /* 2x */
6541da177e4SLinus Torvalds #if 0
6551da177e4SLinus Torvalds if (agp->mode.bits.rate & 4)
6561da177e4SLinus Torvalds pctl.pctl_r_bits.apctl_v_agp_rate = 2; /* 4x */
6571da177e4SLinus Torvalds #endif
6581da177e4SLinus Torvalds
6591da177e4SLinus Torvalds /* RQ Depth? */
6601da177e4SLinus Torvalds pctl.pctl_r_bits.apctl_v_agp_hp_rd = 2;
6611da177e4SLinus Torvalds pctl.pctl_r_bits.apctl_v_agp_lp_rd = 7;
6621da177e4SLinus Torvalds
6631da177e4SLinus Torvalds /*
6641da177e4SLinus Torvalds * AGP Enable.
6651da177e4SLinus Torvalds */
6661da177e4SLinus Torvalds pctl.pctl_r_bits.apctl_v_agp_en = agp->mode.bits.enable;
6671da177e4SLinus Torvalds
6681da177e4SLinus Torvalds /* Tell the user. */
6691da177e4SLinus Torvalds printk("Enabling AGP: %dX%s\n",
6701da177e4SLinus Torvalds 1 << pctl.pctl_r_bits.apctl_v_agp_rate,
6711da177e4SLinus Torvalds pctl.pctl_r_bits.apctl_v_agp_sba_en ? " - SBA" : "");
6721da177e4SLinus Torvalds
6731da177e4SLinus Torvalds /* Write it. */
6741da177e4SLinus Torvalds port->pctl.csr = pctl.pctl_q_whole;
6751da177e4SLinus Torvalds
6761da177e4SLinus Torvalds /* And wait at least 5000 66MHz cycles (per Titan spec). */
6771da177e4SLinus Torvalds udelay(100);
6781da177e4SLinus Torvalds
6791da177e4SLinus Torvalds return 0;
6801da177e4SLinus Torvalds }
6811da177e4SLinus Torvalds
6821da177e4SLinus Torvalds static int
titan_agp_bind_memory(alpha_agp_info * agp,off_t pg_start,struct agp_memory * mem)6831da177e4SLinus Torvalds titan_agp_bind_memory(alpha_agp_info *agp, off_t pg_start, struct agp_memory *mem)
6841da177e4SLinus Torvalds {
6851da177e4SLinus Torvalds struct titan_agp_aperture *aper = agp->aperture.sysdata;
6861da177e4SLinus Torvalds return iommu_bind(aper->arena, aper->pg_start + pg_start,
687d68721ebSIvan Kokshaysky mem->page_count, mem->pages);
6881da177e4SLinus Torvalds }
6891da177e4SLinus Torvalds
6901da177e4SLinus Torvalds static int
titan_agp_unbind_memory(alpha_agp_info * agp,off_t pg_start,struct agp_memory * mem)6911da177e4SLinus Torvalds titan_agp_unbind_memory(alpha_agp_info *agp, off_t pg_start, struct agp_memory *mem)
6921da177e4SLinus Torvalds {
6931da177e4SLinus Torvalds struct titan_agp_aperture *aper = agp->aperture.sysdata;
6941da177e4SLinus Torvalds return iommu_unbind(aper->arena, aper->pg_start + pg_start,
6951da177e4SLinus Torvalds mem->page_count);
6961da177e4SLinus Torvalds }
6971da177e4SLinus Torvalds
6981da177e4SLinus Torvalds static unsigned long
titan_agp_translate(alpha_agp_info * agp,dma_addr_t addr)6991da177e4SLinus Torvalds titan_agp_translate(alpha_agp_info *agp, dma_addr_t addr)
7001da177e4SLinus Torvalds {
7011da177e4SLinus Torvalds struct titan_agp_aperture *aper = agp->aperture.sysdata;
7021da177e4SLinus Torvalds unsigned long baddr = addr - aper->arena->dma_base;
7031da177e4SLinus Torvalds unsigned long pte;
7041da177e4SLinus Torvalds
7051da177e4SLinus Torvalds if (addr < agp->aperture.bus_base ||
7061da177e4SLinus Torvalds addr >= agp->aperture.bus_base + agp->aperture.size) {
707bbb8d343SHarvey Harrison printk("%s: addr out of range\n", __func__);
7081da177e4SLinus Torvalds return -EINVAL;
7091da177e4SLinus Torvalds }
7101da177e4SLinus Torvalds
7111da177e4SLinus Torvalds pte = aper->arena->ptes[baddr >> PAGE_SHIFT];
7121da177e4SLinus Torvalds if (!(pte & 1)) {
713bbb8d343SHarvey Harrison printk("%s: pte not valid\n", __func__);
7141da177e4SLinus Torvalds return -EINVAL;
7151da177e4SLinus Torvalds }
7161da177e4SLinus Torvalds
7171da177e4SLinus Torvalds return (pte >> 1) << PAGE_SHIFT;
7181da177e4SLinus Torvalds }
7191da177e4SLinus Torvalds
7201da177e4SLinus Torvalds struct alpha_agp_ops titan_agp_ops =
7211da177e4SLinus Torvalds {
7221da177e4SLinus Torvalds .setup = titan_agp_setup,
7231da177e4SLinus Torvalds .cleanup = titan_agp_cleanup,
7241da177e4SLinus Torvalds .configure = titan_agp_configure,
7251da177e4SLinus Torvalds .bind = titan_agp_bind_memory,
7261da177e4SLinus Torvalds .unbind = titan_agp_unbind_memory,
7271da177e4SLinus Torvalds .translate = titan_agp_translate
7281da177e4SLinus Torvalds };
7291da177e4SLinus Torvalds
7301da177e4SLinus Torvalds alpha_agp_info *
titan_agp_info(void)7311da177e4SLinus Torvalds titan_agp_info(void)
7321da177e4SLinus Torvalds {
7331da177e4SLinus Torvalds alpha_agp_info *agp;
7341da177e4SLinus Torvalds struct pci_controller *hose;
7351da177e4SLinus Torvalds titan_pachip_port *port;
7361da177e4SLinus Torvalds int hosenum = -1;
7371da177e4SLinus Torvalds union TPAchipPCTL pctl;
7381da177e4SLinus Torvalds
7391da177e4SLinus Torvalds /*
7401da177e4SLinus Torvalds * Find the AGP port.
7411da177e4SLinus Torvalds */
7421da177e4SLinus Torvalds port = &TITAN_pachip0->a_port;
7431da177e4SLinus Torvalds if (titan_query_agp(port))
7441da177e4SLinus Torvalds hosenum = 2;
7451da177e4SLinus Torvalds if (hosenum < 0 &&
746025a2215SJay Estabrook titan_pchip1_present &&
7471da177e4SLinus Torvalds titan_query_agp(port = &TITAN_pachip1->a_port))
7481da177e4SLinus Torvalds hosenum = 3;
7491da177e4SLinus Torvalds
7501da177e4SLinus Torvalds /*
7511da177e4SLinus Torvalds * Find the hose the port is on.
7521da177e4SLinus Torvalds */
7531da177e4SLinus Torvalds for (hose = hose_head; hose; hose = hose->next)
7541da177e4SLinus Torvalds if (hose->index == hosenum)
7551da177e4SLinus Torvalds break;
7561da177e4SLinus Torvalds
7571da177e4SLinus Torvalds if (!hose || !hose->sg_pci)
7581da177e4SLinus Torvalds return NULL;
7591da177e4SLinus Torvalds
7601da177e4SLinus Torvalds /*
7611da177e4SLinus Torvalds * Allocate the info structure.
7621da177e4SLinus Torvalds */
7631da177e4SLinus Torvalds agp = kmalloc(sizeof(*agp), GFP_KERNEL);
764cc9a2c83SJulia Lawall if (!agp)
765cc9a2c83SJulia Lawall return NULL;
7661da177e4SLinus Torvalds
7671da177e4SLinus Torvalds /*
7681da177e4SLinus Torvalds * Fill it in.
7691da177e4SLinus Torvalds */
7701da177e4SLinus Torvalds agp->hose = hose;
7711da177e4SLinus Torvalds agp->private = port;
7721da177e4SLinus Torvalds agp->ops = &titan_agp_ops;
7731da177e4SLinus Torvalds
7741da177e4SLinus Torvalds /*
7751da177e4SLinus Torvalds * Aperture - not configured until ops.setup().
7761da177e4SLinus Torvalds *
7771da177e4SLinus Torvalds * FIXME - should we go ahead and allocate it here?
7781da177e4SLinus Torvalds */
7791da177e4SLinus Torvalds agp->aperture.bus_base = 0;
7801da177e4SLinus Torvalds agp->aperture.size = 0;
7811da177e4SLinus Torvalds agp->aperture.sysdata = NULL;
7821da177e4SLinus Torvalds
7831da177e4SLinus Torvalds /*
7841da177e4SLinus Torvalds * Capabilities.
7851da177e4SLinus Torvalds */
7861da177e4SLinus Torvalds agp->capability.lw = 0;
7871da177e4SLinus Torvalds agp->capability.bits.rate = 3; /* 2x, 1x */
7881da177e4SLinus Torvalds agp->capability.bits.sba = 1;
7891da177e4SLinus Torvalds agp->capability.bits.rq = 7; /* 8 - 1 */
7901da177e4SLinus Torvalds
7911da177e4SLinus Torvalds /*
7921da177e4SLinus Torvalds * Mode.
7931da177e4SLinus Torvalds */
7941da177e4SLinus Torvalds pctl.pctl_q_whole = port->pctl.csr;
7951da177e4SLinus Torvalds agp->mode.lw = 0;
7961da177e4SLinus Torvalds agp->mode.bits.rate = 1 << pctl.pctl_r_bits.apctl_v_agp_rate;
7971da177e4SLinus Torvalds agp->mode.bits.sba = pctl.pctl_r_bits.apctl_v_agp_sba_en;
7981da177e4SLinus Torvalds agp->mode.bits.rq = 7; /* RQ Depth? */
7991da177e4SLinus Torvalds agp->mode.bits.enable = pctl.pctl_r_bits.apctl_v_agp_en;
8001da177e4SLinus Torvalds
8011da177e4SLinus Torvalds return agp;
8021da177e4SLinus Torvalds }
803