--- cpufreq/arch/i386/kernel/cpu/cpufreq/longhaul.c~ 2005-06-08 19:45:25.997290007 -0700 +++ cpufreq/arch/i386/kernel/cpu/cpufreq/longhaul.c 2005-06-08 19:53:02.248684049 -0700 @@ -116,17 +116,57 @@ static int longhaul_get_cpu_mult(void) return eblcr_table[invalue]; } +static u16 cmd_state[64]; + +/* + * Get current PCI bus master state for all devices + * and clear bus master bit + */ +static void disable_mastering(void) +{ + struct pci_dev *dev; + u16 pci_cmd; + int i; + + dev = NULL; + i = 0; + do { + dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev); + if (dev != NULL) { + pci_read_config_word(dev, PCI_COMMAND, &pci_cmd); + cmd_state[i++] = pci_cmd; + pci_cmd &= ~PCI_COMMAND_MASTER; + pci_write_config_word(dev, PCI_COMMAND, pci_cmd); + } + } while (dev != NULL); +} + +/* + * Restore PCI bus master state for all devices + */ +static void restore_mastering(void) +{ + struct pci_dev *dev; + u16 pci_cmd; + int i; + + dev = NULL; + i = 0; + do { + dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev); + if (dev != NULL) { + pci_cmd = cmd_state[i++]; + pci_write_config_byte(dev, PCI_COMMAND, pci_cmd); + } + } while (dev != NULL); +} static void do_powersaver(union msr_longhaul *longhaul, unsigned int clock_ratio_index) { - struct pci_dev *dev; unsigned long flags; unsigned int tmp_mask; int version; - int i; - u16 pci_cmd; - u16 cmd_state[64]; switch (cpu_model) { case CPU_EZRA_T: @@ -147,22 +187,7 @@ static void do_powersaver(union msr_long preempt_disable(); local_irq_save(flags); - - /* - * get current pci bus master state for all devices - * and clear bus master bit - */ - dev = NULL; - i = 0; - do { - dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev); - if (dev != NULL) { - pci_read_config_word(dev, PCI_COMMAND, &pci_cmd); - cmd_state[i++] = pci_cmd; - pci_cmd &= ~PCI_COMMAND_MASTER; - pci_write_config_word(dev, PCI_COMMAND, pci_cmd); - } - } while (dev != NULL); + disable_mastering(); tmp_mask=inb(0x21); /* works on C3. save mask. */ outb(0xFE,0x21); /* TMR0 only */ @@ -178,16 +203,8 @@ static void do_powersaver(union msr_long outb(tmp_mask,0x21); /* restore mask */ - /* restore pci bus master state for all devices */ - dev = NULL; - i = 0; - do { - dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev); - if (dev != NULL) { - pci_cmd = cmd_state[i++]; - pci_write_config_byte(dev, PCI_COMMAND, pci_cmd); - } - } while (dev != NULL); + restore_mastering(); + local_irq_restore(flags); preempt_enable();