aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ia64/sn/io/sgi_if.c
blob: 2303cba48f3c4b085143de34ba33a4bde491c143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* $Id$
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
 */

#include <linux/types.h>
#include <linux/ctype.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <asm/sn/sgi.h>
#include <asm/sn/invent.h>
#include <asm/sn/hcl.h>
#include <asm/sn/labelcl.h>
#include <asm/sn/pci/bridge.h>
#include <asm/sn/ioerror_handling.h>
#include <asm/sn/pci/pciio.h>
#include <asm/sn/slotnum.h>

unsigned char Is_pic_on_this_nasid[512];	/* non-0 when this is a pic shub */

void *
snia_kmem_zalloc(size_t size, int flag)
{
        void *ptr = kmalloc(size, GFP_KERNEL);
	if ( ptr )
        	BZERO(ptr, size);
        return(ptr);
}

void
snia_kmem_free(void *ptr, size_t size)
{
        kfree(ptr);
}

int
nic_vertex_info_match(devfs_handle_t v, char *s)
{
	/* we don't support this */
	return(0);
}

/*
 * the alloc/free_node routines do a simple kmalloc for now ..
 */
void *
snia_kmem_alloc_node(register size_t size, register int flags, cnodeid_t node)
{
	/* someday will Allocate on node 'node' */
	return(kmalloc(size, GFP_KERNEL));
}

void *
snia_kmem_zalloc_node(register size_t size, register int flags, cnodeid_t node)
{
	void *ptr = kmalloc(size, GFP_KERNEL);
	if ( ptr )
		BZERO(ptr, size);
        return(ptr);
}


#define xtod(c)         ((c) <= '9' ? '0' - (c) : 'a' - (c) - 10)
long
atoi(register char *p)
{
        register long n;
        register int c, neg = 0;

        if (p == NULL)
                return 0;

        if (!isdigit(c = *p)) {
                while (isspace(c))
                        c = *++p;
                switch (c) {
                case '-':
                        neg++;
                case '+': /* fall-through */
                        c = *++p;
                }
                if (!isdigit(c))
                        return (0);
        }
        if (c == '0' && *(p + 1) == 'x') {
                p += 2;
                c = *p;
                n = xtod(c);
                while ((c = *++p) && isxdigit(c)) {
                        n *= 16; /* two steps to avoid unnecessary overflow */
                        n += xtod(c); /* accum neg to avoid surprises at MAX */
                }
        } else {
                n = '0' - c;
                while ((c = *++p) && isdigit(c)) {
                        n *= 10; /* two steps to avoid unnecessary overflow */
                        n += '0' - c; /* accum neg to avoid surprises at MAX */
                }
        }
        return (neg ? n : -n);
}

char *
strtok_r(char *string, const char *sepset, char **lasts)
{
        register char   *q, *r;

        /*first or subsequent call*/
        if (string == NULL)
                string = *lasts;

        if(string == 0)         /* return if no tokens remaining */
                return(NULL);

        q = string + strspn(string, sepset);    /* skip leading separators */

        if(*q == '\0') {                /* return if no tokens remaining */
                *lasts = 0;     /* indicate this is last token */
                return(NULL);
        }

        if((r = strpbrk(q, sepset)) == NULL)    /* move past token */
                *lasts = 0;     /* indicate this is last token */
        else {
                *r = '\0';
                *lasts = r+1;
        }
        return(q);
}

/*
 * print_register() allows formatted printing of bit fields.  individual
 * bit fields are described by a struct reg_desc, multiple bit fields within
 * a single word can be described by multiple reg_desc structures.
 * %r outputs a string of the format "<bit field descriptions>"
 * %R outputs a string of the format "0x%x<bit field descriptions>"
 *
 * The fields in a reg_desc are:
 *	unsigned long long rd_mask; An appropriate mask to isolate the bit field
 *				within a word, and'ed with val
 *
 *	int rd_shift;		A shift amount to be done to the isolated
 *				bit field.  done before printing the isolate
 *				bit field with rd_format and before searching
 *				for symbolic value names in rd_values
 *
 *	char *rd_name;		If non-null, a bit field name to label any
 *				out from rd_format or searching rd_values.
 *				if neither rd_format or rd_values is non-null
 *				rd_name is printed only if the isolated
 *				bit field is non-null.
 *
 *	char *rd_format;	If non-null, the shifted bit field value
 *				is printed using this format.
 *
 *	struct reg_values *rd_values;	If non-null, a pointer to a table
 *				matching numeric values with symbolic names.
 *				rd_values are searched and the symbolic
 *				value is printed if a match is found, if no
 *				match is found "???" is printed.
 *				
 */

void
print_register(unsigned long long reg, struct reg_desc *addr)
{
	register struct reg_desc *rd;
	register struct reg_values *rv;
	unsigned long long field;
	int any;

	printk("<");
	any = 0;
	for (rd = addr; rd->rd_mask; rd++) {
		field = reg & rd->rd_mask;
		field = (rd->rd_shift > 0) ? field << rd->rd_shift : field >> -rd->rd_shift;
		if (any && (rd->rd_format || rd->rd_values || (rd->rd_name && field)))
			printk(",");
		if (rd->rd_name) {
			if (rd->rd_format || rd->rd_values || field) {
				printk("%s", rd->rd_name);
				any = 1;
			}
			if (rd->rd_format || rd->rd_values) {
				printk("=");
				any = 1;
			}
		}
		/* You can have any format so long as it is %x */
		if (rd->rd_format) {
			printk("%llx", field);
			any = 1;
			if (rd->rd_values)
				printk(":");
		}
		if (rd->rd_values) {
			any = 1;
			for (rv = rd->rd_values; rv->rv_name; rv++) {
				if (field == rv->rv_value) {
					printk("%s", rv->rv_name);
					break;
				}
			}
			if (rv->rv_name == NULL)
				printk("???");
		}
	}
	printk(">\n");
}