Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 4247
b: refs/heads/master
c: 3b520b2
h: refs/heads/master
i:
  4245: db37571
  4243: 9ecd421
  4239: aafc6fc
v: v3
  • Loading branch information
Shaohua Li authored and Linus Torvalds committed Jul 8, 2005
1 parent 801076c commit 46bfc18
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 36 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 01d299367fe868851a632cfbdb606845f57682aa
refs/heads/master: 3b520b238e018ef0e9d11c9115d5e7d9419c4ef9
5 changes: 5 additions & 0 deletions trunk/arch/i386/kernel/cpu/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ void __devinit identify_cpu(struct cpuinfo_x86 *c)
if (c == &boot_cpu_data)
sysenter_setup();
enable_sep_cpu();

if (c == &boot_cpu_data)
mtrr_bp_init();
else
mtrr_ap_init();
}

#ifdef CONFIG_X86_HT
Expand Down
22 changes: 11 additions & 11 deletions trunk/arch/i386/kernel/cpu/mtrr/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ void __init get_mtrr_state(void)
mtrr_state.enabled = (lo & 0xc00) >> 10;
}

/* Free resources associated with a struct mtrr_state */
void __init finalize_mtrr_state(void)
{
kfree(mtrr_state.var_ranges);
mtrr_state.var_ranges = NULL;
}

/* Some BIOS's are fucked and don't set all MTRRs the same! */
void __init mtrr_state_warn(void)
{
Expand Down Expand Up @@ -334,6 +327,9 @@ static void generic_set_mtrr(unsigned int reg, unsigned long base,
*/
{
unsigned long flags;
struct mtrr_var_range *vr;

vr = &mtrr_state.var_ranges[reg];

local_irq_save(flags);
prepare_set();
Expand All @@ -342,11 +338,15 @@ static void generic_set_mtrr(unsigned int reg, unsigned long base,
/* The invalid bit is kept in the mask, so we simply clear the
relevant mask register to disable a range. */
mtrr_wrmsr(MTRRphysMask_MSR(reg), 0, 0);
memset(vr, 0, sizeof(struct mtrr_var_range));
} else {
mtrr_wrmsr(MTRRphysBase_MSR(reg), base << PAGE_SHIFT | type,
(base & size_and_mask) >> (32 - PAGE_SHIFT));
mtrr_wrmsr(MTRRphysMask_MSR(reg), -size << PAGE_SHIFT | 0x800,
(-size & size_and_mask) >> (32 - PAGE_SHIFT));
vr->base_lo = base << PAGE_SHIFT | type;
vr->base_hi = (base & size_and_mask) >> (32 - PAGE_SHIFT);
vr->mask_lo = -size << PAGE_SHIFT | 0x800;
vr->mask_hi = (-size & size_and_mask) >> (32 - PAGE_SHIFT);

mtrr_wrmsr(MTRRphysBase_MSR(reg), vr->base_lo, vr->base_hi);
mtrr_wrmsr(MTRRphysMask_MSR(reg), vr->mask_lo, vr->mask_hi);
}

post_set();
Expand Down
76 changes: 53 additions & 23 deletions trunk/arch/i386/kernel/cpu/mtrr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ int mtrr_add_page(unsigned long base, unsigned long size,

error = -EINVAL;

/* No CPU hotplug when we change MTRR entries */
lock_cpu_hotplug();
/* Search for existing MTRR */
down(&main_lock);
for (i = 0; i < num_var_ranges; ++i) {
Expand Down Expand Up @@ -372,6 +374,7 @@ int mtrr_add_page(unsigned long base, unsigned long size,
error = i;
out:
up(&main_lock);
unlock_cpu_hotplug();
return error;
}

Expand Down Expand Up @@ -461,6 +464,8 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size)
return -ENXIO;

max = num_var_ranges;
/* No CPU hotplug when we change MTRR entries */
lock_cpu_hotplug();
down(&main_lock);
if (reg < 0) {
/* Search for existing MTRR */
Expand Down Expand Up @@ -501,6 +506,7 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size)
error = reg;
out:
up(&main_lock);
unlock_cpu_hotplug();
return error;
}
/**
Expand Down Expand Up @@ -544,21 +550,9 @@ static void __init init_ifs(void)
centaur_init_mtrr();
}

static void __init init_other_cpus(void)
{
if (use_intel())
get_mtrr_state();

/* bring up the other processors */
set_mtrr(~0U,0,0,0);

if (use_intel()) {
finalize_mtrr_state();
mtrr_state_warn();
}
}


/* The suspend/resume methods are only for CPU without MTRR. CPU using generic
* MTRR driver doesn't require this
*/
struct mtrr_value {
mtrr_type ltype;
unsigned long lbase;
Expand Down Expand Up @@ -611,13 +605,13 @@ static struct sysdev_driver mtrr_sysdev_driver = {


/**
* mtrr_init - initialize mtrrs on the boot CPU
* mtrr_bp_init - initialize mtrrs on the boot CPU
*
* This needs to be called early; before any of the other CPUs are
* initialized (i.e. before smp_init()).
*
*/
static int __init mtrr_init(void)
void __init mtrr_bp_init(void)
{
init_ifs();

Expand Down Expand Up @@ -674,12 +668,48 @@ static int __init mtrr_init(void)
if (mtrr_if) {
set_num_var_ranges();
init_table();
init_other_cpus();

return sysdev_driver_register(&cpu_sysdev_class,
&mtrr_sysdev_driver);
if (use_intel())
get_mtrr_state();
}
return -ENXIO;
}

subsys_initcall(mtrr_init);
void mtrr_ap_init(void)
{
unsigned long flags;

if (!mtrr_if || !use_intel())
return;
/*
* Ideally we should hold main_lock here to avoid mtrr entries changed,
* but this routine will be called in cpu boot time, holding the lock
* breaks it. This routine is called in two cases: 1.very earily time
* of software resume, when there absolutely isn't mtrr entry changes;
* 2.cpu hotadd time. We let mtrr_add/del_page hold cpuhotplug lock to
* prevent mtrr entry changes
*/
local_irq_save(flags);

mtrr_if->set_all();

local_irq_restore(flags);
}

static int __init mtrr_init_finialize(void)
{
if (!mtrr_if)
return 0;
if (use_intel())
mtrr_state_warn();
else {
/* The CPUs haven't MTRR and seemes not support SMP. They have
* specific drivers, we use a tricky method to support
* suspend/resume for them.
* TBD: is there any system with such CPU which supports
* suspend/resume? if no, we should remove the code.
*/
sysdev_driver_register(&cpu_sysdev_class,
&mtrr_sysdev_driver);
}
return 0;
}
subsys_initcall(mtrr_init_finialize);
1 change: 0 additions & 1 deletion trunk/arch/i386/kernel/cpu/mtrr/mtrr.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ extern struct mtrr_ops * mtrr_if;

extern unsigned int num_var_ranges;

void finalize_mtrr_state(void);
void mtrr_state_warn(void);
char *mtrr_attrib_to_str(int x);
void mtrr_wrmsr(unsigned, unsigned, unsigned);
Expand Down
1 change: 1 addition & 0 deletions trunk/arch/i386/power/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void __restore_processor_state(struct saved_context *ctxt)

fix_processor_context();
do_fpu_end();
mtrr_ap_init();
}

void restore_processor_state(void)
Expand Down
4 changes: 4 additions & 0 deletions trunk/arch/x86_64/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,10 @@ void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
#ifdef CONFIG_X86_MCE
mcheck_init(c);
#endif
if (c == &boot_cpu_data)
mtrr_bp_init();
else
mtrr_ap_init();
#ifdef CONFIG_NUMA
if (c != &boot_cpu_data)
numa_add_cpu(c - cpu_data);
Expand Down
1 change: 1 addition & 0 deletions trunk/arch/x86_64/kernel/suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void __restore_processor_state(struct saved_context *ctxt)
fix_processor_context();

do_fpu_end();
mtrr_ap_init();
}

void restore_processor_state(void)
Expand Down
8 changes: 8 additions & 0 deletions trunk/include/asm-i386/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -694,4 +694,12 @@ extern unsigned long boot_option_idle_override;
extern void enable_sep_cpu(void);
extern int sysenter_setup(void);

#ifdef CONFIG_MTRR
extern void mtrr_ap_init(void);
extern void mtrr_bp_init(void);
#else
#define mtrr_ap_init() do {} while (0)
#define mtrr_bp_init() do {} while (0)
#endif

#endif /* __ASM_I386_PROCESSOR_H */
7 changes: 7 additions & 0 deletions trunk/include/asm-x86_64/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ extern void pda_init(int);
extern void early_idt_handler(void);

extern void mcheck_init(struct cpuinfo_x86 *c);
#ifdef CONFIG_MTRR
extern void mtrr_ap_init(void);
extern void mtrr_bp_init(void);
#else
#define mtrr_ap_init() do {} while (0)
#define mtrr_bp_init() do {} while (0)
#endif
extern void init_memory_mapping(unsigned long start, unsigned long end);

extern void system_call(void);
Expand Down

0 comments on commit 46bfc18

Please sign in to comment.