aboutsummaryrefslogtreecommitdiff
path: root/other-licence/common/module_entry.c
blob: 423d90843a5b2e8220d53ae3d4ea69d9af19f84b (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
/******************************************************************************
 * Copyright (c) 2004, 2008 IBM Corporation
 * All rights reserved.
 * This program and the accompanying materials
 * are made available under the terms of the BSD License
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * Contributors:
 *     IBM Corporation - initial implementation
 *****************************************************************************/

#include "netdriver_int.h"

extern snk_module_t snk_module_interface;

snk_kernel_t *snk_kernel_interface = 0;

extern int
check_driver( pci_config_t *pci_conf );


static void*
memset( void *dest, int c, size_t n )
{
	while( n-- ) {
		*( char * ) dest++ = ( char ) c;
	}
	return dest;
}


extern char __bss_start;
extern char __bss_size;

snk_module_t*
module_init(snk_kernel_t *snk_kernel_int, pci_config_t *pciconf)
{
	/* Need to clear bss, heavy linker script dependency, expert change only */
	char              *bss      = &__bss_start;
	unsigned long long bss_size = (unsigned long long) &__bss_size;

	if (((unsigned long long) bss) + bss_size >= 0xFF00000 
	 || bss_size >= 0x2000000) {
		snk_kernel_int->print("BSS size (%llu bytes) is too big!\n", bss_size);
		return 0;
	}

	memset(bss, 0, bss_size);

	if (snk_kernel_int->version != snk_module_interface.version) {
		return 0;
	}

	snk_kernel_interface = snk_kernel_int;

	/* Check if this is the right driver */
	if (check_driver(pciconf) < 0) {
		return 0;
	}

	snk_module_interface.link_addr = module_init;
	return &snk_module_interface;
}