ia64/linux-2.6.18-xen.hg

annotate scripts/binoffset.c @ 798:b02a90bf5bbc

ACPI: Backport missing part for T-State MSR support

Part of below kernel commit was missed while packporting T-State
support.

commit f79f06ab9f86d7203006d2ec8992ac80df36a34e
Author: Zhao Yakui <yakui.zhao@intel.com>
Date: Thu Nov 15 17:06:36 2007 +0800

ACPI: Enable MSR (FixedHW) support for T-States

Add throttling control via MSR when T-states uses
the FixHW Control Status registers.

Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Signed-off-by: Li Shaohua <shaohua.li@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>

Signed-off-by: Wei Gang <gang.wei@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Mar 02 10:53:59 2009 +0000 (2009-03-02)
parents 831230e53067
children
rev   line source
ian@0 1 /***************************************************************************
ian@0 2 * binoffset.c
ian@0 3 * (C) 2002 Randy Dunlap <rdunlap@xenotime.net>
ian@0 4
ian@0 5 # This program is free software; you can redistribute it and/or modify
ian@0 6 # it under the terms of the GNU General Public License as published by
ian@0 7 # the Free Software Foundation; either version 2 of the License, or
ian@0 8 # (at your option) any later version.
ian@0 9 #
ian@0 10 # This program is distributed in the hope that it will be useful,
ian@0 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
ian@0 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ian@0 13 # GNU General Public License for more details.
ian@0 14 #
ian@0 15 # You should have received a copy of the GNU General Public License
ian@0 16 # along with this program; if not, write to the Free Software
ian@0 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
ian@0 18
ian@0 19 # binoffset.c:
ian@0 20 # - searches a (binary) file for a specified (binary) pattern
ian@0 21 # - returns the offset of the located pattern or ~0 if not found
ian@0 22 # - exits with exit status 0 normally or non-0 if pattern is not found
ian@0 23 # or any other error occurs.
ian@0 24
ian@0 25 ****************************************************************/
ian@0 26
ian@0 27 #include <stdio.h>
ian@0 28 #include <stdlib.h>
ian@0 29 #include <string.h>
ian@0 30 #include <errno.h>
ian@0 31 #include <unistd.h>
ian@0 32 #include <fcntl.h>
ian@0 33 #include <sys/types.h>
ian@0 34 #include <sys/stat.h>
ian@0 35 #include <sys/mman.h>
ian@0 36
ian@0 37 #define VERSION "0.1"
ian@0 38 #define BUF_SIZE (16 * 1024)
ian@0 39 #define PAT_SIZE 100
ian@0 40
ian@0 41 char *progname;
ian@0 42 char *inputname;
ian@0 43 int inputfd;
ian@0 44 unsigned int bix; /* buf index */
ian@0 45 unsigned char patterns [PAT_SIZE] = {0}; /* byte-sized pattern array */
ian@0 46 int pat_len; /* actual number of pattern bytes */
ian@0 47 unsigned char *madr; /* mmap address */
ian@0 48 size_t filesize;
ian@0 49 int num_matches = 0;
ian@0 50 off_t firstloc = 0;
ian@0 51
ian@0 52 void usage (void)
ian@0 53 {
ian@0 54 fprintf (stderr, "%s ver. %s\n", progname, VERSION);
ian@0 55 fprintf (stderr, "usage: %s filename pattern_bytes\n",
ian@0 56 progname);
ian@0 57 fprintf (stderr, " [prints location of pattern_bytes in file]\n");
ian@0 58 exit (1);
ian@0 59 }
ian@0 60
ian@0 61 void get_pattern (int pat_count, char *pats [])
ian@0 62 {
ian@0 63 int ix, err, tmp;
ian@0 64
ian@0 65 #ifdef DEBUG
ian@0 66 fprintf (stderr,"get_pattern: count = %d\n", pat_count);
ian@0 67 for (ix = 0; ix < pat_count; ix++)
ian@0 68 fprintf (stderr, " pat # %d: [%s]\n", ix, pats[ix]);
ian@0 69 #endif
ian@0 70
ian@0 71 for (ix = 0; ix < pat_count; ix++) {
ian@0 72 tmp = 0;
ian@0 73 err = sscanf (pats[ix], "%5i", &tmp);
ian@0 74 if (err != 1 || tmp > 0xff) {
ian@0 75 fprintf (stderr, "pattern or value error in pattern # %d [%s]\n",
ian@0 76 ix, pats[ix]);
ian@0 77 usage ();
ian@0 78 }
ian@0 79 patterns [ix] = tmp;
ian@0 80 }
ian@0 81 pat_len = pat_count;
ian@0 82 }
ian@0 83
ian@0 84 void search_pattern (void)
ian@0 85 {
ian@0 86 for (bix = 0; bix < filesize; bix++) {
ian@0 87 if (madr[bix] == patterns[0]) {
ian@0 88 if (memcmp (&madr[bix], patterns, pat_len) == 0) {
ian@0 89 if (num_matches == 0)
ian@0 90 firstloc = bix;
ian@0 91 num_matches++;
ian@0 92 }
ian@0 93 }
ian@0 94 }
ian@0 95 }
ian@0 96
ian@0 97 #ifdef NOTDEF
ian@0 98 size_t get_filesize (int fd)
ian@0 99 {
ian@0 100 off_t end_off = lseek (fd, 0, SEEK_END);
ian@0 101 lseek (fd, 0, SEEK_SET);
ian@0 102 return (size_t) end_off;
ian@0 103 }
ian@0 104 #endif
ian@0 105
ian@0 106 size_t get_filesize (int fd)
ian@0 107 {
ian@0 108 int err;
ian@0 109 struct stat stat;
ian@0 110
ian@0 111 err = fstat (fd, &stat);
ian@0 112 fprintf (stderr, "filesize: %ld\n", err < 0 ? (long)err : stat.st_size);
ian@0 113 if (err < 0)
ian@0 114 return err;
ian@0 115 return (size_t) stat.st_size;
ian@0 116 }
ian@0 117
ian@0 118 int main (int argc, char *argv [])
ian@0 119 {
ian@0 120 progname = argv[0];
ian@0 121
ian@0 122 if (argc < 3)
ian@0 123 usage ();
ian@0 124
ian@0 125 get_pattern (argc - 2, argv + 2);
ian@0 126
ian@0 127 inputname = argv[1];
ian@0 128
ian@0 129 inputfd = open (inputname, O_RDONLY);
ian@0 130 if (inputfd == -1) {
ian@0 131 fprintf (stderr, "%s: cannot open '%s'\n",
ian@0 132 progname, inputname);
ian@0 133 exit (3);
ian@0 134 }
ian@0 135
ian@0 136 filesize = get_filesize (inputfd);
ian@0 137
ian@0 138 madr = mmap (0, filesize, PROT_READ, MAP_PRIVATE, inputfd, 0);
ian@0 139 if (madr == MAP_FAILED) {
ian@0 140 fprintf (stderr, "mmap error = %d\n", errno);
ian@0 141 close (inputfd);
ian@0 142 exit (4);
ian@0 143 }
ian@0 144
ian@0 145 search_pattern ();
ian@0 146
ian@0 147 if (munmap (madr, filesize))
ian@0 148 fprintf (stderr, "munmap error = %d\n", errno);
ian@0 149
ian@0 150 if (close (inputfd))
ian@0 151 fprintf (stderr, "%s: error %d closing '%s'\n",
ian@0 152 progname, errno, inputname);
ian@0 153
ian@0 154 fprintf (stderr, "number of pattern matches = %d\n", num_matches);
ian@0 155 if (num_matches == 0)
ian@0 156 firstloc = ~0;
ian@0 157 printf ("%ld\n", firstloc);
ian@0 158 fprintf (stderr, "%ld\n", firstloc);
ian@0 159
ian@0 160 exit (num_matches ? 0 : 2);
ian@0 161 }
ian@0 162
ian@0 163 /* end binoffset.c */