OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [acpi/] [processor.c] - Blame information for rev 1275

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * acpi_processor.c - ACPI Processor Driver ($Revision: 1.1.1.1 $)
3
 *
4
 *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5
 *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6
 *
7
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or (at
12
 *  your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful, but
15
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 *  General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License along
20
 *  with this program; if not, write to the Free Software Foundation, Inc.,
21
 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22
 *
23
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24
 *  TBD:
25
 *      1. Make # power/performance states dynamic.
26
 *      2. Support duty_cycle values that span bit 4.
27
 *      3. Optimize by having scheduler determine business instead of
28
 *         having us try to calculate it here.
29
 *      4. Need C1 timing -- must modify kernel (IRQ handler) to get this.
30
 */
31
 
32
#include <linux/kernel.h>
33
#include <linux/module.h>
34
#include <linux/init.h>
35
#include <linux/types.h>
36
#include <linux/pci.h>
37
#include <linux/pm.h>
38
#include <asm/io.h>
39
#include <asm/system.h>
40
#include <asm/delay.h>
41
#include <linux/compatmac.h>
42
#include <linux/proc_fs.h>
43
#include <acpi/acpi_bus.h>
44
#include <acpi/acpi_drivers.h>
45
 
46
 
47
#define _COMPONENT              ACPI_PROCESSOR_COMPONENT
48
ACPI_MODULE_NAME                ("acpi_processor")
49
 
50
MODULE_AUTHOR("Paul Diefenbaugh");
51
MODULE_DESCRIPTION(ACPI_PROCESSOR_DRIVER_NAME);
52
MODULE_LICENSE("GPL");
53
 
54
#define PREFIX                          "ACPI: "
55
 
56
#define US_TO_PM_TIMER_TICKS(t)         ((t * (PM_TIMER_FREQUENCY/1000)) / 1000)
57
#define C2_OVERHEAD                     4       /* 1us (3.579 ticks per us) */
58
#define C3_OVERHEAD                     4       /* 1us (3.579 ticks per us) */
59
 
60
#define ACPI_PROCESSOR_BUSY_METRIC      10
61
 
62
#define ACPI_PROCESSOR_MAX_POWER        ACPI_C_STATE_COUNT
63
#define ACPI_PROCESSOR_MAX_C2_LATENCY   100
64
#define ACPI_PROCESSOR_MAX_C3_LATENCY   1000
65
 
66
#define ACPI_PROCESSOR_MAX_PERFORMANCE  8
67
 
68
#define ACPI_PROCESSOR_MAX_THROTTLING   16
69
#define ACPI_PROCESSOR_MAX_THROTTLE     250     /* 25% */
70
#define ACPI_PROCESSOR_MAX_DUTY_WIDTH   4
71
 
72
#define ACPI_PROCESSOR_LIMIT_USER       0
73
#define ACPI_PROCESSOR_LIMIT_THERMAL    1
74
 
75
static int acpi_processor_add (struct acpi_device *device);
76
static int acpi_processor_remove (struct acpi_device *device, int type);
77
 
78
static struct acpi_driver acpi_processor_driver = {
79
        .name =         ACPI_PROCESSOR_DRIVER_NAME,
80
        .class =        ACPI_PROCESSOR_CLASS,
81
        .ids =          ACPI_PROCESSOR_HID,
82
        .ops =          {
83
                                .add =          acpi_processor_add,
84
                                .remove =       acpi_processor_remove,
85
                        },
86
};
87
 
88
/* Power Management */
89
 
90
struct acpi_processor_cx_policy {
91
        u32                     count;
92
        int                     state;
93
        struct {
94
                u32                     time;
95
                u32                     ticks;
96
                u32                     count;
97
                u32                     bm;
98
        }                       threshold;
99
};
100
 
101
struct acpi_processor_cx {
102
        u8                      valid;
103
        u32                     address;
104
        u32                     latency;
105
        u32                     latency_ticks;
106
        u32                     power;
107
        u32                     usage;
108
        struct acpi_processor_cx_policy promotion;
109
        struct acpi_processor_cx_policy demotion;
110
};
111
 
112
struct acpi_processor_power {
113
        int                     state;
114
        int                     default_state;
115
        u32                     bm_activity;
116
        struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
117
};
118
 
119
/* Performance Management */
120
 
121
struct acpi_pct_register {
122
        u8                      descriptor;
123
        u16                     length;
124
        u8                      space_id;
125
        u8                      bit_width;
126
        u8                      bit_offset;
127
        u8                      reserved;
128
        u64                     address;
129
} __attribute__ ((packed));
130
 
131
struct acpi_processor_px {
132
        acpi_integer            core_frequency;         /* megahertz */
133
        acpi_integer            power;                  /* milliWatts */
134
        acpi_integer            transition_latency;     /* microseconds */
135
        acpi_integer            bus_master_latency;     /* microseconds */
136
        acpi_integer            control;                /* control value */
137
        acpi_integer            status;                 /* success indicator */
138
};
139
 
140
struct acpi_processor_performance {
141
        int                     state;
142
        int                     platform_limit;
143
        u16                     control_register;
144
        u16                     status_register;
145
        u8                      control_register_bit_width;
146
        u8                      status_register_bit_width;
147
        int                     state_count;
148
        struct acpi_processor_px states[ACPI_PROCESSOR_MAX_PERFORMANCE];
149
};
150
 
151
 
152
/* Throttling Control */
153
 
154
struct acpi_processor_tx {
155
        u16                     power;
156
        u16                     performance;
157
};
158
 
159
struct acpi_processor_throttling {
160
        int                     state;
161
        u32                     address;
162
        u8                      duty_offset;
163
        u8                      duty_width;
164
        int                     state_count;
165
        struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING];
166
};
167
 
168
/* Limit Interface */
169
 
170
struct acpi_processor_lx {
171
        int                     px;             /* performace state */
172
        int                     tx;             /* throttle level */
173
};
174
 
175
struct acpi_processor_limit {
176
        struct acpi_processor_lx state;         /* current limit */
177
        struct acpi_processor_lx thermal;       /* thermal limit */
178
        struct acpi_processor_lx user;          /* user limit */
179
};
180
 
181
 
182
struct acpi_processor_flags {
183
        u8                      power:1;
184
        u8                      performance:1;
185
        u8                      throttling:1;
186
        u8                      limit:1;
187
        u8                      bm_control:1;
188
        u8                      bm_check:1;
189
        u8                      reserved:2;
190
};
191
 
192
struct acpi_processor {
193
        acpi_handle             handle;
194
        u32                     acpi_id;
195
        u32                     id;
196
        struct acpi_processor_flags flags;
197
        struct acpi_processor_power power;
198
        struct acpi_processor_performance performance;
199
        struct acpi_processor_throttling throttling;
200
        struct acpi_processor_limit limit;
201
};
202
 
203
struct acpi_processor_errata {
204
        u8                      smp;
205
        struct {
206
                u8                      throttle:1;
207
                u8                      fdma:1;
208
                u8                      reserved:6;
209
                u32                     bmisx;
210
        }                       piix4;
211
};
212
 
213
static struct acpi_processor    *processors[NR_CPUS];
214
static struct acpi_processor_errata errata;
215
static void (*pm_idle_save)(void);
216
 
217
 
218
/* --------------------------------------------------------------------------
219
                                Errata Handling
220
   -------------------------------------------------------------------------- */
221
 
222
int
223
acpi_processor_errata_piix4 (
224
        struct pci_dev          *dev)
225
{
226
        u8                      rev = 0;
227
        u8                      value1 = 0;
228
        u8                      value2 = 0;
229
 
230
        ACPI_FUNCTION_TRACE("acpi_processor_errata_piix4");
231
 
232
        if (!dev)
233
                return_VALUE(-EINVAL);
234
 
235
        /*
236
         * Note that 'dev' references the PIIX4 ACPI Controller.
237
         */
238
 
239
        pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
240
 
241
        switch (rev) {
242
        case 0:
243
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
244
                break;
245
        case 1:
246
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n"));
247
                break;
248
        case 2:
249
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n"));
250
                break;
251
        case 3:
252
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n"));
253
                break;
254
        default:
255
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n"));
256
                break;
257
        }
258
 
259
        switch (rev) {
260
 
261
        case 0:          /* PIIX4 A-step */
262
        case 1:         /* PIIX4 B-step */
263
                /*
264
                 * See specification changes #13 ("Manual Throttle Duty Cycle")
265
                 * and #14 ("Enabling and Disabling Manual Throttle"), plus
266
                 * erratum #5 ("STPCLK# Deassertion Time") from the January
267
                 * 2002 PIIX4 specification update.  Applies to only older
268
                 * PIIX4 models.
269
                 */
270
                errata.piix4.throttle = 1;
271
 
272
        case 2:         /* PIIX4E */
273
        case 3:         /* PIIX4M */
274
                /*
275
                 * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
276
                 * Livelock") from the January 2002 PIIX4 specification update.
277
                 * Applies to all PIIX4 models.
278
                 */
279
 
280
                /*
281
                 * BM-IDE
282
                 * ------
283
                 * Find the PIIX4 IDE Controller and get the Bus Master IDE
284
                 * Status register address.  We'll use this later to read
285
                 * each IDE controller's DMA status to make sure we catch all
286
                 * DMA activity.
287
                 */
288
                dev = pci_find_subsys(PCI_VENDOR_ID_INTEL,
289
                           PCI_DEVICE_ID_INTEL_82371AB,
290
                           PCI_ANY_ID, PCI_ANY_ID, NULL);
291
                if (dev)
292
                        errata.piix4.bmisx = pci_resource_start(dev, 4);
293
 
294
                /*
295
                 * Type-F DMA
296
                 * ----------
297
                 * Find the PIIX4 ISA Controller and read the Motherboard
298
                 * DMA controller's status to see if Type-F (Fast) DMA mode
299
                 * is enabled (bit 7) on either channel.  Note that we'll
300
                 * disable C3 support if this is enabled, as some legacy
301
                 * devices won't operate well if fast DMA is disabled.
302
                 */
303
                dev = pci_find_subsys(PCI_VENDOR_ID_INTEL,
304
                        PCI_DEVICE_ID_INTEL_82371AB_0,
305
                        PCI_ANY_ID, PCI_ANY_ID, NULL);
306
                if (dev) {
307
                        pci_read_config_byte(dev, 0x76, &value1);
308
                        pci_read_config_byte(dev, 0x77, &value2);
309
                        if ((value1 & 0x80) || (value2 & 0x80))
310
                                errata.piix4.fdma = 1;
311
                }
312
 
313
                break;
314
        }
315
 
316
        if (errata.piix4.bmisx)
317
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
318
                        "Bus master activity detection (BM-IDE) erratum enabled\n"));
319
        if (errata.piix4.fdma)
320
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
321
                        "Type-F DMA livelock erratum (C3 disabled)\n"));
322
 
323
        return_VALUE(0);
324
}
325
 
326
 
327
int
328
acpi_processor_errata (
329
        struct acpi_processor   *pr)
330
{
331
        int                     result = 0;
332
        struct pci_dev          *dev = NULL;
333
 
334
        ACPI_FUNCTION_TRACE("acpi_processor_errata");
335
 
336
        if (!pr)
337
                return_VALUE(-EINVAL);
338
 
339
        /*
340
         * PIIX4
341
         */
342
        dev = pci_find_subsys(PCI_VENDOR_ID_INTEL,
343
                PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID, PCI_ANY_ID, NULL);
344
        if (dev)
345
                result = acpi_processor_errata_piix4(dev);
346
 
347
        return_VALUE(result);
348
}
349
 
350
 
351
/* --------------------------------------------------------------------------
352
                                Power Management
353
   -------------------------------------------------------------------------- */
354
 
355
static inline u32
356
ticks_elapsed (
357
        u32                     t1,
358
        u32                     t2)
359
{
360
        if (t2 >= t1)
361
                return (t2 - t1);
362
        else if (!acpi_fadt.tmr_val_ext)
363
                return (((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
364
        else
365
                return ((0xFFFFFFFF - t1) + t2);
366
}
367
 
368
 
369
static void
370
acpi_processor_power_activate (
371
        struct acpi_processor   *pr,
372
        int                     state)
373
{
374
        if (!pr)
375
                return;
376
 
377
        pr->power.states[pr->power.state].promotion.count = 0;
378
        pr->power.states[pr->power.state].demotion.count = 0;
379
 
380
        /* Cleanup from old state. */
381
        switch (pr->power.state) {
382
        case ACPI_STATE_C3:
383
                /* Disable bus master reload */
384
                acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0, ACPI_MTX_DO_NOT_LOCK);
385
                break;
386
        }
387
 
388
        /* Prepare to use new state. */
389
        switch (state) {
390
        case ACPI_STATE_C3:
391
                /* Enable bus master reload */
392
                acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1, ACPI_MTX_DO_NOT_LOCK);
393
                break;
394
        }
395
 
396
        pr->power.state = state;
397
 
398
        return;
399
}
400
 
401
 
402
static void
403
acpi_processor_idle (void)
404
{
405
        struct acpi_processor   *pr = NULL;
406
        struct acpi_processor_cx *cx = NULL;
407
        int                     next_state = 0;
408
        int                     sleep_ticks = 0;
409
        u32                     t1, t2 = 0;
410
 
411
        pr = processors[smp_processor_id()];
412
        if (!pr)
413
                return;
414
 
415
        /*
416
         * Interrupts must be disabled during bus mastering calculations and
417
         * for C2/C3 transitions.
418
         */
419
        __cli();
420
 
421
        cx = &(pr->power.states[pr->power.state]);
422
 
423
        /*
424
         * Check BM Activity
425
         * -----------------
426
         * Check for bus mastering activity (if required), record, and check
427
         * for demotion.
428
         */
429
        if (pr->flags.bm_check) {
430
                u32             bm_status = 0;
431
 
432
                pr->power.bm_activity <<= 1;
433
 
434
                acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS,
435
                        &bm_status, ACPI_MTX_DO_NOT_LOCK);
436
                if (bm_status) {
437
                        pr->power.bm_activity++;
438
                        acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS,
439
                                1, ACPI_MTX_DO_NOT_LOCK);
440
                }
441
                /*
442
                 * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
443
                 * the true state of bus mastering activity; forcing us to
444
                 * manually check the BMIDEA bit of each IDE channel.
445
                 */
446
                else if (errata.piix4.bmisx) {
447
                        if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
448
                                || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
449
                                pr->power.bm_activity++;
450
                }
451
                /*
452
                 * Apply bus mastering demotion policy.  Automatically demote
453
                 * to avoid a faulty transition.  Note that the processor
454
                 * won't enter a low-power state during this call (to this
455
                 * funciton) but should upon the next.
456
                 *
457
                 * TBD: A better policy might be to fallback to the demotion
458
                 *      state (use it for this quantum only) istead of
459
                 *      demoting -- and rely on duration as our sole demotion
460
                 *      qualification.  This may, however, introduce DMA
461
                 *      issues (e.g. floppy DMA transfer overrun/underrun).
462
                 */
463
                if (pr->power.bm_activity & cx->demotion.threshold.bm) {
464
                        __sti();
465
                        next_state = cx->demotion.state;
466
                        goto end;
467
                }
468
        }
469
 
470
        cx->usage++;
471
 
472
        /*
473
         * Sleep:
474
         * ------
475
         * Invoke the current Cx state to put the processor to sleep.
476
         */
477
        switch (pr->power.state) {
478
 
479
        case ACPI_STATE_C1:
480
                /* Invoke C1. */
481
                safe_halt();
482
                /*
483
                 * TBD: Can't get time duration while in C1, as resumes
484
                 *      go to an ISR rather than here.  Need to instrument
485
                 *      base interrupt handler.
486
                 */
487
                sleep_ticks = 0xFFFFFFFF;
488
                break;
489
 
490
        case ACPI_STATE_C2:
491
                /* Get start time (ticks) */
492
                t1 = inl(acpi_fadt.xpm_tmr_blk.address);
493
                /* Invoke C2 */
494
                inb(pr->power.states[ACPI_STATE_C2].address);
495
                /* Dummy op - must do something useless after P_LVL2 read */
496
                t2 = inl(acpi_fadt.xpm_tmr_blk.address);
497
                /* Get end time (ticks) */
498
                t2 = inl(acpi_fadt.xpm_tmr_blk.address);
499
                /* Re-enable interrupts */
500
                __sti();
501
                /* Compute time (ticks) that we were actually asleep */
502
                sleep_ticks = ticks_elapsed(t1, t2) - cx->latency_ticks - C2_OVERHEAD;
503
                break;
504
 
505
        case ACPI_STATE_C3:
506
                /* Disable bus master arbitration */
507
                acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1, ACPI_MTX_DO_NOT_LOCK);
508
                /* Get start time (ticks) */
509
                t1 = inl(acpi_fadt.xpm_tmr_blk.address);
510
                /* Invoke C3 */
511
                inb(pr->power.states[ACPI_STATE_C3].address);
512
                /* Dummy op - must do something useless after P_LVL3 read */
513
                t2 = inl(acpi_fadt.xpm_tmr_blk.address);
514
                /* Get end time (ticks) */
515
                t2 = inl(acpi_fadt.xpm_tmr_blk.address);
516
                /* Enable bus master arbitration */
517
                acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_DO_NOT_LOCK);
518
                /* Re-enable interrupts */
519
                __sti();
520
                /* Compute time (ticks) that we were actually asleep */
521
                sleep_ticks = ticks_elapsed(t1, t2) - cx->latency_ticks - C3_OVERHEAD;
522
                break;
523
 
524
        default:
525
                __sti();
526
                return;
527
        }
528
 
529
        next_state = pr->power.state;
530
 
531
        /*
532
         * Promotion?
533
         * ----------
534
         * Track the number of longs (time asleep is greater than threshold)
535
         * and promote when the count threshold is reached.  Note that bus
536
         * mastering activity may prevent promotions.
537
         */
538
        if (cx->promotion.state) {
539
                if (sleep_ticks > cx->promotion.threshold.ticks) {
540
                        cx->promotion.count++;
541
                        cx->demotion.count = 0;
542
                        if (cx->promotion.count >= cx->promotion.threshold.count) {
543
                                if (pr->flags.bm_check) {
544
                                        if (!(pr->power.bm_activity & cx->promotion.threshold.bm)) {
545
                                                next_state = cx->promotion.state;
546
                                                goto end;
547
                                        }
548
                                }
549
                                else {
550
                                        next_state = cx->promotion.state;
551
                                        goto end;
552
                                }
553
                        }
554
                }
555
        }
556
 
557
        /*
558
         * Demotion?
559
         * ---------
560
         * Track the number of shorts (time asleep is less than time threshold)
561
         * and demote when the usage threshold is reached.
562
         */
563
        if (cx->demotion.state) {
564
                if (sleep_ticks < cx->demotion.threshold.ticks) {
565
                        cx->demotion.count++;
566
                        cx->promotion.count = 0;
567
                        if (cx->demotion.count >= cx->demotion.threshold.count) {
568
                                next_state = cx->demotion.state;
569
                                goto end;
570
                        }
571
                }
572
        }
573
 
574
end:
575
        /*
576
         * New Cx State?
577
         * -------------
578
         * If we're going to start using a new Cx state we must clean up
579
         * from the previous and prepare to use the new.
580
         */
581
        if (next_state != pr->power.state)
582
                acpi_processor_power_activate(pr, next_state);
583
 
584
        return;
585
}
586
 
587
 
588
static int
589
acpi_processor_set_power_policy (
590
        struct acpi_processor   *pr)
591
{
592
        ACPI_FUNCTION_TRACE("acpi_processor_set_power_policy");
593
 
594
        /*
595
         * This function sets the default Cx state policy (OS idle handler).
596
         * Our scheme is to promote quickly to C2 but more conservatively
597
         * to C3.  We're favoring C2  for its characteristics of low latency
598
         * (quick response), good power savings, and ability to allow bus
599
         * mastering activity.  Note that the Cx state policy is completely
600
         * customizable and can be altered dynamically.
601
         */
602
 
603
        if (!pr)
604
                return_VALUE(-EINVAL);
605
 
606
        /*
607
         * C0/C1
608
         * -----
609
         */
610
        pr->power.state = ACPI_STATE_C1;
611
        pr->power.default_state = ACPI_STATE_C1;
612
 
613
        /*
614
         * C1/C2
615
         * -----
616
         * Set the default C1 promotion and C2 demotion policies, where we
617
         * promote from C1 to C2 after several (10) successive C1 transitions,
618
         * as we cannot (currently) measure the time spent in C1. Demote from
619
         * C2 to C1 anytime we experience a 'short' (time spent in C2 is less
620
         * than the C2 transtion latency).  Note the simplifying assumption
621
         * that the 'cost' of a transition is amortized when we sleep for at
622
         * least as long as the transition's latency (thus the total transition
623
         * time is two times the latency).
624
         *
625
         * TBD: Measure C1 sleep times by instrumenting the core IRQ handler.
626
         * TBD: Demote to default C-State after long periods of activity.
627
         * TBD: Investigate policy's use of CPU utilization -vs- sleep duration.
628
         */
629
        if (pr->power.states[ACPI_STATE_C2].valid) {
630
                pr->power.states[ACPI_STATE_C1].promotion.threshold.count = 10;
631
                pr->power.states[ACPI_STATE_C1].promotion.threshold.ticks =
632
                        pr->power.states[ACPI_STATE_C2].latency_ticks;
633
                pr->power.states[ACPI_STATE_C1].promotion.state = ACPI_STATE_C2;
634
 
635
                pr->power.states[ACPI_STATE_C2].demotion.threshold.count = 1;
636
                pr->power.states[ACPI_STATE_C2].demotion.threshold.ticks =
637
                        pr->power.states[ACPI_STATE_C2].latency_ticks;
638
                pr->power.states[ACPI_STATE_C2].demotion.state = ACPI_STATE_C1;
639
        }
640
 
641
        /*
642
         * C2/C3
643
         * -----
644
         * Set default C2 promotion and C3 demotion policies, where we promote
645
         * from C2 to C3 after several (4) cycles of no bus mastering activity
646
         * while maintaining sleep time criteria.  Demote immediately on a
647
         * short or whenever bus mastering activity occurs.
648
         */
649
        if ((pr->power.states[ACPI_STATE_C2].valid) &&
650
                (pr->power.states[ACPI_STATE_C3].valid)) {
651
                pr->power.states[ACPI_STATE_C2].promotion.threshold.count = 4;
652
                pr->power.states[ACPI_STATE_C2].promotion.threshold.ticks =
653
                        pr->power.states[ACPI_STATE_C3].latency_ticks;
654
                pr->power.states[ACPI_STATE_C2].promotion.threshold.bm = 0x0F;
655
                pr->power.states[ACPI_STATE_C2].promotion.state = ACPI_STATE_C3;
656
 
657
                pr->power.states[ACPI_STATE_C3].demotion.threshold.count = 1;
658
                pr->power.states[ACPI_STATE_C3].demotion.threshold.ticks =
659
                        pr->power.states[ACPI_STATE_C3].latency_ticks;
660
                pr->power.states[ACPI_STATE_C3].demotion.threshold.bm = 0x0F;
661
                pr->power.states[ACPI_STATE_C3].demotion.state = ACPI_STATE_C2;
662
        }
663
 
664
        return_VALUE(0);
665
}
666
 
667
 
668
int
669
acpi_processor_get_power_info (
670
        struct acpi_processor   *pr)
671
{
672
        int                     result = 0;
673
 
674
        ACPI_FUNCTION_TRACE("acpi_processor_get_power_info");
675
 
676
        if (!pr)
677
                return_VALUE(-EINVAL);
678
 
679
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
680
                "lvl2[0x%08x] lvl3[0x%08x]\n",
681
                pr->power.states[ACPI_STATE_C2].address,
682
                pr->power.states[ACPI_STATE_C3].address));
683
 
684
        /* TBD: Support ACPI 2.0 objects */
685
 
686
        /*
687
         * C0
688
         * --
689
         * This state exists only as filler in our array.
690
         */
691
        pr->power.states[ACPI_STATE_C0].valid = 1;
692
 
693
        /*
694
         * C1
695
         * --
696
         * ACPI requires C1 support for all processors.
697
         *
698
         * TBD: What about PROC_C1?
699
         */
700
        pr->power.states[ACPI_STATE_C1].valid = 1;
701
 
702
        /*
703
         * C2
704
         * --
705
         * We're (currently) only supporting C2 on UP systems.
706
         *
707
         * TBD: Support for C2 on MP (P_LVL2_UP).
708
         */
709
        if (pr->power.states[ACPI_STATE_C2].address) {
710
 
711
                pr->power.states[ACPI_STATE_C2].latency = acpi_fadt.plvl2_lat;
712
 
713
                /*
714
                 * C2 latency must be less than or equal to 100 microseconds.
715
                 */
716
                if (acpi_fadt.plvl2_lat > ACPI_PROCESSOR_MAX_C2_LATENCY)
717
                        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
718
                                "C2 latency too large [%d]\n",
719
                                acpi_fadt.plvl2_lat));
720
                /*
721
                 * Only support C2 on UP systems (see TBD above).
722
                 */
723
                else if (errata.smp)
724
                        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
725
                                "C2 not supported in SMP mode\n"));
726
                /*
727
                 * Otherwise we've met all of our C2 requirements.
728
                 * Normalize the C2 latency to expidite policy.
729
                 */
730
                else {
731
                        pr->power.states[ACPI_STATE_C2].valid = 1;
732
                        pr->power.states[ACPI_STATE_C2].latency_ticks =
733
                                US_TO_PM_TIMER_TICKS(acpi_fadt.plvl2_lat);
734
                }
735
        }
736
 
737
        /*
738
         * C3
739
         * --
740
         * TBD: Investigate use of WBINVD on UP/SMP system in absence of
741
         *      bm_control.
742
         */
743
        if (pr->power.states[ACPI_STATE_C3].address) {
744
 
745
                pr->power.states[ACPI_STATE_C3].latency = acpi_fadt.plvl3_lat;
746
 
747
                /*
748
                 * C3 latency must be less than or equal to 1000 microseconds.
749
                 */
750
                if (acpi_fadt.plvl3_lat > ACPI_PROCESSOR_MAX_C3_LATENCY)
751
                        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
752
                                "C3 latency too large [%d]\n",
753
                                acpi_fadt.plvl3_lat));
754
                /*
755
                 * Only support C3 when bus mastering arbitration control
756
                 * is present (able to disable bus mastering to maintain
757
                 * cache coherency while in C3).
758
                 */
759
                else if (!pr->flags.bm_control)
760
                        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
761
                                "C3 support requires bus mastering control\n"));
762
                /*
763
                 * Only support C3 on UP systems, as bm_control is only viable
764
                 * on a UP system and flushing caches (e.g. WBINVD) is simply
765
                 * too costly (at this time).
766
                 */
767
                else if (errata.smp)
768
                        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
769
                                "C3 not supported in SMP mode\n"));
770
                /*
771
                 * PIIX4 Erratum #18: We don't support C3 when Type-F (fast)
772
                 * DMA transfers are used by any ISA device to avoid livelock.
773
                 * Note that we could disable Type-F DMA (as recommended by
774
                 * the erratum), but this is known to disrupt certain ISA
775
                 * devices thus we take the conservative approach.
776
                 */
777
                else if (errata.piix4.fdma) {
778
                        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
779
                                "C3 not supported on PIIX4 with Type-F DMA\n"));
780
                }
781
                /*
782
                 * Otherwise we've met all of our C3 requirements.
783
                 * Normalize the C2 latency to expidite policy.  Enable
784
                 * checking of bus mastering status (bm_check) so we can
785
                 * use this in our C3 policy.
786
                 */
787
                else {
788
                        pr->power.states[ACPI_STATE_C3].valid = 1;
789
                        pr->power.states[ACPI_STATE_C3].latency_ticks =
790
                                US_TO_PM_TIMER_TICKS(acpi_fadt.plvl3_lat);
791
                        pr->flags.bm_check = 1;
792
                }
793
        }
794
 
795
        /*
796
         * Set Default Policy
797
         * ------------------
798
         * Now that we know which state are supported, set the default
799
         * policy.  Note that this policy can be changed dynamically
800
         * (e.g. encourage deeper sleeps to conserve battery life when
801
         * not on AC).
802
         */
803
        result = acpi_processor_set_power_policy(pr);
804
        if (result)
805
                return_VALUE(result);
806
 
807
        /*
808
         * If this processor supports C2 or C3 we denote it as being 'power
809
         * manageable'.  Note that there's really no policy involved for
810
         * when only C1 is supported.
811
         */
812
        if (pr->power.states[ACPI_STATE_C2].valid
813
                || pr->power.states[ACPI_STATE_C3].valid)
814
                pr->flags.power = 1;
815
 
816
        return_VALUE(0);
817
}
818
 
819
 
820
/* --------------------------------------------------------------------------
821
                              Performance Management
822
   -------------------------------------------------------------------------- */
823
 
824
static int
825
acpi_processor_get_platform_limit (
826
        struct acpi_processor*  pr)
827
{
828
        acpi_status             status = 0;
829
        unsigned long           ppc = 0;
830
 
831
        ACPI_FUNCTION_TRACE("acpi_processor_get_platform_limit");
832
 
833
        if (!pr)
834
                return_VALUE(-EINVAL);
835
 
836
        /*
837
         * _PPC indicates the maximum state currently supported by the platform
838
         * (e.g. 0 = states 0..n; 1 = states 1..n; etc.
839
         */
840
        status = acpi_evaluate_integer(pr->handle, "_PPC", NULL, &ppc);
841
        if(ACPI_FAILURE(status)) {
842
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PPC\n"));
843
                return_VALUE(-ENODEV);
844
        }
845
 
846
        pr->performance.platform_limit = (int) ppc;
847
 
848
        return_VALUE(0);
849
}
850
 
851
 
852
static int
853
acpi_processor_get_performance_control (
854
        struct acpi_processor   *pr)
855
{
856
        int                     result = 0;
857
        acpi_status             status = 0;
858
        struct acpi_buffer      buffer = {ACPI_ALLOCATE_BUFFER, NULL};
859
        union acpi_object       *pct = NULL;
860
        union acpi_object       obj = {0};
861
        struct acpi_pct_register *reg = NULL;
862
 
863
        ACPI_FUNCTION_TRACE("acpi_processor_get_performance_control");
864
 
865
        status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer);
866
        if(ACPI_FAILURE(status)) {
867
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PCT\n"));
868
                return_VALUE(-ENODEV);
869
        }
870
 
871
        pct = (union acpi_object *) buffer.pointer;
872
        if (!pct || (pct->type != ACPI_TYPE_PACKAGE)
873
                || (pct->package.count != 2)) {
874
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PCT data\n"));
875
                result = -EFAULT;
876
                goto end;
877
        }
878
 
879
        /*
880
         * control_register
881
         */
882
 
883
        obj = pct->package.elements[0];
884
 
885
        if ((obj.type != ACPI_TYPE_BUFFER)
886
                || (obj.buffer.length < sizeof(struct acpi_pct_register))
887
                || (obj.buffer.pointer == NULL)) {
888
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
889
                        "Invalid _PCT data (control_register)\n"));
890
                result = -EFAULT;
891
                goto end;
892
        }
893
 
894
        reg = (struct acpi_pct_register *) (obj.buffer.pointer);
895
 
896
        if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO) {
897
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
898
                        "Unsupported address space [%d] (control_register)\n",
899
                        (u32) reg->space_id));
900
                result = -EFAULT;
901
                goto end;
902
        }
903
 
904
        pr->performance.control_register = (u16) reg->address;
905
        pr->performance.control_register_bit_width = reg->bit_width;
906
        /*
907
         * status_register
908
         */
909
 
910
        obj = pct->package.elements[1];
911
 
912
        if ((obj.type != ACPI_TYPE_BUFFER)
913
                || (obj.buffer.length < sizeof(struct acpi_pct_register))
914
                || (obj.buffer.pointer == NULL)) {
915
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
916
                        "Invalid _PCT data (status_register)\n"));
917
                result = -EFAULT;
918
                goto end;
919
        }
920
 
921
        reg = (struct acpi_pct_register *) (obj.buffer.pointer);
922
 
923
        if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO) {
924
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
925
                        "Unsupported address space [%d] (status_register)\n",
926
                        (u32) reg->space_id));
927
                result = -EFAULT;
928
                goto end;
929
        }
930
 
931
        pr->performance.status_register = (u16) reg->address;
932
        pr->performance.status_register_bit_width = reg->bit_width;
933
 
934
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
935
                "control_register[0x%04x] status_register[0x%04x]\n",
936
                pr->performance.control_register,
937
                pr->performance.status_register));
938
 
939
end:
940
        acpi_os_free(buffer.pointer);
941
 
942
        return_VALUE(result);
943
}
944
 
945
 
946
static int
947
acpi_processor_get_performance_states (
948
        struct acpi_processor*  pr)
949
{
950
        int                     result = 0;
951
        acpi_status             status = AE_OK;
952
        struct acpi_buffer      buffer = {ACPI_ALLOCATE_BUFFER, NULL};
953
        struct acpi_buffer      format = {sizeof("NNNNNN"), "NNNNNN"};
954
        struct acpi_buffer      state = {0, NULL};
955
        union acpi_object       *pss = NULL;
956
        int                     i = 0;
957
 
958
        ACPI_FUNCTION_TRACE("acpi_processor_get_performance_states");
959
 
960
        status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer);
961
        if(ACPI_FAILURE(status)) {
962
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PSS\n"));
963
                return_VALUE(-ENODEV);
964
        }
965
 
966
        pss = (union acpi_object *) buffer.pointer;
967
        if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) {
968
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSS data\n"));
969
                result = -EFAULT;
970
                goto end;
971
        }
972
 
973
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d performance states\n",
974
                pss->package.count));
975
 
976
        if (pss->package.count > ACPI_PROCESSOR_MAX_PERFORMANCE) {
977
                pr->performance.state_count = ACPI_PROCESSOR_MAX_PERFORMANCE;
978
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
979
                        "Limiting number of states to max (%d)\n",
980
                        ACPI_PROCESSOR_MAX_PERFORMANCE));
981
        }
982
        else
983
                pr->performance.state_count = pss->package.count;
984
 
985
        if (pr->performance.state_count > 1)
986
                pr->flags.performance = 1;
987
 
988
        for (i = 0; i < pr->performance.state_count; i++) {
989
 
990
                struct acpi_processor_px *px = &(pr->performance.states[i]);
991
 
992
                state.length = sizeof(struct acpi_processor_px);
993
                state.pointer = px;
994
 
995
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i));
996
 
997
                status = acpi_extract_package(&(pss->package.elements[i]),
998
                        &format, &state);
999
                if (ACPI_FAILURE(status)) {
1000
                        ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSS data\n"));
1001
                        result = -EFAULT;
1002
                        goto end;
1003
                }
1004
 
1005
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1006
                        "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n",
1007
                        i,
1008
                        (u32) px->core_frequency,
1009
                        (u32) px->power,
1010
                        (u32) px->transition_latency,
1011
                        (u32) px->bus_master_latency,
1012
                        (u32) px->control,
1013
                        (u32) px->status));
1014
        }
1015
 
1016
end:
1017
        acpi_os_free(buffer.pointer);
1018
 
1019
        return_VALUE(result);
1020
}
1021
 
1022
static int
1023
acpi_processor_write_port(
1024
        u16     port,
1025
        u8      bit_width,
1026
        u32     value)
1027
{
1028
        if (bit_width <= 8) {
1029
                outb(value, port);
1030
        } else if (bit_width <= 16) {
1031
                outw(value, port);
1032
        } else if (bit_width <= 32) {
1033
                outl(value, port);
1034
        } else {
1035
                return -ENODEV;
1036
        }
1037
        return 0;
1038
}
1039
 
1040
static int
1041
acpi_processor_read_port(
1042
        u16     port,
1043
        u8      bit_width,
1044
        u32     *ret)
1045
{
1046
        *ret = 0;
1047
        if (bit_width <= 8) {
1048
                *ret = inb(port);
1049
        } else if (bit_width <= 16) {
1050
                *ret = inw(port);
1051
        } else if (bit_width <= 32) {
1052
                *ret = inl(port);
1053
        } else {
1054
                return -ENODEV;
1055
        }
1056
        return 0;
1057
}
1058
 
1059
static int
1060
acpi_processor_set_performance (
1061
        struct acpi_processor   *pr,
1062
        int                     state)
1063
{
1064
        u16                     port = 0;
1065
        u8                      bit_width = 0;
1066
        int                     ret = 0;
1067
        u32                     value = 0;
1068
        int                     i = 0;
1069
 
1070
        ACPI_FUNCTION_TRACE("acpi_processor_set_performance");
1071
 
1072
        if (!pr)
1073
                return_VALUE(-EINVAL);
1074
 
1075
        if (!pr->flags.performance)
1076
                return_VALUE(-ENODEV);
1077
 
1078
        if (state >= pr->performance.state_count) {
1079
                ACPI_DEBUG_PRINT((ACPI_DB_WARN,
1080
                        "Invalid target state (P%d)\n", state));
1081
                return_VALUE(-ENODEV);
1082
        }
1083
 
1084
        if (state < pr->performance.platform_limit) {
1085
                ACPI_DEBUG_PRINT((ACPI_DB_WARN,
1086
                        "Platform limit (P%d) overrides target state (P%d)\n",
1087
                        pr->performance.platform_limit, state));
1088
                return_VALUE(-ENODEV);
1089
        }
1090
 
1091
        if (state == pr->performance.state) {
1092
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1093
                        "Already at target state (P%d)\n", state));
1094
                return_VALUE(0);
1095
        }
1096
 
1097
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Transitioning from P%d to P%d\n",
1098
                pr->performance.state, state));
1099
 
1100
        /*
1101
         * First we write the target state's 'control' value to the
1102
         * control_register.
1103
         */
1104
 
1105
        port = pr->performance.control_register;
1106
        value = (u32) pr->performance.states[state].control;
1107
        bit_width = pr->performance.control_register_bit_width;
1108
 
1109
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1110
                "Writing 0x%08x to port 0x%04x\n", value, port));
1111
 
1112
        ret = acpi_processor_write_port(port, bit_width, value);
1113
        if (ret) {
1114
                ACPI_DEBUG_PRINT((ACPI_DB_WARN,
1115
                        "Invalid port width 0x%04x\n", bit_width));
1116
                return_VALUE(ret);
1117
        }
1118
 
1119
        /*
1120
         * Then we read the 'status_register' and compare the value with the
1121
         * target state's 'status' to make sure the transition was successful.
1122
         * Note that we'll poll for up to 1ms (100 cycles of 10us) before
1123
         * giving up.
1124
         */
1125
 
1126
        port = pr->performance.status_register;
1127
        bit_width = pr->performance.status_register_bit_width;
1128
 
1129
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1130
                "Looking for 0x%08x from port 0x%04x\n",
1131
                (u32) pr->performance.states[state].status, port));
1132
 
1133
        for (i=0; i<100; i++) {
1134
                ret = acpi_processor_read_port(port, bit_width, &value);
1135
                if (ret) {
1136
                        ACPI_DEBUG_PRINT((ACPI_DB_WARN,
1137
                                "Invalid port width 0x%04x\n", bit_width));
1138
                        return_VALUE(ret);
1139
                }
1140
                if (value == (u32) pr->performance.states[state].status)
1141
                        break;
1142
                udelay(10);
1143
        }
1144
 
1145
        if (value != (u32) pr->performance.states[state].status) {
1146
                ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Transition failed\n"));
1147
                return_VALUE(-ENODEV);
1148
        }
1149
 
1150
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1151
                "Transition successful after %d microseconds\n",
1152
                i * 10));
1153
 
1154
        pr->performance.state = state;
1155
 
1156
        return_VALUE(0);
1157
}
1158
 
1159
 
1160
static int
1161
acpi_processor_get_performance_info (
1162
        struct acpi_processor   *pr)
1163
{
1164
        int                     result = 0;
1165
        acpi_status             status = AE_OK;
1166
        acpi_handle             handle = NULL;
1167
 
1168
        ACPI_FUNCTION_TRACE("acpi_processor_get_performance_info");
1169
 
1170
        if (!pr)
1171
                return_VALUE(-EINVAL);
1172
 
1173
        status = acpi_get_handle(pr->handle, "_PCT", &handle);
1174
        if (ACPI_FAILURE(status)) {
1175
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1176
                        "ACPI-based processor performance control unavailable\n"));
1177
                return_VALUE(0);
1178
        }
1179
 
1180
        result = acpi_processor_get_performance_control(pr);
1181
        if (result)
1182
                return_VALUE(result);
1183
 
1184
        result = acpi_processor_get_performance_states(pr);
1185
        if (result)
1186
                return_VALUE(result);
1187
 
1188
        result = acpi_processor_get_platform_limit(pr);
1189
        if (result)
1190
                return_VALUE(result);
1191
 
1192
        /*
1193
         * TBD: Don't trust the latency values we get from BIOS, but rather
1194
         *      measure the latencies during run-time (e.g. get_latencies).
1195
         */
1196
 
1197
        return_VALUE(0);
1198
}
1199
 
1200
 
1201
/* --------------------------------------------------------------------------
1202
                              Throttling Control
1203
   -------------------------------------------------------------------------- */
1204
 
1205
static int
1206
acpi_processor_get_throttling (
1207
        struct acpi_processor   *pr)
1208
{
1209
        int                     state = 0;
1210
        u32                     value = 0;
1211
        u32                     duty_mask = 0;
1212
        u32                     duty_value = 0;
1213
 
1214
        ACPI_FUNCTION_TRACE("acpi_processor_get_throttling");
1215
 
1216
        if (!pr)
1217
                return_VALUE(-EINVAL);
1218
 
1219
        if (!pr->flags.throttling)
1220
                return_VALUE(-ENODEV);
1221
 
1222
        pr->throttling.state = 0;
1223
 
1224
        __cli();
1225
 
1226
        duty_mask = pr->throttling.state_count - 1;
1227
 
1228
        duty_mask <<= pr->throttling.duty_offset;
1229
 
1230
        value = inl(pr->throttling.address);
1231
 
1232
        /*
1233
         * Compute the current throttling state when throttling is enabled
1234
         * (bit 4 is on).
1235
         */
1236
        if (value & 0x10) {
1237
                duty_value = value & duty_mask;
1238
                duty_value >>= pr->throttling.duty_offset;
1239
 
1240
                if (duty_value)
1241
                        state = pr->throttling.state_count-duty_value;
1242
        }
1243
 
1244
        pr->throttling.state = state;
1245
 
1246
        __sti();
1247
 
1248
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1249
                "Throttling state is T%d (%d%% throttling applied)\n",
1250
                state, pr->throttling.states[state].performance));
1251
 
1252
        return_VALUE(0);
1253
}
1254
 
1255
 
1256
static int
1257
acpi_processor_set_throttling (
1258
        struct acpi_processor   *pr,
1259
        int                     state)
1260
{
1261
        u32                     value = 0;
1262
        u32                     duty_mask = 0;
1263
        u32                     duty_value = 0;
1264
 
1265
        ACPI_FUNCTION_TRACE("acpi_processor_set_throttling");
1266
 
1267
        if (!pr)
1268
                return_VALUE(-EINVAL);
1269
 
1270
        if ((state < 0) || (state > (pr->throttling.state_count - 1)))
1271
                return_VALUE(-EINVAL);
1272
 
1273
        if (!pr->flags.throttling)
1274
                return_VALUE(-ENODEV);
1275
 
1276
        if (state == pr->throttling.state)
1277
                return_VALUE(0);
1278
 
1279
        __cli();
1280
 
1281
        /*
1282
         * Calculate the duty_value and duty_mask.
1283
         */
1284
        if (state) {
1285
                duty_value = pr->throttling.state_count - state;
1286
 
1287
                duty_value <<= pr->throttling.duty_offset;
1288
 
1289
                /* Used to clear all duty_value bits */
1290
                duty_mask = pr->throttling.state_count - 1;
1291
 
1292
                duty_mask <<= acpi_fadt.duty_offset;
1293
                duty_mask = ~duty_mask;
1294
        }
1295
 
1296
        /*
1297
         * Disable throttling by writing a 0 to bit 4.  Note that we must
1298
         * turn it off before you can change the duty_value.
1299
         */
1300
        value = inl(pr->throttling.address);
1301
        if (value & 0x10) {
1302
                value &= 0xFFFFFFEF;
1303
                outl(value, pr->throttling.address);
1304
        }
1305
 
1306
        /*
1307
         * Write the new duty_value and then enable throttling.  Note
1308
         * that a state value of 0 leaves throttling disabled.
1309
         */
1310
        if (state) {
1311
                value &= duty_mask;
1312
                value |= duty_value;
1313
                outl(value, pr->throttling.address);
1314
 
1315
                value |= 0x00000010;
1316
                outl(value, pr->throttling.address);
1317
        }
1318
 
1319
        pr->throttling.state = state;
1320
 
1321
        __sti();
1322
 
1323
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1324
                "Throttling state set to T%d (%d%%)\n", state,
1325
                (pr->throttling.states[state].performance?pr->throttling.states[state].performance/10:0)));
1326
 
1327
        return_VALUE(0);
1328
}
1329
 
1330
 
1331
static int
1332
acpi_processor_get_throttling_info (
1333
        struct acpi_processor   *pr)
1334
{
1335
        int                     result = 0;
1336
        int                     step = 0;
1337
        int                     i = 0;
1338
 
1339
        ACPI_FUNCTION_TRACE("acpi_processor_get_throttling_info");
1340
 
1341
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1342
                "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
1343
                pr->throttling.address,
1344
                pr->throttling.duty_offset,
1345
                pr->throttling.duty_width));
1346
 
1347
        if (!pr)
1348
                return_VALUE(-EINVAL);
1349
 
1350
        /* TBD: Support ACPI 2.0 objects */
1351
 
1352
        if (!pr->throttling.address) {
1353
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
1354
                return_VALUE(0);
1355
        }
1356
        else if (!pr->throttling.duty_width) {
1357
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n"));
1358
                return_VALUE(0);
1359
        }
1360
        /* TBD: Support duty_cycle values that span bit 4. */
1361
        else if ((pr->throttling.duty_offset
1362
                + pr->throttling.duty_width) > 4) {
1363
                ACPI_DEBUG_PRINT((ACPI_DB_WARN, "duty_cycle spans bit 4\n"));
1364
                return_VALUE(0);
1365
        }
1366
 
1367
        /*
1368
         * PIIX4 Errata: We don't support throttling on the original PIIX4.
1369
         * This shouldn't be an issue as few (if any) mobile systems ever
1370
         * used this part.
1371
         */
1372
        if (errata.piix4.throttle) {
1373
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1374
                        "Throttling not supported on PIIX4 A- or B-step\n"));
1375
                return_VALUE(0);
1376
        }
1377
 
1378
        pr->throttling.state_count = 1 << acpi_fadt.duty_width;
1379
 
1380
        /*
1381
         * Compute state values. Note that throttling displays a linear power/
1382
         * performance relationship (at 50% performance the CPU will consume
1383
         * 50% power).  Values are in 1/10th of a percent to preserve accuracy.
1384
         */
1385
 
1386
        step = (1000 / pr->throttling.state_count);
1387
 
1388
        for (i=0; i<pr->throttling.state_count; i++) {
1389
                pr->throttling.states[i].performance = step * i;
1390
                pr->throttling.states[i].power = step * i;
1391
        }
1392
 
1393
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
1394
                pr->throttling.state_count));
1395
 
1396
        pr->flags.throttling = 1;
1397
 
1398
        /*
1399
         * Disable throttling (if enabled).  We'll let subsequent policy (e.g.
1400
         * thermal) decide to lower performance if it so chooses, but for now
1401
         * we'll crank up the speed.
1402
         */
1403
 
1404
        result = acpi_processor_get_throttling(pr);
1405
        if (result)
1406
                goto end;
1407
 
1408
        if (pr->throttling.state) {
1409
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabling throttling (was T%d)\n",
1410
                        pr->throttling.state));
1411
                result = acpi_processor_set_throttling(pr, 0);
1412
                if (result)
1413
                        goto end;
1414
        }
1415
 
1416
end:
1417
        if (result)
1418
                pr->flags.throttling = 0;
1419
 
1420
        return_VALUE(result);
1421
}
1422
 
1423
 
1424
/* --------------------------------------------------------------------------
1425
                                 Limit Interface
1426
   -------------------------------------------------------------------------- */
1427
 
1428
static int
1429
acpi_processor_apply_limit (
1430
        struct acpi_processor*  pr)
1431
{
1432
        int                     result = 0;
1433
        u16                     px = 0;
1434
        u16                     tx = 0;
1435
 
1436
        ACPI_FUNCTION_TRACE("acpi_processor_apply_limit");
1437
 
1438
        if (!pr)
1439
                return_VALUE(-EINVAL);
1440
 
1441
        if (!pr->flags.limit)
1442
                return_VALUE(-ENODEV);
1443
 
1444
        if (pr->flags.performance) {
1445
                px = pr->performance.platform_limit;
1446
                if (pr->limit.user.px > px)
1447
                        px = pr->limit.user.px;
1448
                if (pr->limit.thermal.px > px)
1449
                        px = pr->limit.thermal.px;
1450
 
1451
                result = acpi_processor_set_performance(pr, px);
1452
                if (result)
1453
                        goto end;
1454
        }
1455
 
1456
        if (pr->flags.throttling) {
1457
                if (pr->limit.user.tx > tx)
1458
                        tx = pr->limit.user.tx;
1459
                if (pr->limit.thermal.tx > tx)
1460
                        tx = pr->limit.thermal.tx;
1461
 
1462
                result = acpi_processor_set_throttling(pr, tx);
1463
                if (result)
1464
                        goto end;
1465
        }
1466
 
1467
        pr->limit.state.px = px;
1468
        pr->limit.state.tx = tx;
1469
 
1470
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d] limit set to (P%d:T%d)\n",
1471
                pr->id,
1472
                pr->limit.state.px,
1473
                pr->limit.state.tx));
1474
 
1475
end:
1476
        if (result)
1477
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to set limit\n"));
1478
 
1479
        return_VALUE(result);
1480
}
1481
 
1482
 
1483
int
1484
acpi_processor_set_thermal_limit (
1485
        acpi_handle             handle,
1486
        int                     type)
1487
{
1488
        int                     result = 0;
1489
        struct acpi_processor   *pr = NULL;
1490
        struct acpi_device      *device = NULL;
1491
        int                     px = 0;
1492
        int                     tx = 0;
1493
 
1494
        ACPI_FUNCTION_TRACE("acpi_processor_set_thermal_limit");
1495
 
1496
        if ((type < ACPI_PROCESSOR_LIMIT_NONE)
1497
                || (type > ACPI_PROCESSOR_LIMIT_DECREMENT))
1498
                return_VALUE(-EINVAL);
1499
 
1500
        result = acpi_bus_get_device(handle, &device);
1501
        if (result)
1502
                return_VALUE(result);
1503
 
1504
        pr = (struct acpi_processor *) acpi_driver_data(device);
1505
        if (!pr)
1506
                return_VALUE(-ENODEV);
1507
 
1508
        if (!pr->flags.limit)
1509
                return_VALUE(-ENODEV);
1510
 
1511
        /* Thermal limits are always relative to the current Px/Tx state. */
1512
        if (pr->flags.performance)
1513
                pr->limit.thermal.px = pr->performance.state;
1514
        if (pr->flags.throttling)
1515
                pr->limit.thermal.tx = pr->throttling.state;
1516
 
1517
        /*
1518
         * Our default policy is to only use throttling at the lowest
1519
         * performance state.
1520
         */
1521
 
1522
        px = pr->limit.thermal.px;
1523
        tx = pr->limit.thermal.tx;
1524
 
1525
        switch (type) {
1526
 
1527
        case ACPI_PROCESSOR_LIMIT_NONE:
1528
                px = 0;
1529
                tx = 0;
1530
                break;
1531
 
1532
        case ACPI_PROCESSOR_LIMIT_INCREMENT:
1533
                if (pr->flags.performance) {
1534
                        if (px == (pr->performance.state_count - 1))
1535
                                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1536
                                        "At maximum performance state\n"));
1537
                        else {
1538
                                px++;
1539
                                goto end;
1540
                        }
1541
                }
1542
                if (pr->flags.throttling) {
1543
                        if (tx == (pr->throttling.state_count - 1))
1544
                                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1545
                                        "At maximum throttling state\n"));
1546
                        else
1547
                                tx++;
1548
                }
1549
                break;
1550
 
1551
        case ACPI_PROCESSOR_LIMIT_DECREMENT:
1552
                if (pr->flags.performance) {
1553
                        if (px == pr->performance.platform_limit)
1554
                                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1555
                                        "At minimum performance state\n"));
1556
                        else  {
1557
                                px--;
1558
                                goto end;
1559
                        }
1560
                }
1561
                if (pr->flags.throttling) {
1562
                        if (tx == 0)
1563
                                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1564
                                        "At minimum throttling state\n"));
1565
                        else
1566
                                tx--;
1567
                }
1568
                break;
1569
        }
1570
 
1571
end:
1572
        pr->limit.thermal.px = px;
1573
        pr->limit.thermal.tx = tx;
1574
 
1575
        result = acpi_processor_apply_limit(pr);
1576
        if (result)
1577
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1578
                        "Unable to set thermal limit\n"));
1579
 
1580
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Thermal limit now (P%d:T%d)\n",
1581
                pr->limit.thermal.px,
1582
                pr->limit.thermal.tx));
1583
 
1584
        return_VALUE(result);
1585
}
1586
 
1587
 
1588
static int
1589
acpi_processor_get_limit_info (
1590
        struct acpi_processor   *pr)
1591
{
1592
        ACPI_FUNCTION_TRACE("acpi_processor_get_limit_info");
1593
 
1594
        if (!pr)
1595
                return_VALUE(-EINVAL);
1596
 
1597
        if (pr->flags.performance || pr->flags.throttling)
1598
                pr->flags.limit = 1;
1599
 
1600
        return_VALUE(0);
1601
}
1602
 
1603
 
1604
/* --------------------------------------------------------------------------
1605
                              FS Interface (/proc)
1606
   -------------------------------------------------------------------------- */
1607
 
1608
struct proc_dir_entry           *acpi_processor_dir = NULL;
1609
 
1610
static int
1611
acpi_processor_read_info (
1612
        char                    *page,
1613
        char                    **start,
1614
        off_t                   off,
1615
        int                     count,
1616
        int                     *eof,
1617
        void                    *data)
1618
{
1619
        struct acpi_processor   *pr = (struct acpi_processor *) data;
1620
        char                    *p = page;
1621
        int                     len = 0;
1622
 
1623
        ACPI_FUNCTION_TRACE("acpi_processor_read_info");
1624
 
1625
        if (!pr || (off != 0))
1626
                goto end;
1627
 
1628
        p += sprintf(p, "processor id:            %d\n",
1629
                pr->id);
1630
 
1631
        p += sprintf(p, "acpi id:                 %d\n",
1632
                pr->acpi_id);
1633
 
1634
        p += sprintf(p, "bus mastering control:   %s\n",
1635
                pr->flags.bm_control ? "yes" : "no");
1636
 
1637
        p += sprintf(p, "power management:        %s\n",
1638
                pr->flags.power ? "yes" : "no");
1639
 
1640
        p += sprintf(p, "throttling control:      %s\n",
1641
                pr->flags.throttling ? "yes" : "no");
1642
 
1643
        p += sprintf(p, "performance management:  %s\n",
1644
                pr->flags.performance ? "yes" : "no");
1645
 
1646
        p += sprintf(p, "limit interface:         %s\n",
1647
                pr->flags.limit ? "yes" : "no");
1648
 
1649
end:
1650
        len = (p - page);
1651
        if (len <= off+count) *eof = 1;
1652
        *start = page + off;
1653
        len -= off;
1654
        if (len>count) len = count;
1655
        if (len<0) len = 0;
1656
 
1657
        return_VALUE(len);
1658
}
1659
 
1660
 
1661
static int
1662
acpi_processor_read_power (
1663
        char                    *page,
1664
        char                    **start,
1665
        off_t                   off,
1666
        int                     count,
1667
        int                     *eof,
1668
        void                    *data)
1669
{
1670
        struct acpi_processor   *pr = (struct acpi_processor *) data;
1671
        char                    *p = page;
1672
        int                     len = 0;
1673
        int                     i = 0;
1674
 
1675
        ACPI_FUNCTION_TRACE("acpi_processor_read_power");
1676
 
1677
        if (!pr || (off != 0))
1678
                goto end;
1679
 
1680
        p += sprintf(p, "active state:            C%d\n",
1681
                pr->power.state);
1682
 
1683
        p += sprintf(p, "default state:           C%d\n",
1684
                pr->power.default_state);
1685
 
1686
        p += sprintf(p, "bus master activity:     %08x\n",
1687
                pr->power.bm_activity);
1688
 
1689
        p += sprintf(p, "states:\n");
1690
 
1691
        for (i=1; i<ACPI_C_STATE_COUNT; i++) {
1692
 
1693
                p += sprintf(p, "   %cC%d:                  ",
1694
                        (i == pr->power.state?'*':' '), i);
1695
 
1696
                if (!pr->power.states[i].valid) {
1697
                        p += sprintf(p, "<not supported>\n");
1698
                        continue;
1699
                }
1700
 
1701
                if (pr->power.states[i].promotion.state)
1702
                        p += sprintf(p, "promotion[C%d] ",
1703
                                pr->power.states[i].promotion.state);
1704
                else
1705
                        p += sprintf(p, "promotion[--] ");
1706
 
1707
                if (pr->power.states[i].demotion.state)
1708
                        p += sprintf(p, "demotion[C%d] ",
1709
                                pr->power.states[i].demotion.state);
1710
                else
1711
                        p += sprintf(p, "demotion[--] ");
1712
 
1713
                p += sprintf(p, "latency[%03d] usage[%08d]\n",
1714
                        pr->power.states[i].latency,
1715
                        pr->power.states[i].usage);
1716
        }
1717
 
1718
end:
1719
        len = (p - page);
1720
        if (len <= off+count) *eof = 1;
1721
        *start = page + off;
1722
        len -= off;
1723
        if (len>count) len = count;
1724
        if (len<0) len = 0;
1725
 
1726
        return_VALUE(len);
1727
}
1728
 
1729
 
1730
static int
1731
acpi_processor_read_performance (
1732
        char                    *page,
1733
        char                    **start,
1734
        off_t                   off,
1735
        int                     count,
1736
        int                     *eof,
1737
        void                    *data)
1738
{
1739
        struct acpi_processor   *pr = (struct acpi_processor *) data;
1740
        char                    *p = page;
1741
        int                     len = 0;
1742
        int                     i = 0;
1743
 
1744
        ACPI_FUNCTION_TRACE("acpi_processor_read_performance");
1745
 
1746
        if (!pr || (off != 0))
1747
                goto end;
1748
 
1749
        if (!pr->flags.performance) {
1750
                p += sprintf(p, "<not supported>\n");
1751
                goto end;
1752
        }
1753
 
1754
        p += sprintf(p, "state count:             %d\n",
1755
                pr->performance.state_count);
1756
 
1757
        p += sprintf(p, "active state:            P%d\n",
1758
                pr->performance.state);
1759
 
1760
        p += sprintf(p, "states:\n");
1761
 
1762
        for (i=0; i<pr->performance.state_count; i++)
1763
                p += sprintf(p, "   %cP%d:                  %d MHz, %d mW, %d uS\n",
1764
                        (i == pr->performance.state?'*':' '), i,
1765
                        (u32) pr->performance.states[i].core_frequency,
1766
                        (u32) pr->performance.states[i].power,
1767
                        (u32) pr->performance.states[i].transition_latency);
1768
 
1769
end:
1770
        len = (p - page);
1771
        if (len <= off+count) *eof = 1;
1772
        *start = page + off;
1773
        len -= off;
1774
        if (len>count) len = count;
1775
        if (len<0) len = 0;
1776
 
1777
        return_VALUE(len);
1778
}
1779
 
1780
 
1781
static int
1782
acpi_processor_write_performance (
1783
        struct file             *file,
1784
        const char              *buffer,
1785
        unsigned long           count,
1786
        void                    *data)
1787
{
1788
        int                     result = 0;
1789
        struct acpi_processor   *pr = (struct acpi_processor *) data;
1790
        char                    state_string[12] = {'\0'};
1791
 
1792
        ACPI_FUNCTION_TRACE("acpi_processor_write_performance");
1793
 
1794
        if (!pr || (count > sizeof(state_string) - 1))
1795
                return_VALUE(-EINVAL);
1796
 
1797
        if (copy_from_user(state_string, buffer, count))
1798
                return_VALUE(-EFAULT);
1799
 
1800
        state_string[count] = '\0';
1801
 
1802
        result = acpi_processor_set_performance(pr,
1803
                simple_strtoul(state_string, NULL, 0));
1804
        if (result)
1805
                return_VALUE(result);
1806
 
1807
        return_VALUE(count);
1808
}
1809
 
1810
 
1811
static int
1812
acpi_processor_read_throttling (
1813
        char                    *page,
1814
        char                    **start,
1815
        off_t                   off,
1816
        int                     count,
1817
        int                     *eof,
1818
        void                    *data)
1819
{
1820
        struct acpi_processor   *pr = (struct acpi_processor *) data;
1821
        char                    *p = page;
1822
        int                     len = 0;
1823
        int                     i = 0;
1824
        int                     result = 0;
1825
 
1826
        ACPI_FUNCTION_TRACE("acpi_processor_read_throttling");
1827
 
1828
        if (!pr || (off != 0))
1829
                goto end;
1830
 
1831
        if (!(pr->throttling.state_count > 0)) {
1832
                p += sprintf(p, "<not supported>\n");
1833
                goto end;
1834
        }
1835
 
1836
        result = acpi_processor_get_throttling(pr);
1837
 
1838
        if (result) {
1839
                p += sprintf(p, "Could not determine current throttling state.\n");
1840
                goto end;
1841
        }
1842
 
1843
        p += sprintf(p, "state count:             %d\n",
1844
                pr->throttling.state_count);
1845
 
1846
        p += sprintf(p, "active state:            T%d\n",
1847
                pr->throttling.state);
1848
 
1849
        p += sprintf(p, "states:\n");
1850
 
1851
        for (i=0; i<pr->throttling.state_count; i++)
1852
                p += sprintf(p, "   %cT%d:                  %02d%%\n",
1853
                        (i == pr->throttling.state?'*':' '), i,
1854
                        (pr->throttling.states[i].performance?pr->throttling.states[i].performance/10:0));
1855
 
1856
end:
1857
        len = (p - page);
1858
        if (len <= off+count) *eof = 1;
1859
        *start = page + off;
1860
        len -= off;
1861
        if (len>count) len = count;
1862
        if (len<0) len = 0;
1863
 
1864
        return_VALUE(len);
1865
}
1866
 
1867
 
1868
static int
1869
acpi_processor_write_throttling (
1870
        struct file             *file,
1871
        const char              *buffer,
1872
        unsigned long           count,
1873
        void                    *data)
1874
{
1875
        int                     result = 0;
1876
        struct acpi_processor   *pr = (struct acpi_processor *) data;
1877
        char                    state_string[12] = {'\0'};
1878
 
1879
        ACPI_FUNCTION_TRACE("acpi_processor_write_throttling");
1880
 
1881
        if (!pr || (count > sizeof(state_string) - 1))
1882
                return_VALUE(-EINVAL);
1883
 
1884
        if (copy_from_user(state_string, buffer, count))
1885
                return_VALUE(-EFAULT);
1886
 
1887
        state_string[count] = '\0';
1888
 
1889
        result = acpi_processor_set_throttling(pr,
1890
                simple_strtoul(state_string, NULL, 0));
1891
        if (result)
1892
                return_VALUE(result);
1893
 
1894
        return_VALUE(count);
1895
}
1896
 
1897
 
1898
static int
1899
acpi_processor_read_limit (
1900
        char                    *page,
1901
        char                    **start,
1902
        off_t                   off,
1903
        int                     count,
1904
        int                     *eof,
1905
        void                    *data)
1906
{
1907
        struct acpi_processor   *pr = (struct acpi_processor *) data;
1908
        char                    *p = page;
1909
        int                     len = 0;
1910
 
1911
        ACPI_FUNCTION_TRACE("acpi_processor_read_limit");
1912
 
1913
        if (!pr || (off != 0))
1914
                goto end;
1915
 
1916
        if (!pr->flags.limit) {
1917
                p += sprintf(p, "<not supported>\n");
1918
                goto end;
1919
        }
1920
 
1921
        p += sprintf(p, "active limit:            P%d:T%d\n",
1922
                pr->limit.state.px, pr->limit.state.tx);
1923
 
1924
        p += sprintf(p, "platform limit:          P%d:T0\n",
1925
                pr->flags.performance?pr->performance.platform_limit:0);
1926
 
1927
        p += sprintf(p, "user limit:              P%d:T%d\n",
1928
                pr->limit.user.px, pr->limit.user.tx);
1929
 
1930
        p += sprintf(p, "thermal limit:           P%d:T%d\n",
1931
                pr->limit.thermal.px, pr->limit.thermal.tx);
1932
 
1933
end:
1934
        len = (p - page);
1935
        if (len <= off+count) *eof = 1;
1936
        *start = page + off;
1937
        len -= off;
1938
        if (len>count) len = count;
1939
        if (len<0) len = 0;
1940
 
1941
        return_VALUE(len);
1942
}
1943
 
1944
 
1945
static int
1946
acpi_processor_write_limit (
1947
        struct file             *file,
1948
        const char              *buffer,
1949
        unsigned long           count,
1950
        void                    *data)
1951
{
1952
        int                     result = 0;
1953
        struct acpi_processor   *pr = (struct acpi_processor *) data;
1954
        char                    limit_string[25] = {'\0'};
1955
        int                     px = 0;
1956
        int                     tx = 0;
1957
 
1958
        ACPI_FUNCTION_TRACE("acpi_processor_write_limit");
1959
 
1960
        if (!pr || (count > sizeof(limit_string) - 1)) {
1961
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument\n"));
1962
                return_VALUE(-EINVAL);
1963
        }
1964
 
1965
        if (copy_from_user(limit_string, buffer, count)) {
1966
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data\n"));
1967
                return_VALUE(-EFAULT);
1968
        }
1969
 
1970
        limit_string[count] = '\0';
1971
 
1972
        if (sscanf(limit_string, "%d:%d", &px, &tx) != 2) {
1973
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data format\n"));
1974
                return_VALUE(-EINVAL);
1975
        }
1976
 
1977
        if (pr->flags.performance) {
1978
                if ((px < pr->performance.platform_limit)
1979
                        || (px > (pr->performance.state_count - 1))) {
1980
                        ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid px\n"));
1981
                        return_VALUE(-EINVAL);
1982
                }
1983
                pr->limit.user.px = px;
1984
        }
1985
 
1986
        if (pr->flags.throttling) {
1987
                if ((tx < 0) || (tx > (pr->throttling.state_count - 1))) {
1988
                        ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid tx\n"));
1989
                        return_VALUE(-EINVAL);
1990
                }
1991
                pr->limit.user.tx = tx;
1992
        }
1993
 
1994
        result = acpi_processor_apply_limit(pr);
1995
 
1996
        return_VALUE(count);
1997
}
1998
 
1999
 
2000
static int
2001
acpi_processor_add_fs (
2002
        struct acpi_device      *device)
2003
{
2004
        struct proc_dir_entry   *entry = NULL;
2005
 
2006
        ACPI_FUNCTION_TRACE("acpi_processor_add_fs");
2007
 
2008
        if (!acpi_device_dir(device)) {
2009
                acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
2010
                        acpi_processor_dir);
2011
                if (!acpi_device_dir(device))
2012
                        return_VALUE(-ENODEV);
2013
        }
2014
 
2015
        /* 'info' [R] */
2016
        entry = create_proc_entry(ACPI_PROCESSOR_FILE_INFO,
2017
                S_IRUGO, acpi_device_dir(device));
2018
        if (!entry)
2019
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2020
                        "Unable to create '%s' fs entry\n",
2021
                        ACPI_PROCESSOR_FILE_INFO));
2022
        else {
2023
                entry->read_proc = acpi_processor_read_info;
2024
                entry->data = acpi_driver_data(device);
2025
        }
2026
 
2027
        /* 'power' [R] */
2028
        entry = create_proc_entry(ACPI_PROCESSOR_FILE_POWER,
2029
                S_IRUGO, acpi_device_dir(device));
2030
        if (!entry)
2031
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2032
                        "Unable to create '%s' fs entry\n",
2033
                        ACPI_PROCESSOR_FILE_POWER));
2034
        else {
2035
                entry->read_proc = acpi_processor_read_power;
2036
                entry->data = acpi_driver_data(device);
2037
        }
2038
 
2039
        /* 'performance' [R/W] */
2040
        entry = create_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE,
2041
                S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
2042
        if (!entry)
2043
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2044
                        "Unable to create '%s' fs entry\n",
2045
                        ACPI_PROCESSOR_FILE_PERFORMANCE));
2046
        else {
2047
                entry->read_proc = acpi_processor_read_performance;
2048
                entry->write_proc = acpi_processor_write_performance;
2049
                entry->data = acpi_driver_data(device);
2050
        }
2051
 
2052
        /* 'throttling' [R/W] */
2053
        entry = create_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
2054
                S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
2055
        if (!entry)
2056
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2057
                        "Unable to create '%s' fs entry\n",
2058
                        ACPI_PROCESSOR_FILE_THROTTLING));
2059
        else {
2060
                entry->read_proc = acpi_processor_read_throttling;
2061
                entry->write_proc = acpi_processor_write_throttling;
2062
                entry->data = acpi_driver_data(device);
2063
        }
2064
 
2065
        /* 'limit' [R/W] */
2066
        entry = create_proc_entry(ACPI_PROCESSOR_FILE_LIMIT,
2067
                S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
2068
        if (!entry)
2069
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2070
                        "Unable to create '%s' fs entry\n",
2071
                        ACPI_PROCESSOR_FILE_LIMIT));
2072
        else {
2073
                entry->read_proc = acpi_processor_read_limit;
2074
                entry->write_proc = acpi_processor_write_limit;
2075
                entry->data = acpi_driver_data(device);
2076
        }
2077
 
2078
        return_VALUE(0);
2079
}
2080
 
2081
 
2082
static int
2083
acpi_processor_remove_fs (
2084
        struct acpi_device      *device)
2085
{
2086
        ACPI_FUNCTION_TRACE("acpi_processor_remove_fs");
2087
 
2088
        if (acpi_device_dir(device)) {
2089
                remove_proc_entry(acpi_device_bid(device), acpi_processor_dir);
2090
                acpi_device_dir(device) = NULL;
2091
        }
2092
 
2093
        return_VALUE(0);
2094
}
2095
 
2096
 
2097
/* --------------------------------------------------------------------------
2098
                                 Driver Interface
2099
   -------------------------------------------------------------------------- */
2100
 
2101
static int
2102
acpi_processor_get_info (
2103
        struct acpi_processor   *pr)
2104
{
2105
        acpi_status             status = 0;
2106
        union acpi_object       object = {0};
2107
        struct acpi_buffer      buffer = {sizeof(union acpi_object), &object};
2108
        static int              cpu_index = 0;
2109
 
2110
        ACPI_FUNCTION_TRACE("acpi_processor_get_info");
2111
 
2112
        if (!pr)
2113
                return_VALUE(-EINVAL);
2114
 
2115
#ifdef CONFIG_SMP
2116
        if (smp_num_cpus > 1)
2117
                errata.smp = smp_num_cpus;
2118
 
2119
        /*
2120
         *  Extra Processor objects may be enumerated on MP systems with
2121
         *  less than the max # of CPUs. They should be ignored.
2122
         */
2123
        if ((cpu_index + 1) > smp_num_cpus)
2124
                return_VALUE(-ENODEV);
2125
#endif
2126
 
2127
        acpi_processor_errata(pr);
2128
 
2129
        /*
2130
         * Check to see if we have bus mastering arbitration control.  This
2131
         * is required for proper C3 usage (to maintain cache coherency).
2132
         */
2133
        if (acpi_fadt.V1_pm2_cnt_blk && acpi_fadt.pm2_cnt_len) {
2134
                pr->flags.bm_control = 1;
2135
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2136
                        "Bus mastering arbitration control present\n"));
2137
        }
2138
        else
2139
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2140
                        "No bus mastering arbitration control\n"));
2141
 
2142
        /*
2143
         * Evalute the processor object.  Note that it is common on SMP to
2144
         * have the first (boot) processor with a valid PBLK address while
2145
         * all others have a NULL address.
2146
         */
2147
        status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
2148
        if (ACPI_FAILURE(status)) {
2149
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2150
                        "Error evaluating processor object\n"));
2151
                return_VALUE(-ENODEV);
2152
        }
2153
 
2154
        /*
2155
         * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
2156
         *      >>> 'acpi_get_processor_id(acpi_id, &id)' in arch/xxx/acpi.c
2157
         */
2158
        pr->id = cpu_index++;
2159
        pr->acpi_id = object.processor.proc_id;
2160
 
2161
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
2162
                pr->acpi_id));
2163
 
2164
        if (!object.processor.pblk_address)
2165
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
2166
        else if (object.processor.pblk_length != 6)
2167
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid PBLK length [%d]\n",
2168
                        object.processor.pblk_length));
2169
        else {
2170
                pr->throttling.address = object.processor.pblk_address;
2171
                pr->throttling.duty_offset = acpi_fadt.duty_offset;
2172
                pr->throttling.duty_width = acpi_fadt.duty_width;
2173
                pr->power.states[ACPI_STATE_C2].address =
2174
                        object.processor.pblk_address + 4;
2175
                pr->power.states[ACPI_STATE_C3].address =
2176
                        object.processor.pblk_address + 5;
2177
        }
2178
 
2179
        acpi_processor_get_power_info(pr);
2180
        acpi_processor_get_performance_info(pr);
2181
        acpi_processor_get_throttling_info(pr);
2182
        acpi_processor_get_limit_info(pr);
2183
 
2184
        return_VALUE(0);
2185
}
2186
 
2187
 
2188
static void
2189
acpi_processor_notify (
2190
        acpi_handle             handle,
2191
        u32                     event,
2192
        void                    *data)
2193
{
2194
        int                     result = 0;
2195
        struct acpi_processor   *pr = (struct acpi_processor *) data;
2196
        struct acpi_device      *device = NULL;
2197
 
2198
        ACPI_FUNCTION_TRACE("acpi_processor_notify");
2199
 
2200
        if (!pr)
2201
                return_VOID;
2202
 
2203
        if (acpi_bus_get_device(pr->handle, &device))
2204
                return_VOID;
2205
 
2206
        switch (event) {
2207
        case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
2208
                result = acpi_processor_get_platform_limit(pr);
2209
                if (!result)
2210
                        acpi_processor_apply_limit(pr);
2211
 
2212
                acpi_bus_generate_event(device, event,
2213
                        pr->performance.platform_limit);
2214
                break;
2215
        case ACPI_PROCESSOR_NOTIFY_POWER:
2216
                /* TBD */
2217
                acpi_bus_generate_event(device, event, 0);
2218
                break;
2219
        default:
2220
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2221
                        "Unsupported event [0x%x]\n", event));
2222
                break;
2223
        }
2224
 
2225
        return_VOID;
2226
}
2227
 
2228
 
2229
static int
2230
acpi_processor_add (
2231
        struct acpi_device      *device)
2232
{
2233
        int                     result = 0;
2234
        acpi_status             status = AE_OK;
2235
        struct acpi_processor   *pr = NULL;
2236
        u32                     i = 0;
2237
 
2238
        ACPI_FUNCTION_TRACE("acpi_processor_add");
2239
 
2240
        if (!device)
2241
                return_VALUE(-EINVAL);
2242
 
2243
        pr = kmalloc(sizeof(struct acpi_processor), GFP_KERNEL);
2244
        if (!pr)
2245
                return_VALUE(-ENOMEM);
2246
        memset(pr, 0, sizeof(struct acpi_processor));
2247
 
2248
        pr->handle = device->handle;
2249
        sprintf(acpi_device_name(device), "%s", ACPI_PROCESSOR_DEVICE_NAME);
2250
        sprintf(acpi_device_class(device), "%s", ACPI_PROCESSOR_CLASS);
2251
        acpi_driver_data(device) = pr;
2252
 
2253
        result = acpi_processor_get_info(pr);
2254
        if (result)
2255
                goto end;
2256
 
2257
        result = acpi_processor_add_fs(device);
2258
        if (result)
2259
                goto end;
2260
 
2261
        status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
2262
                acpi_processor_notify, pr);
2263
        if (ACPI_FAILURE(status)) {
2264
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2265
                        "Error installing notify handler\n"));
2266
                result = -ENODEV;
2267
                goto end;
2268
        }
2269
 
2270
        processors[pr->id] = pr;
2271
 
2272
        /*
2273
         * Install the idle handler if processor power management is supported.
2274
         * Note that the default idle handler (default_idle) will be used on
2275
         * platforms that only support C1.
2276
         */
2277
        if ((pr->id == 0) && (pr->flags.power)) {
2278
                pm_idle_save = pm_idle;
2279
                pm_idle = acpi_processor_idle;
2280
        }
2281
 
2282
        printk(KERN_INFO PREFIX "%s [%s] (supports",
2283
                acpi_device_name(device), acpi_device_bid(device));
2284
        for (i=1; i<ACPI_C_STATE_COUNT; i++)
2285
                if (pr->power.states[i].valid)
2286
                        printk(" C%d", i);
2287
        if (pr->flags.performance)
2288
                printk(", %d performance states", pr->performance.state_count);
2289
        if (pr->flags.throttling)
2290
                printk(", %d throttling states", pr->throttling.state_count);
2291
        printk(")\n");
2292
 
2293
end:
2294
        if (result) {
2295
                acpi_processor_remove_fs(device);
2296
                kfree(pr);
2297
        }
2298
 
2299
        return_VALUE(result);
2300
}
2301
 
2302
 
2303
static int
2304
acpi_processor_remove (
2305
        struct acpi_device      *device,
2306
        int                     type)
2307
{
2308
        acpi_status             status = AE_OK;
2309
        struct acpi_processor   *pr = NULL;
2310
 
2311
        ACPI_FUNCTION_TRACE("acpi_processor_remove");
2312
 
2313
        if (!device || !acpi_driver_data(device))
2314
                return_VALUE(-EINVAL);
2315
 
2316
        pr = (struct acpi_processor *) acpi_driver_data(device);
2317
 
2318
        /* Unregister the idle handler when processor #0 is removed. */
2319
        if (pr->id == 0)
2320
                pm_idle = pm_idle_save;
2321
 
2322
        status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
2323
                acpi_processor_notify);
2324
        if (ACPI_FAILURE(status)) {
2325
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2326
                        "Error removing notify handler\n"));
2327
        }
2328
 
2329
        acpi_processor_remove_fs(device);
2330
 
2331
        processors[pr->id] = NULL;
2332
 
2333
        kfree(pr);
2334
 
2335
        return_VALUE(0);
2336
}
2337
 
2338
 
2339
static int __init
2340
acpi_processor_init (void)
2341
{
2342
        int                     result = 0;
2343
 
2344
        ACPI_FUNCTION_TRACE("acpi_processor_init");
2345
 
2346
        memset(&processors, 0, sizeof(processors));
2347
        memset(&errata, 0, sizeof(errata));
2348
 
2349
        acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
2350
        if (!acpi_processor_dir)
2351
                return_VALUE(-ENODEV);
2352
 
2353
        result = acpi_bus_register_driver(&acpi_processor_driver);
2354
        if (result < 0) {
2355
                remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
2356
                return_VALUE(-ENODEV);
2357
        }
2358
 
2359
        return_VALUE(0);
2360
}
2361
 
2362
 
2363
static void __exit
2364
acpi_processor_exit (void)
2365
{
2366
        ACPI_FUNCTION_TRACE("acpi_processor_exit");
2367
 
2368
        acpi_bus_unregister_driver(&acpi_processor_driver);
2369
 
2370
        remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
2371
 
2372
        return_VOID;
2373
}
2374
 
2375
 
2376
module_init(acpi_processor_init);
2377
module_exit(acpi_processor_exit);
2378
 
2379
EXPORT_SYMBOL(acpi_processor_set_thermal_limit);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.