18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 38c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 48c2ecf20Sopenharmony_ci * for more details. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 2000, 2001 Keith M Wesolowski 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci#include <linux/kernel.h> 98c2ecf20Sopenharmony_ci#include <linux/pci.h> 108c2ecf20Sopenharmony_ci#include <linux/types.h> 118c2ecf20Sopenharmony_ci#include <asm/ip32/mace.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#if 0 148c2ecf20Sopenharmony_ci# define DPRINTK(args...) printk(args); 158c2ecf20Sopenharmony_ci#else 168c2ecf20Sopenharmony_ci# define DPRINTK(args...) 178c2ecf20Sopenharmony_ci#endif 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* 208c2ecf20Sopenharmony_ci * O2 has up to 5 PCI devices connected into the MACE bridge. The device 218c2ecf20Sopenharmony_ci * map looks like this: 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * 0 aic7xxx 0 248c2ecf20Sopenharmony_ci * 1 aic7xxx 1 258c2ecf20Sopenharmony_ci * 2 expansion slot 268c2ecf20Sopenharmony_ci * 3 N/C 278c2ecf20Sopenharmony_ci * 4 N/C 288c2ecf20Sopenharmony_ci */ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistatic inline int mkaddr(struct pci_bus *bus, unsigned int devfn, 318c2ecf20Sopenharmony_ci unsigned int reg) 328c2ecf20Sopenharmony_ci{ 338c2ecf20Sopenharmony_ci return ((bus->number & 0xff) << 16) | 348c2ecf20Sopenharmony_ci ((devfn & 0xff) << 8) | 358c2ecf20Sopenharmony_ci (reg & 0xfc); 368c2ecf20Sopenharmony_ci} 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic int 408c2ecf20Sopenharmony_cimace_pci_read_config(struct pci_bus *bus, unsigned int devfn, 418c2ecf20Sopenharmony_ci int reg, int size, u32 *val) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci u32 control = mace->pci.control; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci /* disable master aborts interrupts during config read */ 468c2ecf20Sopenharmony_ci mace->pci.control = control & ~MACEPCI_CONTROL_MAR_INT; 478c2ecf20Sopenharmony_ci mace->pci.config_addr = mkaddr(bus, devfn, reg); 488c2ecf20Sopenharmony_ci switch (size) { 498c2ecf20Sopenharmony_ci case 1: 508c2ecf20Sopenharmony_ci *val = mace->pci.config_data.b[(reg & 3) ^ 3]; 518c2ecf20Sopenharmony_ci break; 528c2ecf20Sopenharmony_ci case 2: 538c2ecf20Sopenharmony_ci *val = mace->pci.config_data.w[((reg >> 1) & 1) ^ 1]; 548c2ecf20Sopenharmony_ci break; 558c2ecf20Sopenharmony_ci case 4: 568c2ecf20Sopenharmony_ci *val = mace->pci.config_data.l; 578c2ecf20Sopenharmony_ci break; 588c2ecf20Sopenharmony_ci } 598c2ecf20Sopenharmony_ci /* ack possible master abort */ 608c2ecf20Sopenharmony_ci mace->pci.error &= ~MACEPCI_ERROR_MASTER_ABORT; 618c2ecf20Sopenharmony_ci mace->pci.control = control; 628c2ecf20Sopenharmony_ci /* 638c2ecf20Sopenharmony_ci * someone forgot to set the ultra bit for the onboard 648c2ecf20Sopenharmony_ci * scsi chips; we fake it here 658c2ecf20Sopenharmony_ci */ 668c2ecf20Sopenharmony_ci if (bus->number == 0 && reg == 0x40 && size == 4 && 678c2ecf20Sopenharmony_ci (devfn == (1 << 3) || devfn == (2 << 3))) 688c2ecf20Sopenharmony_ci *val |= 0x1000; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci DPRINTK("read%d: reg=%08x,val=%02x\n", size * 8, reg, *val); 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci return PCIBIOS_SUCCESSFUL; 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic int 768c2ecf20Sopenharmony_cimace_pci_write_config(struct pci_bus *bus, unsigned int devfn, 778c2ecf20Sopenharmony_ci int reg, int size, u32 val) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci mace->pci.config_addr = mkaddr(bus, devfn, reg); 808c2ecf20Sopenharmony_ci switch (size) { 818c2ecf20Sopenharmony_ci case 1: 828c2ecf20Sopenharmony_ci mace->pci.config_data.b[(reg & 3) ^ 3] = val; 838c2ecf20Sopenharmony_ci break; 848c2ecf20Sopenharmony_ci case 2: 858c2ecf20Sopenharmony_ci mace->pci.config_data.w[((reg >> 1) & 1) ^ 1] = val; 868c2ecf20Sopenharmony_ci break; 878c2ecf20Sopenharmony_ci case 4: 888c2ecf20Sopenharmony_ci mace->pci.config_data.l = val; 898c2ecf20Sopenharmony_ci break; 908c2ecf20Sopenharmony_ci } 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci DPRINTK("write%d: reg=%08x,val=%02x\n", size * 8, reg, val); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci return PCIBIOS_SUCCESSFUL; 958c2ecf20Sopenharmony_ci} 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistruct pci_ops mace_pci_ops = { 988c2ecf20Sopenharmony_ci .read = mace_pci_read_config, 998c2ecf20Sopenharmony_ci .write = mace_pci_write_config, 1008c2ecf20Sopenharmony_ci}; 101