nvram.c (d5bbb5021ce8d9ff561c7469f5b4589ccb3bc4a6) | nvram.c (2d58636e0af724f38acad25246c1625efec36122) |
---|---|
1/* 2 * CMOS/NV-RAM driver for Linux 3 * 4 * Copyright (C) 1997 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> 5 * idea by and with help from Richard Jelinek <rj@suse.de> 6 * Portions copyright (c) 2001,2002 Sun Microsystems (thockin@sun.com) 7 * 8 * This driver allows you to access the contents of the non-volatile memory in --- 122 unchanged lines hidden (view full) --- 131 unsigned short sum = 0; 132 133 for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++i) 134 sum += __nvram_read_byte(i); 135 __nvram_write_byte(sum >> 8, PC_CKS_LOC); 136 __nvram_write_byte(sum & 0xff, PC_CKS_LOC + 1); 137} 138 | 1/* 2 * CMOS/NV-RAM driver for Linux 3 * 4 * Copyright (C) 1997 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> 5 * idea by and with help from Richard Jelinek <rj@suse.de> 6 * Portions copyright (c) 2001,2002 Sun Microsystems (thockin@sun.com) 7 * 8 * This driver allows you to access the contents of the non-volatile memory in --- 122 unchanged lines hidden (view full) --- 131 unsigned short sum = 0; 132 133 for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++i) 134 sum += __nvram_read_byte(i); 135 __nvram_write_byte(sum >> 8, PC_CKS_LOC); 136 __nvram_write_byte(sum & 0xff, PC_CKS_LOC + 1); 137} 138 |
139#if 0 140void nvram_set_checksum(void) | 139static long pc_nvram_set_checksum(void) |
141{ | 140{ |
142 unsigned long flags; | 141 spin_lock_irq(&rtc_lock); 142 __nvram_set_checksum(); 143 spin_unlock_irq(&rtc_lock); 144 return 0; 145} |
143 | 146 |
144 spin_lock_irqsave(&rtc_lock, flags); | 147static long pc_nvram_initialize(void) 148{ 149 ssize_t i; 150 151 spin_lock_irq(&rtc_lock); 152 for (i = 0; i < NVRAM_BYTES; ++i) 153 __nvram_write_byte(0, i); |
145 __nvram_set_checksum(); | 154 __nvram_set_checksum(); |
146 spin_unlock_irqrestore(&rtc_lock, flags); | 155 spin_unlock_irq(&rtc_lock); 156 return 0; |
147} | 157} |
148#endif /* 0 */ | |
149 150static ssize_t pc_nvram_get_size(void) 151{ 152 return NVRAM_BYTES; 153} 154 155const struct nvram_ops arch_nvram_ops = { 156 .read_byte = pc_nvram_read_byte, 157 .write_byte = pc_nvram_write_byte, 158 .get_size = pc_nvram_get_size, | 158 159static ssize_t pc_nvram_get_size(void) 160{ 161 return NVRAM_BYTES; 162} 163 164const struct nvram_ops arch_nvram_ops = { 165 .read_byte = pc_nvram_read_byte, 166 .write_byte = pc_nvram_write_byte, 167 .get_size = pc_nvram_get_size, |
168 .set_checksum = pc_nvram_set_checksum, 169 .initialize = pc_nvram_initialize, |
|
159}; 160EXPORT_SYMBOL(arch_nvram_ops); 161#endif /* CONFIG_X86 */ 162 163/* 164 * The are the file operation function for user access to /dev/nvram 165 */ 166 --- 69 unchanged lines hidden (view full) --- 236checksum_err: 237 spin_unlock_irq(&rtc_lock); 238 return -EIO; 239} 240 241static long nvram_misc_ioctl(struct file *file, unsigned int cmd, 242 unsigned long arg) 243{ | 170}; 171EXPORT_SYMBOL(arch_nvram_ops); 172#endif /* CONFIG_X86 */ 173 174/* 175 * The are the file operation function for user access to /dev/nvram 176 */ 177 --- 69 unchanged lines hidden (view full) --- 247checksum_err: 248 spin_unlock_irq(&rtc_lock); 249 return -EIO; 250} 251 252static long nvram_misc_ioctl(struct file *file, unsigned int cmd, 253 unsigned long arg) 254{ |
244 int i; | 255 long ret = -ENOTTY; |
245 246 switch (cmd) { | 256 257 switch (cmd) { |
247 | |
248 case NVRAM_INIT: 249 /* initialize NVRAM contents and checksum */ 250 if (!capable(CAP_SYS_ADMIN)) 251 return -EACCES; 252 | 258 case NVRAM_INIT: 259 /* initialize NVRAM contents and checksum */ 260 if (!capable(CAP_SYS_ADMIN)) 261 return -EACCES; 262 |
253 mutex_lock(&nvram_mutex); 254 spin_lock_irq(&rtc_lock); 255 256 for (i = 0; i < NVRAM_BYTES; ++i) 257 __nvram_write_byte(0, i); 258 __nvram_set_checksum(); 259 260 spin_unlock_irq(&rtc_lock); 261 mutex_unlock(&nvram_mutex); 262 return 0; 263 | 263 if (arch_nvram_ops.initialize != NULL) { 264 mutex_lock(&nvram_mutex); 265 ret = arch_nvram_ops.initialize(); 266 mutex_unlock(&nvram_mutex); 267 } 268 break; |
264 case NVRAM_SETCKS: 265 /* just set checksum, contents unchanged (maybe useful after 266 * checksum garbaged somehow...) */ 267 if (!capable(CAP_SYS_ADMIN)) 268 return -EACCES; 269 | 269 case NVRAM_SETCKS: 270 /* just set checksum, contents unchanged (maybe useful after 271 * checksum garbaged somehow...) */ 272 if (!capable(CAP_SYS_ADMIN)) 273 return -EACCES; 274 |
270 mutex_lock(&nvram_mutex); 271 spin_lock_irq(&rtc_lock); 272 __nvram_set_checksum(); 273 spin_unlock_irq(&rtc_lock); 274 mutex_unlock(&nvram_mutex); 275 return 0; 276 277 default: 278 return -ENOTTY; | 275 if (arch_nvram_ops.set_checksum != NULL) { 276 mutex_lock(&nvram_mutex); 277 ret = arch_nvram_ops.set_checksum(); 278 mutex_unlock(&nvram_mutex); 279 } 280 break; |
279 } | 281 } |
282 return ret; |
|
280} 281 282static int nvram_misc_open(struct inode *inode, struct file *file) 283{ 284 spin_lock(&nvram_state_lock); 285 | 283} 284 285static int nvram_misc_open(struct inode *inode, struct file *file) 286{ 287 spin_lock(&nvram_state_lock); 288 |
289 /* Prevent multiple readers/writers if desired. */ |
|
286 if ((nvram_open_cnt && (file->f_flags & O_EXCL)) || | 290 if ((nvram_open_cnt && (file->f_flags & O_EXCL)) || |
287 (nvram_open_mode & NVRAM_EXCL) || 288 ((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) { | 291 (nvram_open_mode & NVRAM_EXCL)) { |
289 spin_unlock(&nvram_state_lock); 290 return -EBUSY; 291 } 292 | 292 spin_unlock(&nvram_state_lock); 293 return -EBUSY; 294 } 295 |
296 /* Prevent multiple writers if the set_checksum ioctl is implemented. */ 297 if ((arch_nvram_ops.set_checksum != NULL) && 298 (file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE)) { 299 spin_unlock(&nvram_state_lock); 300 return -EBUSY; 301 } 302 |
|
293 if (file->f_flags & O_EXCL) 294 nvram_open_mode |= NVRAM_EXCL; 295 if (file->f_mode & FMODE_WRITE) 296 nvram_open_mode |= NVRAM_WRITE; 297 nvram_open_cnt++; 298 299 spin_unlock(&nvram_state_lock); 300 --- 167 unchanged lines hidden --- | 303 if (file->f_flags & O_EXCL) 304 nvram_open_mode |= NVRAM_EXCL; 305 if (file->f_mode & FMODE_WRITE) 306 nvram_open_mode |= NVRAM_WRITE; 307 nvram_open_cnt++; 308 309 spin_unlock(&nvram_state_lock); 310 --- 167 unchanged lines hidden --- |