Path: blob/master/arch/mips/loongson2ef/common/cs5536/cs5536_isa.c
26495 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* the ISA Virtual Support Module of AMD CS55363*4* Copyright (C) 2007 Lemote, Inc.5* Author : jlliu, [email protected]6*7* Copyright (C) 2009 Lemote, Inc.8* Author: Wu Zhangjin, [email protected]9*/1011#include <linux/pci.h>12#include <cs5536/cs5536.h>13#include <cs5536/cs5536_pci.h>1415/* common variables for PCI_ISA_READ/WRITE_BAR */16static const u32 divil_msr_reg[6] = {17DIVIL_MSR_REG(DIVIL_LBAR_SMB), DIVIL_MSR_REG(DIVIL_LBAR_GPIO),18DIVIL_MSR_REG(DIVIL_LBAR_MFGPT), DIVIL_MSR_REG(DIVIL_LBAR_IRQ),19DIVIL_MSR_REG(DIVIL_LBAR_PMS), DIVIL_MSR_REG(DIVIL_LBAR_ACPI),20};2122static const u32 soft_bar_flag[6] = {23SOFT_BAR_SMB_FLAG, SOFT_BAR_GPIO_FLAG, SOFT_BAR_MFGPT_FLAG,24SOFT_BAR_IRQ_FLAG, SOFT_BAR_PMS_FLAG, SOFT_BAR_ACPI_FLAG,25};2627static const u32 sb_msr_reg[6] = {28SB_MSR_REG(SB_R0), SB_MSR_REG(SB_R1), SB_MSR_REG(SB_R2),29SB_MSR_REG(SB_R3), SB_MSR_REG(SB_R4), SB_MSR_REG(SB_R5),30};3132static const u32 bar_space_range[6] = {33CS5536_SMB_RANGE, CS5536_GPIO_RANGE, CS5536_MFGPT_RANGE,34CS5536_IRQ_RANGE, CS5536_PMS_RANGE, CS5536_ACPI_RANGE,35};3637static const int bar_space_len[6] = {38CS5536_SMB_LENGTH, CS5536_GPIO_LENGTH, CS5536_MFGPT_LENGTH,39CS5536_IRQ_LENGTH, CS5536_PMS_LENGTH, CS5536_ACPI_LENGTH,40};4142/*43* enable the divil module bar space.44*45* For all the DIVIL module LBAR, you should control the DIVIL LBAR reg46* and the RCONFx(0~5) reg to use the modules.47*/48static void divil_lbar_enable(void)49{50u32 hi, lo;51int offset;5253/*54* The DIVIL IRQ is not used yet. and make the RCONF0 reserved.55*/5657for (offset = DIVIL_LBAR_SMB; offset <= DIVIL_LBAR_PMS; offset++) {58_rdmsr(DIVIL_MSR_REG(offset), &hi, &lo);59hi |= 0x01;60_wrmsr(DIVIL_MSR_REG(offset), hi, lo);61}62}6364/*65* disable the divil module bar space.66*/67static void divil_lbar_disable(void)68{69u32 hi, lo;70int offset;7172for (offset = DIVIL_LBAR_SMB; offset <= DIVIL_LBAR_PMS; offset++) {73_rdmsr(DIVIL_MSR_REG(offset), &hi, &lo);74hi &= ~0x01;75_wrmsr(DIVIL_MSR_REG(offset), hi, lo);76}77}7879/*80* BAR write: write value to the n BAR81*/8283void pci_isa_write_bar(int n, u32 value)84{85u32 hi = 0, lo = value;8687if (value == PCI_BAR_RANGE_MASK) {88_rdmsr(GLCP_MSR_REG(GLCP_SOFT_COM), &hi, &lo);89lo |= soft_bar_flag[n];90_wrmsr(GLCP_MSR_REG(GLCP_SOFT_COM), hi, lo);91} else if (value & 0x01) {92/* NATIVE reg */93hi = 0x0000f001;94lo &= bar_space_range[n];95_wrmsr(divil_msr_reg[n], hi, lo);9697/* RCONFx is 4bytes in units for I/O space */98hi = ((value & 0x000ffffc) << 12) |99((bar_space_len[n] - 4) << 12) | 0x01;100lo = ((value & 0x000ffffc) << 12) | 0x01;101_wrmsr(sb_msr_reg[n], hi, lo);102}103}104105/*106* BAR read: read the n BAR107*/108109u32 pci_isa_read_bar(int n)110{111u32 conf_data = 0;112u32 hi, lo;113114_rdmsr(GLCP_MSR_REG(GLCP_SOFT_COM), &hi, &lo);115if (lo & soft_bar_flag[n]) {116conf_data = bar_space_range[n] | PCI_BASE_ADDRESS_SPACE_IO;117lo &= ~soft_bar_flag[n];118_wrmsr(GLCP_MSR_REG(GLCP_SOFT_COM), hi, lo);119} else {120_rdmsr(divil_msr_reg[n], &hi, &lo);121conf_data = lo & bar_space_range[n];122conf_data |= 0x01;123conf_data &= ~0x02;124}125return conf_data;126}127128/*129* isa_write: ISA write transfer130*131* We assume that this is not a bus master transfer.132*/133void pci_isa_write_reg(int reg, u32 value)134{135u32 hi = 0, lo = value;136u32 temp;137138switch (reg) {139case PCI_COMMAND:140if (value & PCI_COMMAND_IO)141divil_lbar_enable();142else143divil_lbar_disable();144break;145case PCI_STATUS:146_rdmsr(SB_MSR_REG(SB_ERROR), &hi, &lo);147temp = lo & 0x0000ffff;148if ((value & PCI_STATUS_SIG_TARGET_ABORT) &&149(lo & SB_TAS_ERR_EN))150temp |= SB_TAS_ERR_FLAG;151152if ((value & PCI_STATUS_REC_TARGET_ABORT) &&153(lo & SB_TAR_ERR_EN))154temp |= SB_TAR_ERR_FLAG;155156if ((value & PCI_STATUS_REC_MASTER_ABORT)157&& (lo & SB_MAR_ERR_EN))158temp |= SB_MAR_ERR_FLAG;159160if ((value & PCI_STATUS_DETECTED_PARITY)161&& (lo & SB_PARE_ERR_EN))162temp |= SB_PARE_ERR_FLAG;163164lo = temp;165_wrmsr(SB_MSR_REG(SB_ERROR), hi, lo);166break;167case PCI_CACHE_LINE_SIZE:168value &= 0x0000ff00;169_rdmsr(SB_MSR_REG(SB_CTRL), &hi, &lo);170hi &= 0xffffff00;171hi |= (value >> 8);172_wrmsr(SB_MSR_REG(SB_CTRL), hi, lo);173break;174case PCI_BAR0_REG:175pci_isa_write_bar(0, value);176break;177case PCI_BAR1_REG:178pci_isa_write_bar(1, value);179break;180case PCI_BAR2_REG:181pci_isa_write_bar(2, value);182break;183case PCI_BAR3_REG:184pci_isa_write_bar(3, value);185break;186case PCI_BAR4_REG:187pci_isa_write_bar(4, value);188break;189case PCI_BAR5_REG:190pci_isa_write_bar(5, value);191break;192case PCI_UART1_INT_REG:193_rdmsr(DIVIL_MSR_REG(PIC_YSEL_HIGH), &hi, &lo);194/* disable uart1 interrupt in PIC */195lo &= ~(0xf << 24);196if (value) /* enable uart1 interrupt in PIC */197lo |= (CS5536_UART1_INTR << 24);198_wrmsr(DIVIL_MSR_REG(PIC_YSEL_HIGH), hi, lo);199break;200case PCI_UART2_INT_REG:201_rdmsr(DIVIL_MSR_REG(PIC_YSEL_HIGH), &hi, &lo);202/* disable uart2 interrupt in PIC */203lo &= ~(0xf << 28);204if (value) /* enable uart2 interrupt in PIC */205lo |= (CS5536_UART2_INTR << 28);206_wrmsr(DIVIL_MSR_REG(PIC_YSEL_HIGH), hi, lo);207break;208case PCI_ISA_FIXUP_REG:209if (value) {210/* enable the TARGET ABORT/MASTER ABORT etc. */211_rdmsr(SB_MSR_REG(SB_ERROR), &hi, &lo);212lo |= 0x00000063;213_wrmsr(SB_MSR_REG(SB_ERROR), hi, lo);214}215break;216default:217/* ALL OTHER PCI CONFIG SPACE HEADER IS NOT IMPLEMENTED. */218break;219}220}221222/*223* isa_read: ISA read transfers224*225* We assume that this is not a bus master transfer.226*/227u32 pci_isa_read_reg(int reg)228{229u32 conf_data = 0;230u32 hi, lo;231232switch (reg) {233case PCI_VENDOR_ID:234conf_data =235CFG_PCI_VENDOR_ID(CS5536_ISA_DEVICE_ID, CS5536_VENDOR_ID);236break;237case PCI_COMMAND:238/* we just check the first LBAR for the IO enable bit, */239/* maybe we should changed later. */240_rdmsr(DIVIL_MSR_REG(DIVIL_LBAR_SMB), &hi, &lo);241if (hi & 0x01)242conf_data |= PCI_COMMAND_IO;243break;244case PCI_STATUS:245conf_data |= PCI_STATUS_66MHZ;246conf_data |= PCI_STATUS_DEVSEL_MEDIUM;247conf_data |= PCI_STATUS_FAST_BACK;248249_rdmsr(SB_MSR_REG(SB_ERROR), &hi, &lo);250if (lo & SB_TAS_ERR_FLAG)251conf_data |= PCI_STATUS_SIG_TARGET_ABORT;252if (lo & SB_TAR_ERR_FLAG)253conf_data |= PCI_STATUS_REC_TARGET_ABORT;254if (lo & SB_MAR_ERR_FLAG)255conf_data |= PCI_STATUS_REC_MASTER_ABORT;256if (lo & SB_PARE_ERR_FLAG)257conf_data |= PCI_STATUS_DETECTED_PARITY;258break;259case PCI_CLASS_REVISION:260_rdmsr(GLCP_MSR_REG(GLCP_CHIP_REV_ID), &hi, &lo);261conf_data = lo & 0x000000ff;262conf_data |= (CS5536_ISA_CLASS_CODE << 8);263break;264case PCI_CACHE_LINE_SIZE:265_rdmsr(SB_MSR_REG(SB_CTRL), &hi, &lo);266hi &= 0x000000f8;267conf_data = CFG_PCI_CACHE_LINE_SIZE(PCI_BRIDGE_HEADER_TYPE, hi);268break;269/*270* we only use the LBAR of DIVIL, no RCONF used.271* all of them are IO space.272*/273case PCI_BAR0_REG:274return pci_isa_read_bar(0);275break;276case PCI_BAR1_REG:277return pci_isa_read_bar(1);278break;279case PCI_BAR2_REG:280return pci_isa_read_bar(2);281break;282case PCI_BAR3_REG:283break;284case PCI_BAR4_REG:285return pci_isa_read_bar(4);286break;287case PCI_BAR5_REG:288return pci_isa_read_bar(5);289break;290case PCI_CARDBUS_CIS:291conf_data = PCI_CARDBUS_CIS_POINTER;292break;293case PCI_SUBSYSTEM_VENDOR_ID:294conf_data =295CFG_PCI_VENDOR_ID(CS5536_ISA_SUB_ID, CS5536_SUB_VENDOR_ID);296break;297case PCI_ROM_ADDRESS:298conf_data = PCI_EXPANSION_ROM_BAR;299break;300case PCI_CAPABILITY_LIST:301conf_data = PCI_CAPLIST_POINTER;302break;303case PCI_INTERRUPT_LINE:304/* no interrupt used here */305conf_data = CFG_PCI_INTERRUPT_LINE(0x00, 0x00);306break;307default:308break;309}310311return conf_data;312}313314/*315* The mfgpt timer interrupt is running early, so we must keep the south bridge316* mmio always enabled. Otherwise we may race with the PCI configuration which317* may temporarily disable it. When that happens and the timer interrupt fires,318* we are not able to clear it and the system will hang.319*/320static void cs5536_isa_mmio_always_on(struct pci_dev *dev)321{322dev->mmio_always_on = 1;323}324DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA,325PCI_CLASS_BRIDGE_ISA, 8, cs5536_isa_mmio_always_on);326327328