Commit 4ce2b158 authored by Hanna V. Linder's avatar Hanna V. Linder Committed by Greg Kroah-Hartman

[PATCH] PCI: sh pci_ops changes

sh pci ops changes
parent cd7ab7bd
...@@ -31,76 +31,57 @@ struct pci_fixup pcibios_fixups[] = { ...@@ -31,76 +31,57 @@ struct pci_fixup pcibios_fixups[] = {
{0, 0, 0, NULL} {0, 0, 0, NULL}
}; };
#define BBA_SELECTED(dev) (dev->bus->number==0 && dev->devfn==0) #define BBA_SELECTED(bus,devfn) (bus->number==0 && devfn==0)
static int gapspci_read_config_byte(struct pci_dev *dev, int where, static int gapspci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 * val)
u8 * val)
{ {
if (BBA_SELECTED(dev)) switch (size) {
*val = inb(GAPSPCI_BBA_CONFIG+where); case 1:
else if (BBA_SELECTED(bus, devfn))
*val = 0xff; *val = (u8)inb(GAPSPCI_BBA_CONFIG+where);
else
*val = (u8)0xff;
break;
case 2:
if (BBA_SELECTED(bus, devfn))
*val = (u16)inw(GAPSPCI_BBA_CONFIG+where);
else
*val = (u16)0xffff;
break;
case 4:
if (BBA_SELECTED(bus, devfn))
*val = inl(GAPSPCI_BBA_CONFIG+where);
else
*val = 0xffffffff;
break;
}
return PCIBIOS_SUCCESSFUL; return PCIBIOS_SUCCESSFUL;
} }
static int gapspci_read_config_word(struct pci_dev *dev, int where, static int gapspci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val)
u16 * val)
{
if (BBA_SELECTED(dev))
*val = inw(GAPSPCI_BBA_CONFIG+where);
else
*val = 0xffff;
return PCIBIOS_SUCCESSFUL;
}
static int gapspci_read_config_dword(struct pci_dev *dev, int where,
u32 * val)
{ {
if (BBA_SELECTED(dev)) if (BBA_SELECTED(bus, devfn)) {
*val = inl(GAPSPCI_BBA_CONFIG+where); switch (size) {
else case 1:
*val = 0xffffffff; if (BBA_SELECTED(bus, devfn))
outb((u8)val, GAPSPCI_BBA_CONFIG+where);
return PCIBIOS_SUCCESSFUL; break;
} case 2:
if (BBA_SELECTED(bus, devfn))
static int gapspci_write_config_byte(struct pci_dev *dev, int where, outw((u16)val, GAPSPCI_BBA_CONFIG+where);
u8 val) break;
{ case 4:
if (BBA_SELECTED(dev)) if (BBA_SELECTED(bus, devfn))
outb(val, GAPSPCI_BBA_CONFIG+where); outl(val, GAPSPCI_BBA_CONFIG+where);
break;
return PCIBIOS_SUCCESSFUL; }
} }
return PCIBIOS_SUCCESSFUL;
static int gapspci_write_config_word(struct pci_dev *dev, int where,
u16 val)
{
if (BBA_SELECTED(dev))
outw(val, GAPSPCI_BBA_CONFIG+where);
return PCIBIOS_SUCCESSFUL;
}
static int gapspci_write_config_dword(struct pci_dev *dev, int where,
u32 val)
{
if (BBA_SELECTED(dev))
outl(val, GAPSPCI_BBA_CONFIG+where);
return PCIBIOS_SUCCESSFUL;
} }
static struct pci_ops pci_config_ops = { static struct pci_ops pci_config_ops = {
gapspci_read_config_byte, .read = gapspci_read,
gapspci_read_config_word, .write = gapspci_write,
gapspci_read_config_dword,
gapspci_write_config_byte,
gapspci_write_config_word,
gapspci_write_config_dword
}; };
...@@ -143,7 +124,7 @@ void __init pcibios_fixup_bus(struct pci_bus *bus) ...@@ -143,7 +124,7 @@ void __init pcibios_fixup_bus(struct pci_bus *bus)
for (ln=bus->devices.next; ln != &bus->devices; ln=ln->next) { for (ln=bus->devices.next; ln != &bus->devices; ln=ln->next) {
dev = pci_dev_b(ln); dev = pci_dev_b(ln);
if (!BBA_SELECTED(dev)) continue; if (!BBA_SELECTED(bus, dev->devfn)) continue;
printk("PCI: MMIO fixup to %s\n", dev->name); printk("PCI: MMIO fixup to %s\n", dev->name);
dev->resource[1].start=0x01001700; dev->resource[1].start=0x01001700;
......
...@@ -41,14 +41,14 @@ struct pci_ops *pci_root_ops; ...@@ -41,14 +41,14 @@ struct pci_ops *pci_root_ops;
#ifdef CONFIG_PCI_DIRECT #ifdef CONFIG_PCI_DIRECT
#define CONFIG_CMD(dev, where) (0x80000000 | (dev->bus->number << 16) | (dev->devfn << 8) | (where & ~3)) #define CONFIG_CMD(bus, devfn, where) (0x80000000 | (bus->number << 16) | (devfn << 8) | (where & ~3))
#define PCI_REG(reg) (SH7751_PCIREG_BASE+reg) #define PCI_REG(reg) (SH7751_PCIREG_BASE+reg)
/* /*
* Functions for accessing PCI configuration space with type 1 accesses * Functions for accessing PCI configuration space with type 1 accesses
*/ */
static int pci_conf1_read_config_byte(struct pci_dev *dev, int where, u8 *value) static int pci_conf1_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
{ {
u32 word; u32 word;
unsigned long flags; unsigned long flags;
...@@ -57,144 +57,88 @@ static int pci_conf1_read_config_byte(struct pci_dev *dev, int where, u8 *value) ...@@ -57,144 +57,88 @@ static int pci_conf1_read_config_byte(struct pci_dev *dev, int where, u8 *value)
* so we must do byte alignment by hand * so we must do byte alignment by hand
*/ */
save_and_cli(flags); save_and_cli(flags);
outl(CONFIG_CMD(dev,where), PCI_REG(SH7751_PCIPAR)); outl(CONFIG_CMD(bus,devfn,where), PCI_REG(SH7751_PCIPAR));
word = inl(PCI_REG(SH7751_PCIPDR)); word = inl(PCI_REG(SH7751_PCIPDR));
restore_flags(flags); restore_flags(flags);
switch (where & 0x3) {
case 3:
*value = (u8)(word >> 24);
break;
case 2:
*value = (u8)(word >> 16);
break;
case 1:
*value = (u8)(word >> 8);
break;
default:
*value = (u8)word;
break;
}
PCIDBG(4,"pci_conf1_read_config_byte@0x%08x=0x%x\n",
CONFIG_CMD(dev,where),*value);
return PCIBIOS_SUCCESSFUL;
}
static int pci_conf1_read_config_word(struct pci_dev *dev, int where, u16 *value) switch (size) {
{
u32 word;
unsigned long flags;
/* PCIPDR may only be accessed as 32 bit words,
* so we must do word alignment by hand
*/
save_and_cli(flags);
outl(CONFIG_CMD(dev,where), PCI_REG(SH7751_PCIPAR));
word = inl(PCI_REG(SH7751_PCIPDR));
restore_flags(flags);
switch (where & 0x3) {
case 3:
// This should never happen...
printk(KERN_ERR "PCI BIOS: read_config_word: Illegal u16 alignment");
return PCIBIOS_BAD_REGISTER_NUMBER;
case 2:
*value = (u16)(word >> 16);
break;
case 1: case 1:
*value = (u16)(word >> 8); switch (where & 0x3) {
break; case 3:
default: *value = (u8)(word >> 24);
*value = (u16)word; break;
case 2:
*value = (u8)(word >> 16);
break;
case 1:
*value = (u8)(word >> 8);
break;
default:
*value = (u8)word;
break;
}
case 2:
switch (where & 0x3) {
case 3: /*This should never happen.*/
printk(KERN_ERR "PCI BIOS: read_config: Illegal u16 alignment");
return PCIBIOS_BAD_REGISTER_NUMBER;
case 2:
*value = (u16)(word >> 16);
break;
case 1:
*value = (u16)(word >> 8);
break;
default:
*value = (u16)word;
break;
}
case 4:
*value = word;
break; break;
} }
PCIDBG(4,"pci_conf1_read_config_word@0x%08x=0x%x\n", PCIDBG(4,"pci_conf1_read@0x%08x=0x%x\n", CONFIG_CMD(bus,devfn,where),*value);
CONFIG_CMD(dev,where),*value);
return PCIBIOS_SUCCESSFUL;
}
static int pci_conf1_read_config_dword(struct pci_dev *dev, int where, u32 *value)
{
unsigned long flags;
save_and_cli(flags);
outl(CONFIG_CMD(dev,where), PCI_REG(SH7751_PCIPAR));
*value = inl(PCI_REG(SH7751_PCIPDR));
restore_flags(flags);
PCIDBG(4,"pci_conf1_read_config_dword@0x%08x=0x%x\n",
CONFIG_CMD(dev,where),*value);
return PCIBIOS_SUCCESSFUL; return PCIBIOS_SUCCESSFUL;
} }
static int pci_conf1_write_config_byte(struct pci_dev *dev, int where, u8 value) /*
* Since SH7751 only does 32bit access we'll have to do a read,mask,write operation.
* We'll allow an odd byte offset, though it should be illegal.
*/
static int pci_conf1_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
{ {
u32 word; u32 word,mask;
u32 shift = (where & 3) * 8;
u32 mask = ((1 << 8) - 1) << shift; // create the byte mask
unsigned long flags; unsigned long flags;
/* Since SH7751 only does 32bit access we'll have to do a
* read,mask,write operation
*/
save_and_cli(flags);
outl(CONFIG_CMD(dev,where), PCI_REG(SH7751_PCIPAR));
word = inl(PCI_REG(SH7751_PCIPDR)) ;
word &= ~mask;
word |= value << shift;
outl(word, PCI_REG(SH7751_PCIPDR));
restore_flags(flags);
PCIDBG(4,"pci_conf1_write_config_byte@0x%08x=0x%x\n",
CONFIG_CMD(dev,where),word);
return PCIBIOS_SUCCESSFUL;
}
static int pci_conf1_write_config_word(struct pci_dev *dev, int where, u16 value)
{
u32 word;
u32 shift = (where & 3) * 8; u32 shift = (where & 3) * 8;
u32 mask = ((1 << 16) - 1) << shift; // create the word mask
unsigned long flags;
/* Since SH7751 only does 32bit access we'll have to do a if(size == 1) {
* read,mask,write operation. We'll allow an odd byte offset, mask = ((1 << 8) - 1) << shift; // create the byte mask
* though it should be illegal. } else if(size == 2){
*/ if(shift == 24)
if (shift == 24) return PCIBIOS_BAD_REGISTER_NUMBER;
return PCIBIOS_BAD_REGISTER_NUMBER; mask = ((1 << 16) - 1) << shift; // create the word mask
}
save_and_cli(flags); save_and_cli(flags);
outl(CONFIG_CMD(dev,where), PCI_REG(SH7751_PCIPAR)); outl(CONFIG_CMD(bus,devfn,where), PCI_REG(SH7751_PCIPAR));
if(size == 4){
outl(value, PCI_REG(SH7751_PCIPDR));
restore_flags(flags);
PCIDBG(4,"pci_conf1_write@0x%08x=0x%x\n", CONFIG_CMD(bus,devfn,where),value);
return PCIBIOS_SUCCESSFUL;
}
word = inl(PCI_REG(SH7751_PCIPDR)) ; word = inl(PCI_REG(SH7751_PCIPDR)) ;
word &= ~mask; word &= ~mask;
word |= value << shift; word |= value << shift;
outl(word, PCI_REG(SH7751_PCIPDR));
outl(value, PCI_REG(SH7751_PCIPDR));
restore_flags(flags);
PCIDBG(4,"pci_conf1_write_config_word@0x%08x=0x%x\n",
CONFIG_CMD(dev,where),word);
return PCIBIOS_SUCCESSFUL;
}
static int pci_conf1_write_config_dword(struct pci_dev *dev, int where, u32 value)
{
unsigned long flags;
save_and_cli(flags);
outl(CONFIG_CMD(dev,where), PCI_REG(SH7751_PCIPAR));
outl(value, PCI_REG(SH7751_PCIPDR));
restore_flags(flags); restore_flags(flags);
PCIDBG(4,"pci_conf1_write_config_dword@0x%08x=0x%x\n", PCIDBG(4,"pci_conf1_write@0x%08x=0x%x\n", CONFIG_CMD(bus,devfn,where),word);
CONFIG_CMD(dev,where),value);
return PCIBIOS_SUCCESSFUL; return PCIBIOS_SUCCESSFUL;
} }
#undef CONFIG_CMD #undef CONFIG_CMD
static struct pci_ops pci_direct_conf1 = { static struct pci_ops pci_direct_conf1 = {
pci_conf1_read_config_byte, .read = pci_conf1_read,
pci_conf1_read_config_word, .write = pci_conf1_write,
pci_conf1_read_config_dword,
pci_conf1_write_config_byte,
pci_conf1_write_config_word,
pci_conf1_write_config_dword
}; };
struct pci_ops * __init pci_check_direct(void) struct pci_ops * __init pci_check_direct(void)
......
...@@ -268,7 +268,7 @@ char * __init pcibios_setup(char *str) ...@@ -268,7 +268,7 @@ char * __init pcibios_setup(char *str)
#define SET_CONFIG_BITS(bus,devfn,where)\ #define SET_CONFIG_BITS(bus,devfn,where)\
(((bus) << 16) | ((devfn) << 8) | ((where) & ~3) | (bus!=0)) (((bus) << 16) | ((devfn) << 8) | ((where) & ~3) | (bus!=0))
#define CONFIG_CMD(dev, where) SET_CONFIG_BITS((dev)->bus->number,(dev)->devfn,where) #define CONFIG_CMD(bus, devfn, where) SET_CONFIG_BITS(bus->number,devfn,where)
static int CheckForMasterAbort(void) static int CheckForMasterAbort(void)
...@@ -284,79 +284,53 @@ static int CheckForMasterAbort(void) ...@@ -284,79 +284,53 @@ static int CheckForMasterAbort(void)
} }
/* Write to config register */ /* Write to config register */
static int st40pci_read_config_byte(struct pci_dev *dev, int where, static int st40pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 * val)
u8 * val)
{ {
ST40PCI_WRITE(PAR, CONFIG_CMD(dev, where)); ST40PCI_WRITE(PAR, CONFIG_CMD(bus, devfn, where));
switch (size) {
*val = ST40PCI_READ_BYTE(PDR + (where & 3)); case 1:
*val = (u8)ST40PCI_READ_BYTE(PDR + (where & 3));
if (CheckForMasterAbort()) break;
*val = 0xff; case 2:
*val = (u16)ST40PCI_READ_SHORT(PDR + (where & 2));
break;
return PCIBIOS_SUCCESSFUL; case 4:
} *val = ST40PCI_READ(PDR);
break;
static int st40pci_read_config_word(struct pci_dev *dev, int where, }
u16 * val)
{
ST40PCI_WRITE(PAR, CONFIG_CMD(dev, where));
*val = ST40PCI_READ_SHORT(PDR + (where & 2));
if (CheckForMasterAbort())
*val = 0xffff;
return PCIBIOS_SUCCESSFUL;
}
static int st40pci_read_config_dword(struct pci_dev *dev, int where,
u32 * val)
{
ST40PCI_WRITE(PAR, CONFIG_CMD(dev, where));
*val = ST40PCI_READ(PDR);
if (CheckForMasterAbort())
*val = 0xffffffff;
return PCIBIOS_SUCCESSFUL;
}
static int st40pci_write_config_byte(struct pci_dev *dev, int where,
u8 val)
{
ST40PCI_WRITE(PAR, CONFIG_CMD(dev, where));
ST40PCI_WRITE_BYTE(PDR + (where & 3), val);
CheckForMasterAbort();
return PCIBIOS_SUCCESSFUL;
}
static int st40pci_write_config_word(struct pci_dev *dev, int where,
u16 val)
{
ST40PCI_WRITE(PAR, CONFIG_CMD(dev, where));
ST40PCI_WRITE_SHORT(PDR + (where & 2), val);
CheckForMasterAbort(); if (CheckForMasterAbort()){
switch (size) {
case 1:
*val = (u8)0xff;
break;
case 2:
*val = (u16)0xffff;
break;
case 4:
*val = 0xffffffff;
break;
}
}
return PCIBIOS_SUCCESSFUL; return PCIBIOS_SUCCESSFUL;
} }
static int st40pci_write_config_dword(struct pci_dev *dev, int where, static int st40pci_write(struct pci_bus *bus, unsigned int devfn; int where, int size, u32 val)
u32 val)
{ {
ST40PCI_WRITE(PAR, CONFIG_CMD(dev, where)); ST40PCI_WRITE(PAR, CONFIG_CMD(dev, where));
ST40PCI_WRITE(PDR, val); switch (size) {
case 1:
ST40PCI_WRITE_BYTE(PDR + (where & 3), (u8)val);
break;
case 2:
ST40PCI_WRITE_SHORT(PDR + (where & 2), (u16)val);
break;
case 4:
ST40PCI_WRITE(PDR, val);
break;
}
CheckForMasterAbort(); CheckForMasterAbort();
...@@ -364,12 +338,8 @@ static int st40pci_write_config_dword(struct pci_dev *dev, int where, ...@@ -364,12 +338,8 @@ static int st40pci_write_config_dword(struct pci_dev *dev, int where,
} }
static struct pci_ops pci_config_ops = { static struct pci_ops pci_config_ops = {
st40pci_read_config_byte, .read = st40pci_read,
st40pci_read_config_word, .write = st40pci_write,
st40pci_read_config_dword,
st40pci_write_config_byte,
st40pci_write_config_word,
st40pci_write_config_dword
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment