blob: c25fc906105935b91b6567af72ba7b978d7760d4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Compaq Hot Plug Controller Driver
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 *
8 * All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18 * NON INFRINGEMENT. See the GNU General Public License for more
19 * details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * Send feedback to <greg@kroah.com>
26 *
27 */
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/proc_fs.h>
33#include <linux/slab.h>
34#include <linux/workqueue.h>
35#include <linux/pci.h>
Greg Kroah-Hartman7a54f252006-10-13 20:05:19 -070036#include <linux/pci_hotplug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/uaccess.h>
38#include "cpqphp.h"
39#include "cpqphp_nvram.h"
40
41
42#define ROM_INT15_PHY_ADDR 0x0FF859
43#define READ_EV 0xD8A4
44#define WRITE_EV 0xD8A5
45
46struct register_foo {
47 union {
48 unsigned long lword; /* eax */
49 unsigned short word; /* ax */
50
51 struct {
52 unsigned char low; /* al */
53 unsigned char high; /* ah */
54 } byte;
55 } data;
56
57 unsigned char opcode; /* see below */
58 unsigned long length; /* if the reg. is a pointer, how much data */
59} __attribute__ ((packed));
60
61struct all_reg {
62 struct register_foo eax_reg;
63 struct register_foo ebx_reg;
64 struct register_foo ecx_reg;
65 struct register_foo edx_reg;
66 struct register_foo edi_reg;
67 struct register_foo esi_reg;
68 struct register_foo eflags_reg;
69} __attribute__ ((packed));
70
71
72struct ev_hrt_header {
73 u8 Version;
74 u8 num_of_ctrl;
75 u8 next;
76};
77
78struct ev_hrt_ctrl {
79 u8 bus;
80 u8 device;
81 u8 function;
82 u8 mem_avail;
83 u8 p_mem_avail;
84 u8 io_avail;
85 u8 bus_avail;
86 u8 next;
87};
88
89
90static u8 evbuffer_init;
91static u8 evbuffer_length;
92static u8 evbuffer[1024];
93
94static void __iomem *compaq_int15_entry_point;
95
Alex Chiang427438c2009-03-31 09:23:16 -060096/* lock for ordering int15_bios_call() */
97static spinlock_t int15_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99
100/* This is a series of function that deals with
Alex Chiang427438c2009-03-31 09:23:16 -0600101 * setting & getting the hotplug resource table in some environment variable.
102 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104/*
105 * We really shouldn't be doing this unless there is a _very_ good reason to!!!
106 * greg k-h
107 */
108
109
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400110static u32 add_byte(u32 **p_buffer, u8 value, u32 *used, u32 *avail)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 u8 **tByte;
113
114 if ((*used + 1) > *avail)
115 return(1);
Alex Chiang861fefb2009-03-31 09:23:11 -0600116
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800117 *((u8 *)*p_buffer) = value;
118 tByte = (u8 **)p_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 (*tByte)++;
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800120 *used += 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 return(0);
122}
123
124
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400125static u32 add_dword(u32 **p_buffer, u32 value, u32 *used, u32 *avail)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 if ((*used + 4) > *avail)
128 return(1);
129
130 **p_buffer = value;
131 (*p_buffer)++;
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800132 *used += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 return(0);
134}
135
136
137/*
138 * check_for_compaq_ROM
139 *
140 * this routine verifies that the ROM OEM string is 'COMPAQ'
141 *
142 * returns 0 for non-Compaq ROM, 1 for Compaq ROM
143 */
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800144static int check_for_compaq_ROM(void __iomem *rom_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
146 u8 temp1, temp2, temp3, temp4, temp5, temp6;
147 int result = 0;
148
149 temp1 = readb(rom_start + 0xffea + 0);
150 temp2 = readb(rom_start + 0xffea + 1);
151 temp3 = readb(rom_start + 0xffea + 2);
152 temp4 = readb(rom_start + 0xffea + 3);
153 temp5 = readb(rom_start + 0xffea + 4);
154 temp6 = readb(rom_start + 0xffea + 5);
155 if ((temp1 == 'C') &&
156 (temp2 == 'O') &&
157 (temp3 == 'M') &&
158 (temp4 == 'P') &&
159 (temp5 == 'A') &&
160 (temp6 == 'Q')) {
161 result = 1;
162 }
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800163 dbg("%s - returned %d\n", __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 return result;
165}
166
167
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800168static u32 access_EV(u16 operation, u8 *ev_name, u8 *buffer, u32 *buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
170 unsigned long flags;
171 int op = operation;
172 int ret_val;
Alex Chiang861fefb2009-03-31 09:23:11 -0600173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 if (!compaq_int15_entry_point)
175 return -ENODEV;
Alex Chiang861fefb2009-03-31 09:23:11 -0600176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 spin_lock_irqsave(&int15_lock, flags);
178 __asm__ (
179 "xorl %%ebx,%%ebx\n" \
180 "xorl %%edx,%%edx\n" \
181 "pushf\n" \
182 "push %%cs\n" \
183 "cli\n" \
184 "call *%6\n"
185 : "=c" (*buf_size), "=a" (ret_val)
186 : "a" (op), "c" (*buf_size), "S" (ev_name),
187 "D" (buffer), "m" (compaq_int15_entry_point)
188 : "%ebx", "%edx");
189 spin_unlock_irqrestore(&int15_lock, flags);
Alex Chiang861fefb2009-03-31 09:23:11 -0600190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 return((ret_val & 0xFF00) >> 8);
192}
193
194
195/*
196 * load_HRT
197 *
198 * Read the hot plug Resource Table from NVRAM
199 */
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800200static int load_HRT(void __iomem *rom_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
202 u32 available;
203 u32 temp_dword;
204 u8 temp_byte = 0xFF;
205 u32 rc;
206
Quentin Lambert656f9782014-09-07 20:02:47 +0200207 if (!check_for_compaq_ROM(rom_start))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 available = 1024;
211
Alex Chiang427438c2009-03-31 09:23:16 -0600212 /* Now load the EV */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 temp_dword = available;
214
215 rc = access_EV(READ_EV, "CQTHPS", evbuffer, &temp_dword);
216
217 evbuffer_length = temp_dword;
218
Alex Chiang427438c2009-03-31 09:23:16 -0600219 /* We're maintaining the resource lists so write FF to invalidate old
220 * info
221 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 temp_dword = 1;
223
224 rc = access_EV(WRITE_EV, "CQTHPS", &temp_byte, &temp_dword);
225
226 return rc;
227}
228
229
230/*
231 * store_HRT
232 *
233 * Save the hot plug Resource Table in NVRAM
234 */
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800235static u32 store_HRT(void __iomem *rom_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
237 u32 *buffer;
238 u32 *pFill;
239 u32 usedbytes;
240 u32 available;
241 u32 temp_dword;
242 u32 rc;
243 u8 loop;
244 u8 numCtrl = 0;
245 struct controller *ctrl;
246 struct pci_resource *resNode;
247 struct ev_hrt_header *p_EV_header;
248 struct ev_hrt_ctrl *p_ev_ctrl;
249
250 available = 1024;
251
Quentin Lambert656f9782014-09-07 20:02:47 +0200252 if (!check_for_compaq_ROM(rom_start))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 return(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800255 buffer = (u32 *) evbuffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 if (!buffer)
258 return(1);
259
260 pFill = buffer;
261 usedbytes = 0;
262
263 p_EV_header = (struct ev_hrt_header *) pFill;
264
265 ctrl = cpqhp_ctrl_list;
Alex Chiang861fefb2009-03-31 09:23:11 -0600266
Alex Chiang427438c2009-03-31 09:23:16 -0600267 /* The revision of this structure */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400268 rc = add_byte(&pFill, 1 + ctrl->push_flag, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 if (rc)
270 return(rc);
271
Alex Chiang427438c2009-03-31 09:23:16 -0600272 /* The number of controllers */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400273 rc = add_byte(&pFill, 1, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (rc)
275 return(rc);
276
277 while (ctrl) {
278 p_ev_ctrl = (struct ev_hrt_ctrl *) pFill;
279
280 numCtrl++;
281
Alex Chiang427438c2009-03-31 09:23:16 -0600282 /* The bus number */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400283 rc = add_byte(&pFill, ctrl->bus, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 if (rc)
285 return(rc);
286
Alex Chiang427438c2009-03-31 09:23:16 -0600287 /* The device Number */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400288 rc = add_byte(&pFill, PCI_SLOT(ctrl->pci_dev->devfn), &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 if (rc)
290 return(rc);
291
Alex Chiang427438c2009-03-31 09:23:16 -0600292 /* The function Number */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400293 rc = add_byte(&pFill, PCI_FUNC(ctrl->pci_dev->devfn), &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 if (rc)
295 return(rc);
296
Alex Chiang427438c2009-03-31 09:23:16 -0600297 /* Skip the number of available entries */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400298 rc = add_dword(&pFill, 0, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 if (rc)
300 return(rc);
301
Alex Chiang427438c2009-03-31 09:23:16 -0600302 /* Figure out memory Available */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 resNode = ctrl->mem_head;
305
306 loop = 0;
307
308 while (resNode) {
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800309 loop++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Alex Chiang427438c2009-03-31 09:23:16 -0600311 /* base */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400312 rc = add_dword(&pFill, resNode->base, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 if (rc)
314 return(rc);
315
Alex Chiang427438c2009-03-31 09:23:16 -0600316 /* length */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400317 rc = add_dword(&pFill, resNode->length, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 if (rc)
319 return(rc);
320
321 resNode = resNode->next;
322 }
323
Alex Chiang427438c2009-03-31 09:23:16 -0600324 /* Fill in the number of entries */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 p_ev_ctrl->mem_avail = loop;
326
Alex Chiang427438c2009-03-31 09:23:16 -0600327 /* Figure out prefetchable memory Available */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 resNode = ctrl->p_mem_head;
330
331 loop = 0;
332
333 while (resNode) {
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800334 loop++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Alex Chiang427438c2009-03-31 09:23:16 -0600336 /* base */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400337 rc = add_dword(&pFill, resNode->base, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 if (rc)
339 return(rc);
340
Alex Chiang427438c2009-03-31 09:23:16 -0600341 /* length */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400342 rc = add_dword(&pFill, resNode->length, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 if (rc)
344 return(rc);
345
346 resNode = resNode->next;
347 }
348
Alex Chiang427438c2009-03-31 09:23:16 -0600349 /* Fill in the number of entries */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 p_ev_ctrl->p_mem_avail = loop;
351
Alex Chiang427438c2009-03-31 09:23:16 -0600352 /* Figure out IO Available */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 resNode = ctrl->io_head;
355
356 loop = 0;
357
358 while (resNode) {
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800359 loop++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Alex Chiang427438c2009-03-31 09:23:16 -0600361 /* base */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400362 rc = add_dword(&pFill, resNode->base, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 if (rc)
364 return(rc);
365
Alex Chiang427438c2009-03-31 09:23:16 -0600366 /* length */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400367 rc = add_dword(&pFill, resNode->length, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 if (rc)
369 return(rc);
370
371 resNode = resNode->next;
372 }
373
Alex Chiang427438c2009-03-31 09:23:16 -0600374 /* Fill in the number of entries */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 p_ev_ctrl->io_avail = loop;
376
Alex Chiang427438c2009-03-31 09:23:16 -0600377 /* Figure out bus Available */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379 resNode = ctrl->bus_head;
380
381 loop = 0;
382
383 while (resNode) {
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800384 loop++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Alex Chiang427438c2009-03-31 09:23:16 -0600386 /* base */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400387 rc = add_dword(&pFill, resNode->base, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 if (rc)
389 return(rc);
390
Alex Chiang427438c2009-03-31 09:23:16 -0600391 /* length */
Ryan Desfosses3c78bc62014-04-18 20:13:49 -0400392 rc = add_dword(&pFill, resNode->length, &usedbytes, &available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (rc)
394 return(rc);
395
396 resNode = resNode->next;
397 }
398
Alex Chiang427438c2009-03-31 09:23:16 -0600399 /* Fill in the number of entries */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 p_ev_ctrl->bus_avail = loop;
401
402 ctrl = ctrl->next;
403 }
Alex Chiang861fefb2009-03-31 09:23:11 -0600404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 p_EV_header->num_of_ctrl = numCtrl;
406
Alex Chiang427438c2009-03-31 09:23:16 -0600407 /* Now store the EV */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 temp_dword = usedbytes;
410
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800411 rc = access_EV(WRITE_EV, "CQTHPS", (u8 *) buffer, &temp_dword);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 dbg("usedbytes = 0x%x, length = 0x%x\n", usedbytes, temp_dword);
414
415 evbuffer_length = temp_dword;
416
417 if (rc) {
418 err(msg_unable_to_save);
419 return(1);
420 }
421
422 return(0);
423}
424
425
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800426void compaq_nvram_init(void __iomem *rom_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
Quentin Lambert656f9782014-09-07 20:02:47 +0200428 if (rom_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
Quentin Lambert656f9782014-09-07 20:02:47 +0200430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 dbg("int15 entry = %p\n", compaq_int15_entry_point);
432
433 /* initialize our int15 lock */
434 spin_lock_init(&int15_lock);
435}
436
437
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800438int compaq_nvram_load(void __iomem *rom_start, struct controller *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
440 u8 bus, device, function;
441 u8 nummem, numpmem, numio, numbus;
442 u32 rc;
443 u8 *p_byte;
444 struct pci_resource *mem_node;
445 struct pci_resource *p_mem_node;
446 struct pci_resource *io_node;
447 struct pci_resource *bus_node;
448 struct ev_hrt_ctrl *p_ev_ctrl;
449 struct ev_hrt_header *p_EV_header;
450
451 if (!evbuffer_init) {
Alex Chiang427438c2009-03-31 09:23:16 -0600452 /* Read the resource list information in from NVRAM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if (load_HRT(rom_start))
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800454 memset(evbuffer, 0, 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456 evbuffer_init = 1;
457 }
458
Alex Chiang427438c2009-03-31 09:23:16 -0600459 /* If we saved information in NVRAM, use it now */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 p_EV_header = (struct ev_hrt_header *) evbuffer;
461
Alex Chiang427438c2009-03-31 09:23:16 -0600462 /* The following code is for systems where version 1.0 of this
463 * driver has been loaded, but doesn't support the hardware.
464 * In that case, the driver would incorrectly store something
465 * in NVRAM.
466 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 if ((p_EV_header->Version == 2) ||
468 ((p_EV_header->Version == 1) && !ctrl->push_flag)) {
469 p_byte = &(p_EV_header->next);
470
471 p_ev_ctrl = (struct ev_hrt_ctrl *) &(p_EV_header->next);
472
473 p_byte += 3;
474
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800475 if (p_byte > ((u8 *)p_EV_header + evbuffer_length))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return 2;
477
478 bus = p_ev_ctrl->bus;
479 device = p_ev_ctrl->device;
480 function = p_ev_ctrl->function;
481
482 while ((bus != ctrl->bus) ||
Alex Chiang861fefb2009-03-31 09:23:11 -0600483 (device != PCI_SLOT(ctrl->pci_dev->devfn)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 (function != PCI_FUNC(ctrl->pci_dev->devfn))) {
485 nummem = p_ev_ctrl->mem_avail;
486 numpmem = p_ev_ctrl->p_mem_avail;
487 numio = p_ev_ctrl->io_avail;
488 numbus = p_ev_ctrl->bus_avail;
489
490 p_byte += 4;
491
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800492 if (p_byte > ((u8 *)p_EV_header + evbuffer_length))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 return 2;
494
Alex Chiang427438c2009-03-31 09:23:16 -0600495 /* Skip forward to the next entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 p_byte += (nummem + numpmem + numio + numbus) * 8;
497
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800498 if (p_byte > ((u8 *)p_EV_header + evbuffer_length))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 return 2;
500
501 p_ev_ctrl = (struct ev_hrt_ctrl *) p_byte;
502
503 p_byte += 3;
504
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800505 if (p_byte > ((u8 *)p_EV_header + evbuffer_length))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 return 2;
507
508 bus = p_ev_ctrl->bus;
509 device = p_ev_ctrl->device;
510 function = p_ev_ctrl->function;
511 }
512
513 nummem = p_ev_ctrl->mem_avail;
514 numpmem = p_ev_ctrl->p_mem_avail;
515 numio = p_ev_ctrl->io_avail;
516 numbus = p_ev_ctrl->bus_avail;
517
518 p_byte += 4;
519
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800520 if (p_byte > ((u8 *)p_EV_header + evbuffer_length))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 return 2;
522
523 while (nummem--) {
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800524 mem_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 if (!mem_node)
527 break;
528
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800529 mem_node->base = *(u32 *)p_byte;
530 dbg("mem base = %8.8x\n", mem_node->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 p_byte += 4;
532
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800533 if (p_byte > ((u8 *)p_EV_header + evbuffer_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 kfree(mem_node);
535 return 2;
536 }
537
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800538 mem_node->length = *(u32 *)p_byte;
539 dbg("mem length = %8.8x\n", mem_node->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 p_byte += 4;
541
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800542 if (p_byte > ((u8 *)p_EV_header + evbuffer_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 kfree(mem_node);
544 return 2;
545 }
546
547 mem_node->next = ctrl->mem_head;
548 ctrl->mem_head = mem_node;
549 }
550
551 while (numpmem--) {
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800552 p_mem_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 if (!p_mem_node)
555 break;
556
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800557 p_mem_node->base = *(u32 *)p_byte;
558 dbg("pre-mem base = %8.8x\n", p_mem_node->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 p_byte += 4;
560
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800561 if (p_byte > ((u8 *)p_EV_header + evbuffer_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 kfree(p_mem_node);
563 return 2;
564 }
565
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800566 p_mem_node->length = *(u32 *)p_byte;
567 dbg("pre-mem length = %8.8x\n", p_mem_node->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 p_byte += 4;
569
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800570 if (p_byte > ((u8 *)p_EV_header + evbuffer_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 kfree(p_mem_node);
572 return 2;
573 }
574
575 p_mem_node->next = ctrl->p_mem_head;
576 ctrl->p_mem_head = p_mem_node;
577 }
578
579 while (numio--) {
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800580 io_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582 if (!io_node)
583 break;
584
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800585 io_node->base = *(u32 *)p_byte;
586 dbg("io base = %8.8x\n", io_node->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 p_byte += 4;
588
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800589 if (p_byte > ((u8 *)p_EV_header + evbuffer_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 kfree(io_node);
591 return 2;
592 }
593
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800594 io_node->length = *(u32 *)p_byte;
595 dbg("io length = %8.8x\n", io_node->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 p_byte += 4;
597
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800598 if (p_byte > ((u8 *)p_EV_header + evbuffer_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 kfree(io_node);
600 return 2;
601 }
602
603 io_node->next = ctrl->io_head;
604 ctrl->io_head = io_node;
605 }
606
607 while (numbus--) {
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800608 bus_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 if (!bus_node)
611 break;
612
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800613 bus_node->base = *(u32 *)p_byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 p_byte += 4;
615
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800616 if (p_byte > ((u8 *)p_EV_header + evbuffer_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 kfree(bus_node);
618 return 2;
619 }
620
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800621 bus_node->length = *(u32 *)p_byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 p_byte += 4;
623
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800624 if (p_byte > ((u8 *)p_EV_header + evbuffer_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 kfree(bus_node);
626 return 2;
627 }
628
629 bus_node->next = ctrl->bus_head;
630 ctrl->bus_head = bus_node;
631 }
632
Alex Chiang427438c2009-03-31 09:23:16 -0600633 /* If all of the following fail, we don't have any resources for
634 * hot plug add
635 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 rc = 1;
637 rc &= cpqhp_resource_sort_and_combine(&(ctrl->mem_head));
638 rc &= cpqhp_resource_sort_and_combine(&(ctrl->p_mem_head));
639 rc &= cpqhp_resource_sort_and_combine(&(ctrl->io_head));
640 rc &= cpqhp_resource_sort_and_combine(&(ctrl->bus_head));
641
642 if (rc)
643 return(rc);
644 } else {
Alex Chiang861fefb2009-03-31 09:23:11 -0600645 if ((evbuffer[0] != 0) && (!ctrl->push_flag))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 return 1;
647 }
648
649 return 0;
650}
651
Alex Chiang861fefb2009-03-31 09:23:11 -0600652
Bogicevic Sasaff3ce482015-12-27 13:21:11 -0800653int compaq_nvram_store(void __iomem *rom_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654{
655 int rc = 1;
656
657 if (rom_start == NULL)
658 return -ENODEV;
659
660 if (evbuffer_init) {
661 rc = store_HRT(rom_start);
Quentin Lambert656f9782014-09-07 20:02:47 +0200662 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 err(msg_unable_to_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 }
665 return rc;
666}
667