chrp_pci.c 7.03 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
/*
2
 * BK Id: %F% %I% %G% %U% %#%
Linus Torvalds's avatar
Linus Torvalds committed
3
 */
Linus Torvalds's avatar
Linus Torvalds committed
4 5 6 7 8 9 10 11 12 13 14
/*
 * CHRP pci routines.
 */

#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/pci.h>
#include <linux/delay.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/ide.h>
Linus Torvalds's avatar
Linus Torvalds committed
15
#include <linux/bootmem.h>
Linus Torvalds's avatar
Linus Torvalds committed
16 17 18 19 20 21 22 23

#include <asm/io.h>
#include <asm/pgtable.h>
#include <asm/irq.h>
#include <asm/hydra.h>
#include <asm/prom.h>
#include <asm/gg2.h>
#include <asm/machdep.h>
Linus Torvalds's avatar
Linus Torvalds committed
24
#include <asm/sections.h>
Linus Torvalds's avatar
Linus Torvalds committed
25
#include <asm/pci-bridge.h>
26
#include <asm/open_pic.h>
Linus Torvalds's avatar
Linus Torvalds committed
27 28

/* LongTrail */
Linus Torvalds's avatar
Linus Torvalds committed
29 30
unsigned long gg2_pci_config_base;

Linus Torvalds's avatar
Linus Torvalds committed
31 32 33 34 35
/*
 * The VLSI Golden Gate II has only 512K of PCI configuration space, so we
 * limit the bus number to 3 bits
 */

36 37 38 39 40
int __chrp gg2_read_config(struct pci_bus *bus, unsigned int devfn, int off,
			   int len, u32 *val)
{
	volatile unsigned char *cfg_data;
	struct pci_controller *hose = bus->sysdata;
Linus Torvalds's avatar
Linus Torvalds committed
41

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
	if (bus->number > 7)
		return PCIBIOS_DEVICE_NOT_FOUND;
	/*
	 * Note: the caller has already checked that off is
	 * suitably aligned and that len is 1, 2 or 4.
	 */
	cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off);
	switch (len) {
	case 1:
		*val =  in_8((u8 *)cfg_data);
		break;
	case 2:
		*val = in_le16((u16 *)cfg_data);
		break;
	default:
		*val = in_le32((u32 *)cfg_data);
		break;
	}
	return PCIBIOS_SUCCESSFUL;
Linus Torvalds's avatar
Linus Torvalds committed
61 62
}

63 64
int __chrp gg2_write_config(struct pci_bus *bus, unsigned int devfn, int off,
			    int len, u32 val)
Linus Torvalds's avatar
Linus Torvalds committed
65
{
66 67
	volatile unsigned char *cfg_data;
	struct pci_controller *hose = bus->sysdata;
Linus Torvalds's avatar
Linus Torvalds committed
68

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
	if (bus->number > 7)
		return PCIBIOS_DEVICE_NOT_FOUND;
	/*
	 * Note: the caller has already checked that off is
	 * suitably aligned and that len is 1, 2 or 4.
	 */
	cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off);
	switch (len) {
	case 1:
		out_8((u8 *)cfg_data, val);
		break;
	case 2:
		out_le16((u16 *)cfg_data, val);
		break;
	default:
		out_le32((u32 *)cfg_data, val);
		break;
	}
	return PCIBIOS_SUCCESSFUL;
Linus Torvalds's avatar
Linus Torvalds committed
88 89
}

90
static struct pci_ops gg2_pci_ops =
Linus Torvalds's avatar
Linus Torvalds committed
91
{
92 93
	gg2_read_config,
	gg2_write_config
Linus Torvalds's avatar
Linus Torvalds committed
94
};
Linus Torvalds's avatar
Linus Torvalds committed
95

Linus Torvalds's avatar
Linus Torvalds committed
96 97 98
/*
 * Access functions for PCI config space using RTAS calls.
 */
99 100 101 102 103 104 105 106 107 108 109 110
int __chrp
rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
		 int len, u32 *val)
{
	unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
		| ((bus->number & 0xff) << 16);
        unsigned long ret = ~0UL;
	int rval;

	rval = call_rtas("read-pci-config", 2, 2, &ret, addr, len);
	*val = ret;
	return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
Linus Torvalds's avatar
Linus Torvalds committed
111 112
}

113 114 115 116 117 118 119
int __chrp
rtas_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
		  int len, u32 val)
{
	unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
		| ((bus->number & 0xff) << 16);
	int rval;
Linus Torvalds's avatar
Linus Torvalds committed
120

121 122 123
	rval = call_rtas("write-pci-config", 3, 1, NULL, addr, len, val);
	return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
}
Linus Torvalds's avatar
Linus Torvalds committed
124

Linus Torvalds's avatar
Linus Torvalds committed
125
static struct pci_ops rtas_pci_ops =
Linus Torvalds's avatar
Linus Torvalds committed
126
{
127 128
	rtas_read_config,
	rtas_write_config
Linus Torvalds's avatar
Linus Torvalds committed
129
};
Linus Torvalds's avatar
Linus Torvalds committed
130

131 132
volatile struct Hydra *Hydra = NULL;

Linus Torvalds's avatar
Linus Torvalds committed
133 134 135 136 137 138
int __init
hydra_init(void)
{
	struct device_node *np;

	np = find_devices("mac-io");
139
	if (np == NULL || np->n_addrs == 0)
Linus Torvalds's avatar
Linus Torvalds committed
140 141 142
		return 0;
	Hydra = ioremap(np->addrs[0].address, np->addrs[0].size);
	printk("Hydra Mac I/O at %x\n", np->addrs[0].address);
143 144
	printk("Hydra Feature_Control was %x",
	       in_le32(&Hydra->Feature_Control));
Linus Torvalds's avatar
Linus Torvalds committed
145 146 147 148 149 150 151 152
	out_le32(&Hydra->Feature_Control, (HYDRA_FC_SCC_CELL_EN |
					   HYDRA_FC_SCSI_CELL_EN |
					   HYDRA_FC_SCCA_ENABLE |
					   HYDRA_FC_SCCB_ENABLE |
					   HYDRA_FC_ARB_BYPASS |
					   HYDRA_FC_MPIC_ENABLE |
					   HYDRA_FC_SLOW_SCC_PCLK |
					   HYDRA_FC_MPIC_IS_MASTER));
153
	printk(", now %x\n", in_le32(&Hydra->Feature_Control));
Linus Torvalds's avatar
Linus Torvalds committed
154 155 156 157 158 159 160 161 162 163 164
	return 1;
}

void __init
chrp_pcibios_fixup(void)
{
	struct pci_dev *dev;
	struct device_node *np;

	/* PCI interrupts are controlled by the OpenPIC */
	pci_for_each_dev(dev) {
Linus Torvalds's avatar
Linus Torvalds committed
165
		np = pci_device_to_OF_node(dev);
Linus Torvalds's avatar
Linus Torvalds committed
166 167
		if ((np != 0) && (np->n_intrs > 0) && (np->intrs[0].line != 0))
			dev->irq = np->intrs[0].line;
Linus Torvalds's avatar
Linus Torvalds committed
168
		pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
Linus Torvalds's avatar
Linus Torvalds committed
169 170 171
	}
}

172 173 174 175 176 177
#define PRG_CL_RESET_VALID 0x00010000

static void __init
setup_python(struct pci_controller *hose, struct device_node *dev)
{
	u32 *reg, val;
178
	unsigned long addr = dev->addrs[0].address;
179

180
	setup_indirect_pci(hose, addr + 0xf8000, addr + 0xf8010);
181 182 183 184 185 186 187 188 189 190 191

	/* Clear the magic go-slow bit */
	reg = (u32 *) ioremap(dev->addrs[0].address + 0xf6000, 0x40);
	val = in_be32(&reg[12]);
	if (val & PRG_CL_RESET_VALID) {
		out_be32(&reg[12], val & ~PRG_CL_RESET_VALID);
		in_be32(&reg[12]);
	}
	iounmap(reg);
}

Linus Torvalds's avatar
Linus Torvalds committed
192 193
void __init
chrp_find_bridges(void)
Linus Torvalds's avatar
Linus Torvalds committed
194
{
Linus Torvalds's avatar
Linus Torvalds committed
195
	struct device_node *dev;
Linus Torvalds's avatar
Linus Torvalds committed
196
	int *bus_range;
Linus Torvalds's avatar
Linus Torvalds committed
197
	int len, index = -1;
Linus Torvalds's avatar
Linus Torvalds committed
198 199
	struct pci_controller *hose;
	unsigned int *dma;
Linus Torvalds's avatar
Linus Torvalds committed
200 201
	char *model, *machine;
	int is_longtrail = 0, is_mot = 0;
Linus Torvalds's avatar
Linus Torvalds committed
202
	struct device_node *root = find_path_device("/");
Linus Torvalds's avatar
Linus Torvalds committed
203

Linus Torvalds's avatar
Linus Torvalds committed
204 205 206 207 208 209 210 211 212 213 214 215
	/*
	 * The PCI host bridge nodes on some machines don't have
	 * properties to adequately identify them, so we have to
	 * look at what sort of machine this is as well.
	 */
	machine = get_property(root, "model", NULL);
	if (machine != NULL) {
		is_longtrail = strncmp(machine, "IBM,LongTrail", 13) == 0;
		is_mot = strncmp(machine, "MOT", 3) == 0;
	}
	for (dev = root->child; dev != NULL; dev = dev->sibling) {
		if (dev->type == NULL || strcmp(dev->type, "pci") != 0)
Linus Torvalds's avatar
Linus Torvalds committed
216
			continue;
Linus Torvalds's avatar
Linus Torvalds committed
217 218 219
		++index;
		/* The GG2 bridge on the LongTrail doesn't have an address */
		if (dev->n_addrs < 1 && !is_longtrail) {
Linus Torvalds's avatar
Linus Torvalds committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
			printk(KERN_WARNING "Can't use %s: no address\n",
			       dev->full_name);
			continue;
		}
		bus_range = (int *) get_property(dev, "bus-range", &len);
		if (bus_range == NULL || len < 2 * sizeof(int)) {
			printk(KERN_WARNING "Can't get bus-range for %s\n",
				dev->full_name);
			continue;
		}
		if (bus_range[1] == bus_range[0])
			printk(KERN_INFO "PCI bus %d", bus_range[0]);
		else
			printk(KERN_INFO "PCI buses %d..%d",
			       bus_range[0], bus_range[1]);
Linus Torvalds's avatar
Linus Torvalds committed
235 236 237 238
		printk(" controlled by %s", dev->type);
		if (dev->n_addrs > 0)
			printk(" at %x", dev->addrs[0].address);
		printk("\n");
Linus Torvalds's avatar
Linus Torvalds committed
239 240 241 242 243 244 245 246 247 248 249

		hose = pcibios_alloc_controller();
		if (!hose) {
			printk("Can't allocate PCI controller structure for %s\n",
				dev->full_name);
			continue;
		}
		hose->arch_data = dev;
		hose->first_busno = bus_range[0];
		hose->last_busno = bus_range[1];

Linus Torvalds's avatar
Linus Torvalds committed
250 251 252 253
		model = get_property(dev, "model", NULL);
		if (model == NULL)
			model = "<none>";
		if (device_is_compatible(dev, "IBM,python")) {
254
			setup_python(hose, dev);
Linus Torvalds's avatar
Linus Torvalds committed
255 256 257 258 259
		} else if (is_mot
			   || strncmp(model, "Motorola, Grackle", 17) == 0) {
			setup_grackle(hose);
		} else if (is_longtrail) {
			hose->ops = &gg2_pci_ops;
260
			hose->cfg_data = (unsigned char *)
Linus Torvalds's avatar
Linus Torvalds committed
261
				ioremap(GG2_PCI_CONFIG_BASE, 0x80000);
262
			gg2_pci_config_base = (unsigned long) hose->cfg_data;
Linus Torvalds's avatar
Linus Torvalds committed
263 264 265 266 267
		} else {
			printk("No methods for %s (model %s), using RTAS\n",
			       dev->full_name, model);
			hose->ops = &rtas_pci_ops;
		}
Linus Torvalds's avatar
Linus Torvalds committed
268

Linus Torvalds's avatar
Linus Torvalds committed
269
		pci_process_bridge_OF_ranges(hose, dev, index == 0);
Linus Torvalds's avatar
Linus Torvalds committed
270 271 272 273 274 275 276 277 278 279

		/* check the first bridge for a property that we can
		   use to set pci_dram_offset */
		dma = (unsigned int *)
			get_property(dev, "ibm,dma-ranges", &len);
		if (index == 0 && dma != NULL && len >= 6 * sizeof(*dma)) {
			pci_dram_offset = dma[2] - dma[3];
			printk("pci_dram_offset = %lx\n", pci_dram_offset);
		}
	}
Linus Torvalds's avatar
Linus Torvalds committed
280 281 282

	ppc_md.pcibios_fixup = chrp_pcibios_fixup;
}