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
|
/*
* OpenBIOS - free your system!
* ( firmware/flash device driver for Linux )
*
* bios_core.c - core skeleton
*
* This program is part of a free implementation of the IEEE 1275-1994
* Standard for Boot (Initialization Configuration) Firmware.
*
* Copyright (C) 1998-2004 Stefan Reinauer, <stepan@openbios.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*
*/
#include <linux/config.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
#ifdef MODULE
#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif
#endif
#include <linux/module.h>
#endif
#include <linux/pci.h>
#include <linux/errno.h>
#include <linux/vmalloc.h>
#include <linux/init.h>
#include <asm/io.h>
#include "bios.h"
#include "pcisets.h"
#include "flashchips.h"
#include "programming.h"
extern struct file_operations bios_fops;
int bios_proc_register(void);
int bios_proc_unregister(void);
int write = 0;
spinlock_t bios_lock = SPIN_LOCK_UNLOCKED;
/*
* ******************************************
*
* Cleanup
*
* ******************************************
*/
static void free_iomaps(void)
{
unsigned long lastmapped=0;
unsigned int i;
/* We remember the last mapped area to be sure that we only iounmap
* every mapped area once. If two flash devices are in the same
* area but do not occur sequentially during probing you have a
* seriously strange hardware
*/
for (i=0; i<flashcount; i++) {
if (lastmapped==flashdevices[i].mapped)
continue;
iounmap((void *)flashdevices[i].mapped);
lastmapped=flashdevices[i].mapped;
}
}
/*
* ******************************************
*
* Initialization
*
* ******************************************
*/
void probe_system(void)
{
#ifdef __alpha__
probe_alphafw();
#endif
/* This function checks all flash media attached to
* PCI devices in the system. This means NON-PCI systems
* don't work. This causes machine checks on my LX164 test
* machine, so leave it away until it's fixed. This is
* needed for Ruffians, so we check the machine type
* in probe_alphafw() and call probe_pcibus from there.
* This could use some cleanup
*/
#ifndef __alpha__
probe_pcibus();
#endif
}
static __init int bios_init(void)
{
printk(KERN_INFO "BIOS driver v" BIOS_VERSION " (writing %s) for "
UTS_RELEASE "\n", write?"enabled":"disabled");
#if !defined(UTC_BIOS) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
if (!pci_present()) {
printk(KERN_WARNING "BIOS: No PCI system.");
return -EBUSY;
}
#endif
/* Probe for flash devices */
probe_system();
if (flashcount==0) {
printk(KERN_WARNING "BIOS: No flash devices found.\n");
return -EBUSY;
}
if (register_chrdev(BIOS_MAJOR, "bios", &bios_fops) == -EBUSY) {
printk(KERN_WARNING "BIOS: Could not register bios device.\n");
free_iomaps();
return -EBUSY;
}
#ifdef CONFIG_PROC_FS
bios_proc_register();
#endif
return 0;
}
/*
* ******************************************
*
* module handling
*
* ******************************************
*/
#ifdef MODULE
MODULE_PARM(write,"i");
MODULE_AUTHOR("Stefan Reinauer <stepan@openbios.org>");
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,10)
MODULE_LICENSE("GPL");
#endif
static __exit void cleanup_bios_module (void)
{
#ifdef CONFIG_PROC_FS
bios_proc_unregister();
#endif
free_iomaps();
unregister_chrdev(BIOS_MAJOR, "bios");
printk(KERN_INFO "BIOS driver removed.\n");
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
int init_module(void)
{
return bios_init();
}
void cleanup_module(void)
{
cleanup_bios_module();
}
#endif
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,74)
module_init(bios_init);
module_exit(cleanup_bios_module);
#endif
void inc_mod(void)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
MOD_INC_USE_COUNT;
#endif
}
void dec_mod(void)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
MOD_DEC_USE_COUNT;
#endif
}
#endif
|