int BCMATTACHFN(nvram_init)(void *si) { bool isemb; int ret; si_t *sih; static int nvram_status = -1; #ifdef __ECOS if (!kernel_initial) return 0; #endif /* Check for previous 'restore defaults' condition */ if (nvram_status == 1) return 1; /* Check whether nvram already initilized */ if (nvram_status == 0 && !nvram_do_reset) return 0; sih = (si_t *)si; /* Restore defaults from embedded NVRAM if button held down */ if (nvram_do_reset) { /* Initialize with embedded NVRAM */ nvram_header = find_nvram(TRUE, &isemb); ret = _nvram_init(si); if (ret == 0) { nvram_status = 1; return 1; } nvram_status = -1; _nvram_exit(); } /* Find NVRAM */ nvram_header = find_nvram(FALSE, &isemb); ret = _nvram_init(si); if (ret == 0) { /* Restore defaults if embedded NVRAM used */ if (nvram_header && isemb) { ret = 1; } } nvram_status = ret; return ret; }
int BCMINITFN(devinfo_nvram_init)(void *si) { int ret; si_t *sih = (si_t *)si; nvram_header = find_devinfo_nvram(sih); _nvram_hash_select(1); ret = _nvram_init(si, 1); _nvram_hash_select(0); return (ret); }
int nvram_init(void *si) { bool isemb; int ret; si_t *sih; static int nvram_status = -1; /* Check for previous 'restore defaults' condition */ if (nvram_status == 1) return 1; sih = (si_t *)si; /* Initialize private semaphore */ if ((nvram_lock = semBCreate(SEM_Q_FIFO, SEM_FULL)) == NULL) { printf("nvram_init: semBCreate failed\n"); return ERROR; } /* Find NVRAM */ nvram_header = find_nvram(FALSE, &isemb); if (!nvram_header) { #if defined(BUILD_VXBOOT) nvram_header = NV_RAM_ADRS; #else return ERROR; #endif } ret = _nvram_init(si); if (ret == 0) { /* Restore defaults if embedded NVRAM used */ if (nvram_header && isemb) { ret = 1; } } nvram_status = ret; return ret; }
static int __init dev_nvram_init(void) { int ret; /* Initialize hash table lock */ spin_lock_init(&nvram_lock); nvram_values = kzalloc(NVRAM_VALUES_SPACE, GFP_ATOMIC); if (!nvram_values) return -ENOMEM; /* Initialize hash table */ _nvram_init(); /* Register char device */ ret = register_chrdev(NVRAM_MAJOR, MTD_NVRAM_NAME, &dev_nvram_fops); if (ret < 0) { printk(KERN_ERR "NVRAM: unable to register character device\n"); goto err; } nvram_major = NVRAM_MAJOR; g_pdentry = create_proc_read_entry(MTD_NVRAM_NAME, 0444, NULL, nvram_proc_version_read, NULL); if (!g_pdentry) { ret = -ENOMEM; goto err; } printk("ASUS NVRAM: initialized. Available NVRAM space: %d\n", NVRAM_SPACE); return 0; err: dev_nvram_exit(); return ret; }
int nvram_init(void *sbh) { #ifdef ASUS #else ulong offsets[] = { FLASH_BASE + 4 MB - NVRAM_SPACE, FLASH_BASE + 3 MB - NVRAM_SPACE, FLASH_BASE + 2 MB - NVRAM_SPACE, FLASH_BASE + 1 MB - NVRAM_SPACE, FLASH_BASE + 4 KB, FLASH_BASE + 1 KB, #ifdef _CFE_ (ulong) embedded_nvram, #endif }; int i, ret; #ifdef vxworks /* Initialize private semaphore */ if ((nvram_lock = semBCreate(SEM_Q_FIFO, SEM_FULL)) == NULL) { printf("nvram_init: semBCreate failed\n"); return ERROR; } #endif if (sbh) { for (i = 4; i < ARRAYSIZE(offsets); i++) { nvram_header = (struct nvram_header *) offsets[i]; if (nvram_header->magic == NVRAM_MAGIC) break; nvram_header = NULL; } /* Temporarily initialize with embedded NVRAM */ ret = _nvram_init(); if (ret == 0) { /* Restore defaults if button held down */ if (nvram_reset(sbh)) return 1; _nvram_exit(); } } /* Find NVRAM */ for (i = 0; i < ARRAYSIZE(offsets); i++) { nvram_header = (struct nvram_header *) offsets[i]; if (nvram_header->magic == NVRAM_MAGIC) break; nvram_header = NULL; } ret = _nvram_init(); if (ret == 0) { /* Restore defaults if embedded NVRAM used */ if (nvram_header && i >= 4) ret = 1; } return ret; #endif }
static int dev_nvram_init(void) { int order = 0, ret = 0; struct page *page, *end; unsigned int i; osl_t *osh; /* Allocate and reserve memory to mmap() */ while ((PAGE_SIZE << order) < nvram_space) order++; end = virt_to_page(nvram_buf + (PAGE_SIZE << order) - 1); for (page = virt_to_page(nvram_buf); page <= end; page++) { SetPageReserved(page); } #if defined(CONFIG_MTD) || defined(CONFIG_MTD_MODULE) /* Find associated MTD device */ for (i = 0; i < MAX_MTD_DEVICES; i++) { nvram_mtd = get_mtd_device(NULL, i); if (!IS_ERR(nvram_mtd)) { if (!strcmp(nvram_mtd->name, "nvram") && nvram_mtd->size >= nvram_space) { break; } put_mtd_device(nvram_mtd); } } if (i >= MAX_MTD_DEVICES) nvram_mtd = NULL; #endif /* Initialize hash table lock */ spin_lock_init(&nvram_lock); /* Initialize commit semaphore */ init_MUTEX(&nvram_sem); /* Register char device */ if ((nvram_major = register_chrdev(0, "nvram", &dev_nvram_fops)) < 0) { ret = nvram_major; goto err; } if (si_osh(sih) == NULL) { osh = osl_attach(NULL, SI_BUS, FALSE); if (osh == NULL) { printk("Error allocating osh\n"); unregister_chrdev(nvram_major, "nvram"); goto err; } si_setosh(sih, osh); } printk("dev_nvram_init: _nvram_init\n"); /* Initialize hash table */ _nvram_init((void *)sih); /* Create /dev/nvram handle */ nvram_class = class_create(THIS_MODULE, "nvram"); if (IS_ERR(nvram_class)) { printk("Error creating nvram class\n"); goto err; } /* Add the device nvram0 */ class_device_create(nvram_class, NULL, MKDEV(nvram_major, 0), NULL, "nvram"); /* reserve commit read buffer */ /* Backup sector blocks to be erased */ if (!(nvram_commit_buf = kmalloc(ROUNDUP(nvram_space, nvram_mtd->erasesize), GFP_KERNEL))) { printk("dev_nvram_init: nvram_commit_buf out of memory\n"); goto err; } /* Set the SDRAM NCDL value into NVRAM if not already done */ if (getintvar(NULL, "sdram_ncdl") == 0) { unsigned int ncdl; char buf[] = "0x00000000"; if ((ncdl = si_memc_get_ncdl(sih))) { sprintf(buf, "0x%08x", ncdl); nvram_set("sdram_ncdl", buf); nvram_commit(); } } return 0; err: dev_nvram_exit(); return ret; }
static int dev_nvram_init(void) { int order = 0, ret = 0; struct page *page, *end; unsigned int i; osl_t *osh; /* Allocate and reserve memory to mmap() */ while ((PAGE_SIZE << order) < NVRAM_SPACE) order++; end = virt_to_page(nvram_buf + (PAGE_SIZE << order) - 1); for (page = virt_to_page(nvram_buf); page <= end; page++) { SetPageReserved(page); } #if defined(CONFIG_MTD) || defined(CONFIG_MTD_MODULE) /* Find associated MTD device */ for (i = 0; i < MAX_MTD_DEVICES; i++) { nvram_mtd = get_mtd_device(NULL, i); if (!IS_ERR(nvram_mtd)) { if (!strcmp(nvram_mtd->name, "nvram") && nvram_mtd->size >= NVRAM_SPACE) { break; } put_mtd_device(nvram_mtd); } } if (i >= MAX_MTD_DEVICES) nvram_mtd = NULL; #endif #ifdef RTN66U_NVRAM_64K_SUPPORT int ret32; char *log_buf; u_int32_t offset_t; size_t log_len; DECLARE_WAITQUEUE(wait, current); wait_queue_head_t wait_q; struct erase_info erase; offset_t = 0x18000; ret32 = nvram_mtd->read(nvram_mtd, offset_t, 4, &log_len, &log_buf); if(log_buf==0xffffffff) { /* Erase sector blocks */ init_waitqueue_head(&wait_q); erase.mtd = nvram_mtd; erase.addr = 0; erase.len = nvram_mtd->erasesize; erase.callback = erase_callback; erase.priv = (u_long) &wait_q; set_current_state(TASK_INTERRUPTIBLE); add_wait_queue(&wait_q, &wait); /* Unlock sector blocks */ if (nvram_mtd->unlock) nvram_mtd->unlock(nvram_mtd, 0, nvram_mtd->erasesize); if ((ret = nvram_mtd->erase(nvram_mtd, &erase))) { set_current_state(TASK_RUNNING); remove_wait_queue(&wait_q, &wait); printk("nvram mtd erase error\n"); } /* Wait for erase to finish */ schedule(); remove_wait_queue(&wait_q, &wait); } #endif /* Initialize hash table lock */ spin_lock_init(&nvram_lock); /* Initialize commit semaphore */ init_MUTEX(&nvram_sem); /* Register char device */ if ((nvram_major = register_chrdev(0, "nvram", &dev_nvram_fops)) < 0) { ret = nvram_major; goto err; } if (si_osh(sih) == NULL) { osh = osl_attach(NULL, SI_BUS, FALSE); if (osh == NULL) { printk("Error allocating osh\n"); unregister_chrdev(nvram_major, "nvram"); goto err; } si_setosh(sih, osh); } /* Initialize hash table */ _nvram_init(sih); /* Create /dev/nvram handle */ nvram_class = class_create(THIS_MODULE, "nvram"); if (IS_ERR(nvram_class)) { printk("Error creating nvram class\n"); goto err; } /* Add the device nvram0 */ class_device_create(nvram_class, NULL, MKDEV(nvram_major, 0), NULL, "nvram"); /* reserve commit read buffer */ /* Backup sector blocks to be erased */ if (!(nvram_commit_buf = kmalloc(ROUNDUP(NVRAM_SPACE, nvram_mtd->erasesize), GFP_KERNEL))) { printk("dev_nvram_init: nvram_commit_buf out of memory\n"); goto err; } /* Set the SDRAM NCDL value into NVRAM if not already done */ if (getintvar(NULL, "sdram_ncdl") == 0) { unsigned int ncdl; char buf[] = "0x00000000"; if ((ncdl = si_memc_get_ncdl(sih))) { sprintf(buf, "0x%08x", ncdl); nvram_set("sdram_ncdl", buf); nvram_commit(); } } return 0; err: dev_nvram_exit(); return ret; }
static int __init dev_nvram_init(void) { int order = 0, ret = 0; struct page *page, *end; unsigned int i; /* Allocate and reserve memory to mmap() */ while ((PAGE_SIZE << order) < NVRAM_SPACE) order++; end = virt_to_page(nvram_buf + (PAGE_SIZE << order) - 1); for (page = virt_to_page(nvram_buf); page <= end; page++) mem_map_reserve(page); #ifdef CONFIG_MTD /* Find associated MTD device */ for (i = 0; i < MAX_MTD_DEVICES; i++) { nvram_mtd = get_mtd_device(NULL, i); if (nvram_mtd) { if (!strcmp(nvram_mtd->name, "nvram") && nvram_mtd->size >= NVRAM_SPACE) break; put_mtd_device(nvram_mtd); } } if (i >= MAX_MTD_DEVICES) nvram_mtd = NULL; #endif /* Initialize hash table lock */ spin_lock_init(&nvram_lock); /* Initialize commit semaphore */ init_MUTEX(&nvram_sem); /* Register char device */ if ((nvram_major = devfs_register_chrdev(0, "nvram", &dev_nvram_fops)) < 0) { ret = nvram_major; goto err; } /* Initialize hash table */ _nvram_init(sbh); /* Create /dev/nvram handle */ nvram_handle = devfs_register(NULL, "nvram", DEVFS_FL_NONE, nvram_major, 0, S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP, &dev_nvram_fops, NULL); /* Set the SDRAM NCDL value into NVRAM if not already done */ if (getintvar(NULL, "sdram_ncdl") == 0) { unsigned int ncdl; char buf[] = "0x00000000"; if ((ncdl = sb_memc_get_ncdl(sbh))) { sprintf(buf, "0x%08x", ncdl); nvram_set("sdram_ncdl", buf); nvram_commit(); } } return 0; err: dev_nvram_exit(); return ret; }
static int dev_nvram_init(void) { int order = 0, ret = 0; struct page *page, *end; osl_t *osh; #if defined(CONFIG_MTD) || defined(CONFIG_MTD_MODULE) unsigned int i; #endif /* Allocate and reserve memory to mmap() */ while ((PAGE_SIZE << order) < nvram_space) order++; end = virt_to_page(nvram_buf + (PAGE_SIZE << order) - 1); for (page = virt_to_page(nvram_buf); page <= end; page++) { SetPageReserved(page); } #if defined(CONFIG_MTD) || defined(CONFIG_MTD_MODULE) /* Find associated MTD device */ for (i = 0; i < MAX_MTD_DEVICES; i++) { nvram_mtd = get_mtd_device(NULL, i); if (!IS_ERR(nvram_mtd)) { if (!strcmp(nvram_mtd->name, "nvram") && nvram_mtd->size >= nvram_space) { break; } put_mtd_device(nvram_mtd); } } if (i >= MAX_MTD_DEVICES) nvram_mtd = NULL; #endif /* Initialize hash table lock */ spin_lock_init(&nvram_lock); /* Initialize commit semaphore */ init_MUTEX(&nvram_sem); /* Register char device */ if ((nvram_major = register_chrdev(0, "nvram", &dev_nvram_fops)) < 0) { ret = nvram_major; goto err; } if (si_osh(sih) == NULL) { osh = osl_attach(NULL, SI_BUS, FALSE); if (osh == NULL) { printk("Error allocating osh\n"); unregister_chrdev(nvram_major, "nvram"); goto err; } si_setosh(sih, osh); } /* Initialize hash table */ _nvram_init(sih); /* Create /dev/nvram handle */ nvram_class = class_create(THIS_MODULE, "nvram"); if (IS_ERR(nvram_class)) { printk("Error creating nvram class\n"); goto err; } /* Add the device nvram0 */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) class_device_create(nvram_class, NULL, MKDEV(nvram_major, 0), NULL, "nvram"); #else /* Linux 2.6.36 and above */ device_create(nvram_class, NULL, MKDEV(nvram_major, 0), NULL, "nvram"); #endif /* Linux 2.6.36 */ return 0; err: dev_nvram_exit(); return ret; }