char *vt_init(vt_info_t *vi_p) { int r; struct mem_range mr; /* Allow memory mapping */ mr.mr_base = (phys_bytes)(vi_p->vram_base); mr.mr_limit = mr.mr_base + vi_p->vram_size; if( OK != (r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr))) panic("video_txt: sys_privctl (ADD_MEM) failed: %d\n", r); /* Map memory */ video_mem = vm_map_phys(SELF, (void *)mr.mr_base, vi_p->vram_size); if(video_mem == MAP_FAILED) panic("video_txt couldn't map video memory"); /* Save text mode resolution */ scr_lines = vi_p->scr_lines; scr_width = vi_p->scr_width; return video_mem; }
void *vg_init(unsigned short mode) { struct reg86u reg86; reg86.u.b.intno = VBE_INTERRUPT_VECTOR; /* BIOS video services */ reg86.u.b.ah = VBE_FUNCTION; reg86.u.b.al = VBE_SET_VBE_MODE; reg86.u.w.bx = mode | BIT(VBE_MODE_NUMBER_LINEAR_FLAT_FRAME_BUFFER_BIT); vbe_mode_info_t vbe_mode_info; if (sys_int86(®86) == OK) { if (reg86.u.w.ax == VBE_FUNCTION_SUPPORTED | VBE_FUNCTION_CALL_SUCCESSFUL) { if(vbe_get_mode_info(mode, &vbe_mode_info)) { return NULL; } else { int r; struct mem_range mr; unsigned mr_size; h_res = vbe_mode_info.XResolution; v_res = vbe_mode_info.YResolution; bits_per_pixel = vbe_mode_info.BitsPerPixel; /* Allow memory mapping */ mr.mr_base = vbe_mode_info.PhysBasePtr; mr_size = h_res * v_res * bits_per_pixel; mr.mr_limit = mr.mr_base + mr_size; if(sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr)) { return NULL; } /* Map memory */ video_mem = vm_map_phys(SELF, (void *)mr.mr_base, mr_size); if(video_mem != MAP_FAILED) { if ((double_buffer = malloc(h_res * v_res * bits_per_pixel / 8)) != NULL) { if ((mouse_buffer = malloc(h_res * v_res * bits_per_pixel / 8)) != NULL) { return video_mem; } } } } } } return NULL; }
/* don't know where ACPI tables are, we may need to access any memory */ PRIVATE int init_mem_priv(void) { struct mem_range mr; mr.mr_base = 0; mr.mr_limit = 0xffffffff; return sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr); }
void* vg_init(unsigned short mode) { struct mem_range mr; vbe_mode_info_t vmi_p; struct reg86u reg86; reg86.u.b.intno = BIOS_VIDEO; reg86.u.b.ah = VBE; reg86.u.b.al = SET_VBE; reg86.u.w.bx = BIT(LINEAR_BIT) | mode; if (sys_int86(®86)) { printf("vg_init()::bios call didn't return 0\n"); return NULL; } if (vbe_get_mode_info(mode, &vmi_p) == -1) { printf("vg_init()::failed in vbe_get_mode_info"); return NULL; } h_res = vmi_p.XResolution; v_res = vmi_p.YResolution; bits_per_pixel = vmi_p.BitsPerPixel; if (bits_per_pixel / 8 > 0) bytes_per_pixel = bits_per_pixel / 8; else bytes_per_pixel = 1; vram_size = h_res * v_res * bytes_per_pixel; int r; /* Allow memory mapping */ mr.mr_base = vmi_p.PhysBasePtr; mr.mr_limit = mr.mr_base + vram_size; if (sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr) != 0) { panic("video_txt: sys_privctl (ADD_MEM) failed: %d\n", r); return NULL; } /* Map memory */ video_mem = vm_map_phys(SELF, (void *) mr.mr_base, vram_size); buffer = malloc(vram_size); if (video_mem == MAP_FAILED) { panic("video_txt couldn't map video memory"); return NULL; } return video_mem; }
//maps buffer at base base, size size to proccess's virtual memory, void* map_virtual_memory(unsigned long base, unsigned long size, void** ptr) { int r; struct mem_range mr; mr.mr_base = (phys_bytes)(base); mr.mr_limit = mr.mr_base + size; if( OK != (r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr))) panic("video_txt: sys_privctl (ADD_MEM) failed: %d\n", r); *ptr = vm_map_phys(SELF, (void *)mr.mr_base, size); if(*ptr == MAP_FAILED) panic("video_gr couldn't map video memory"); return *ptr; }
void *vg_init(unsigned short mode) { vbe_mode_info_t config; if ( vbe_set_mode(VBE_MODE, mode) == 1) //set graphic mode return NULL; if (vbe_get_mode_info(mode, &config) != 0) //get vbe info { return NULL; } h_res = config.XResolution; //store X Resolution v_res = config.YResolution; //store Y Resolution bits_per_pixel = config.BitsPerPixel; //store Bits Per Pixel vram_size = (config.XResolution * config.YResolution * config.BitsPerPixel) / 8; //store the size of the vram int r; struct mem_range mr; /* Allow memory mapping */ mr.mr_base = (config.PhysBasePtr); mr.mr_limit = mr.mr_base + (config.XResolution * config.YResolution * config.BitsPerPixel) / 8; if( OK != (r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr))) panic("video_txt: sys_privctl (ADD_MEM) failed: %d\n", r); /* Map memory */ video_mem = vm_map_phys(SELF, (void *)mr.mr_base, (config.XResolution * config.YResolution * config.BitsPerPixel) / 8); if(video_mem == MAP_FAILED) panic("video_txt couldn't map video memory"); if (video_mem == NULL) { printf("vg_init: Error!\n"); vg_exit(); return NULL; } return config.PhysBasePtr; }
void * vg_init(unsigned long mode) { struct reg86u r; r.u.w.ax = 0x4F02; // VBE call, function 02 -- set VBE mode -- ah:0x4F invoking VBE function, al:0x02 function being called:set VBE mode r.u.w.bx = 1<<14|mode; // set bit 14: linear framebuffer r.u.b.intno = 0x10; if( sys_int86(&r) != OK ) { printf("set_vbe_mode: sys_int86() failed \n"); } /* vbe_mode_info_t info; if(vbe_get_mode_info(mode,&info)==1) printf("error in vbe_get_mode \n"); h_res=info.XResolution; v_res=info.YResolution; bits_per_pixel=info.BitsPerPixel; *video_mem=info.PhysBasePtr;*/ h_res=H_RES; v_res=V_RES; bits_per_pixel=BITS_PER_PIXEL; bytes_per_pixel=bits_per_pixel/8; int y; struct mem_range mr; /* Allow memory mapping */ mr.mr_base = VRAM_PHYS_ADDR; mr.mr_limit = mr.mr_base + h_res*v_res; if( OK != (y = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr))) panic("video_txt: sys_privctl (ADD_MEM) failed: %d\n", y); /* Map memory */ video_mem = vm_map_phys(SELF, (void *)mr.mr_base, h_res*v_res); if(video_mem == MAP_FAILED) panic("video_txt couldn't map video memory"); return NULL; }
/*===========================================================================* * sef_cb_init_fresh * *===========================================================================*/ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) { /* Initialize the reincarnation server. */ struct boot_image *ip; int s,i; int nr_image_srvs, nr_image_priv_srvs, nr_uncaught_init_srvs; struct rproc *rp; struct rproc *replica_rp; struct rprocpub *rpub; struct boot_image image[NR_BOOT_PROCS]; struct boot_image_priv *boot_image_priv; struct boot_image_sys *boot_image_sys; struct boot_image_dev *boot_image_dev; int pid, replica_pid; endpoint_t replica_endpoint; int ipc_to; int *calls; int all_c[] = { ALL_C, NULL_C }; int no_c[] = { NULL_C }; /* See if we run in verbose mode. */ env_parse("rs_verbose", "d", 0, &rs_verbose, 0, 1); if ((s = sys_getinfo(GET_HZ, &system_hz, sizeof(system_hz), 0, 0)) != OK) panic("Cannot get system timer frequency\n"); /* Initialize the global init descriptor. */ rinit.rproctab_gid = cpf_grant_direct(ANY, (vir_bytes) rprocpub, sizeof(rprocpub), CPF_READ); if(!GRANT_VALID(rinit.rproctab_gid)) { panic("unable to create rprocpub table grant: %d", rinit.rproctab_gid); } /* Initialize some global variables. */ rupdate.flags = 0; shutting_down = FALSE; /* Get a copy of the boot image table. */ if ((s = sys_getimage(image)) != OK) { panic("unable to get copy of boot image table: %d", s); } /* Determine the number of system services in the boot image table. */ nr_image_srvs = 0; for(i=0;i<NR_BOOT_PROCS;i++) { ip = &image[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(ip->endpoint))) { continue; } nr_image_srvs++; } /* Determine the number of entries in the boot image priv table and make sure * it matches the number of system services in the boot image table. */ nr_image_priv_srvs = 0; for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } nr_image_priv_srvs++; } if(nr_image_srvs != nr_image_priv_srvs) { panic("boot image table and boot image priv table mismatch"); } /* Reset the system process table. */ for (rp=BEG_RPROC_ADDR; rp<END_RPROC_ADDR; rp++) { rp->r_flags = 0; rp->r_pub = &rprocpub[rp - rproc]; rp->r_pub->in_use = FALSE; } /* Initialize the system process table in 4 steps, each of them following * the appearance of system services in the boot image priv table. * - Step 1: set priviliges, sys properties, and dev properties (if any) * for every system service. */ for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } /* Lookup the corresponding entries in other tables. */ boot_image_info_lookup(boot_image_priv->endpoint, image, &ip, NULL, &boot_image_sys, &boot_image_dev); rp = &rproc[boot_image_priv - boot_image_priv_table]; rpub = rp->r_pub; /* * Set privileges. */ /* Get label. */ strcpy(rpub->label, boot_image_priv->label); /* Force a static priv id for system services in the boot image. */ rp->r_priv.s_id = static_priv_id( _ENDPOINT_P(boot_image_priv->endpoint)); /* Initialize privilege bitmaps and signal manager. */ rp->r_priv.s_flags = boot_image_priv->flags; /* priv flags */ rp->r_priv.s_trap_mask= SRV_OR_USR(rp, SRV_T, USR_T); /* traps */ ipc_to = SRV_OR_USR(rp, SRV_M, USR_M); /* targets */ fill_send_mask(&rp->r_priv.s_ipc_to, ipc_to == ALL_M); rp->r_priv.s_sig_mgr= SRV_OR_USR(rp, SRV_SM, USR_SM); /* sig mgr */ rp->r_priv.s_bak_sig_mgr = NONE; /* backup sig mgr */ /* Initialize kernel call mask bitmap. */ calls = SRV_OR_USR(rp, SRV_KC, USR_KC) == ALL_C ? all_c : no_c; fill_call_mask(calls, NR_SYS_CALLS, rp->r_priv.s_k_call_mask, KERNEL_CALL, TRUE); /* Set the privilege structure. */ if(boot_image_priv->endpoint != RS_PROC_NR) { if ((s = sys_privctl(ip->endpoint, SYS_PRIV_SET_SYS, &(rp->r_priv))) != OK) { panic("unable to set privilege structure: %d", s); } } /* Synch the privilege structure with the kernel. */ if ((s = sys_getpriv(&(rp->r_priv), ip->endpoint)) != OK) { panic("unable to synch privilege structure: %d", s); } /* * Set sys properties. */ rpub->sys_flags = boot_image_sys->flags; /* sys flags */ /* * Set dev properties. */ rpub->dev_flags = boot_image_dev->flags; /* device flags */ rpub->dev_nr = boot_image_dev->dev_nr; /* major device number */ rpub->dev_style = boot_image_dev->dev_style; /* device style */ rpub->dev_style2 = boot_image_dev->dev_style2; /* device style 2 */ /* Get process name. */ strcpy(rpub->proc_name, ip->proc_name); /* Build command settings. */ rp->r_cmd[0]= '\0'; rp->r_script[0]= '\0'; build_cmd_dep(rp); /* Initialize vm call mask bitmap. */ calls = SRV_OR_USR(rp, SRV_VC, USR_VC) == ALL_C ? all_c : no_c; fill_call_mask(calls, NR_VM_CALLS, rpub->vm_call_mask, VM_RQ_BASE, TRUE); /* Scheduling parameters. */ rp->r_scheduler = SRV_OR_USR(rp, SRV_SCH, USR_SCH); rp->r_priority = SRV_OR_USR(rp, SRV_Q, USR_Q); rp->r_quantum = SRV_OR_USR(rp, SRV_QT, USR_QT); /* Get some settings from the boot image table. */ rpub->endpoint = ip->endpoint; /* Set some defaults. */ rp->r_old_rp = NULL; /* no old version yet */ rp->r_new_rp = NULL; /* no new version yet */ rp->r_prev_rp = NULL; /* no prev replica yet */ rp->r_next_rp = NULL; /* no next replica yet */ rp->r_uid = 0; /* root */ rp->r_check_tm = 0; /* not checked yet */ getuptime(&rp->r_alive_tm); /* currently alive */ rp->r_stop_tm = 0; /* not exiting yet */ rp->r_restarts = 0; /* no restarts so far */ rp->r_period = 0; /* no period yet */ rp->r_exec = NULL; /* no in-memory copy yet */ rp->r_exec_len = 0; /* Mark as in use and active. */ rp->r_flags = RS_IN_USE | RS_ACTIVE; rproc_ptr[_ENDPOINT_P(rpub->endpoint)]= rp; rpub->in_use = TRUE; } /* - Step 2: allow every system service in the boot image to run. */ nr_uncaught_init_srvs = 0; for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } /* Lookup the corresponding slot in the system process table. */ rp = &rproc[boot_image_priv - boot_image_priv_table]; rpub = rp->r_pub; /* RS is already running as we speak. */ if(boot_image_priv->endpoint == RS_PROC_NR) { if ((s = init_service(rp, SEF_INIT_FRESH)) != OK) { panic("unable to initialize RS: %d", s); } continue; } /* Allow the service to run. */ if ((s = sched_init_proc(rp)) != OK) { panic("unable to initialize scheduling: %d", s); } if ((s = sys_privctl(rpub->endpoint, SYS_PRIV_ALLOW, NULL)) != OK) { panic("unable to initialize privileges: %d", s); } /* Initialize service. We assume every service will always get * back to us here at boot time. */ if(boot_image_priv->flags & SYS_PROC) { if ((s = init_service(rp, SEF_INIT_FRESH)) != OK) { panic("unable to initialize service: %d", s); } if(rpub->sys_flags & SF_SYNCH_BOOT) { /* Catch init ready message now to synchronize. */ catch_boot_init_ready(rpub->endpoint); } else { /* Catch init ready message later. */ nr_uncaught_init_srvs++; } } } /* - Step 3: let every system service complete initialization by * catching all the init ready messages left. */ while(nr_uncaught_init_srvs) { catch_boot_init_ready(ANY); nr_uncaught_init_srvs--; } /* - Step 4: all the system services in the boot image are now running. * Complete the initialization of the system process table in collaboration * with other system services. */ for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } /* Lookup the corresponding slot in the system process table. */ rp = &rproc[boot_image_priv - boot_image_priv_table]; rpub = rp->r_pub; /* Get pid from PM. */ rp->r_pid = getnpid(rpub->endpoint); if(rp->r_pid == -1) { panic("unable to get pid"); } } /* Set alarm to periodically check service status. */ if (OK != (s=sys_setalarm(RS_DELTA_T, 0))) panic("couldn't set alarm: %d", s); /* Now create a new RS instance with a private page table and let the current * instance live update into the replica. Clone RS' own slot first. */ rp = rproc_ptr[_ENDPOINT_P(RS_PROC_NR)]; if((s = clone_slot(rp, &replica_rp)) != OK) { panic("unable to clone current RS instance: %d", s); } /* Fork a new RS instance. */ pid = srv_fork(); if(pid == -1) { panic("unable to fork a new RS instance"); } replica_pid = pid ? pid : getpid(); replica_endpoint = getnprocnr(replica_pid); replica_rp->r_pid = replica_pid; replica_rp->r_pub->endpoint = replica_endpoint; if(pid == 0) { /* New RS instance running. */ /* Live update the old instance into the new one. */ s = update_service(&rp, &replica_rp, RS_SWAP); if(s != OK) { panic("unable to live update RS: %d", s); } cpf_reload(); /* Clean up the old RS instance, the new instance will take over. */ cleanup_service(rp); /* Map out our own text and data. */ unmap_ok = 1; _minix_unmapzero(); /* Ask VM to pin memory for the new RS instance. */ if((s = vm_memctl(RS_PROC_NR, VM_RS_MEM_PIN)) != OK) { panic("unable to pin memory for the new RS instance: %d", s); } } else { /* Old RS instance running. */ /* Set up privileges for the new instance and let it run. */ s = sys_privctl(replica_endpoint, SYS_PRIV_SET_SYS, &(replica_rp->r_priv)); if(s != OK) { panic("unable to set privileges for the new RS instance: %d", s); } if ((s = sched_init_proc(replica_rp)) != OK) { panic("unable to initialize RS replica scheduling: %d", s); } s = sys_privctl(replica_endpoint, SYS_PRIV_YIELD, NULL); if(s != OK) { panic("unable to yield control to the new RS instance: %d", s); } NOT_REACHABLE; } return(OK); }
void * vg_init(unsigned long mode) { // ----------------------- // -Non-Hardcoded Version- // ----------------------- struct reg86u reg86; vbe_mode_info_t vmi; int r; struct mem_range mr; reg86.u.w.ax = 0x4F02; reg86.u.w.bx = 1<<14|mode; reg86.u.b.intno = 0x10; if(sys_int86(®86) != OK) { printf("set_vbe_mode: sys_int86() failed\n"); return NULL; } else { vbe_get_mode_info(mode, &vmi); h_res = vmi.XResolution; v_res = vmi.YResolution; bits_per_pixel = vmi.BitsPerPixel; mr.mr_base = vmi.PhysBasePtr; mr.mr_limit = mr.mr_base + (h_res * v_res * (bits_per_pixel / 8)); if((r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr)) != OK) { panic("vg_init: sys_privctl (ADD_MEM) failed: %d\n", r); return NULL; } else { video_mem = vm_map_phys(SELF, (void *)mr.mr_base, (h_res * v_res * (bits_per_pixel / 8))); if(video_mem == MAP_FAILED){ panic("vg_init: Couldn't map video memory!\n"); return NULL; } else return video_mem; } } // ------------------- // -Hardcoded Version- // ------------------- /* struct reg86u reg86; vbe_mode_info_t vmi; int r; struct mem_range mr; reg86.u.w.ax = 0x4F02; reg86.u.w.bx = 1<<14|mode; reg86.u.b.intno = 0x10; if(sys_int86(®86) != OK) { printf("set_vbe_mode: sys_int86() failed\n"); return NULL; } else { h_res = H_RES; v_res = V_RES; bits_per_pixel = BITS_PER_PIXEL; mr.mr_base = VRAM_PHYS_ADDR; mr.mr_limit = mr.mr_base + (h_res * v_res * (bits_per_pixel / 8)); if((r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr)) != OK) { panic("vg_init: sys_privctl (ADD_MEM) failed: %d\n", r); return NULL; } else { video_mem = vm_map_phys(SELF, (void *)mr.mr_base, (h_res * v_res * (bits_per_pixel / 8))); if(video_mem == MAP_FAILED){ panic("vg_init: Couldn't map video memory!\n"); return NULL; } else return video_mem; } }*/ }
/*============================================================================* * lan8710a_map_regs * *============================================================================*/ static void lan8710a_map_regs(void) { struct minix_mem_range mr; mr.mr_base = CM_PER_BASE_ADR; mr.mr_limit = CM_PER_BASE_ADR + MEMORY_LIMIT; if (sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr) != 0) { panic("Unable to request permission to map memory"); } lan8710a_state.regs_cp_per = (vir_bytes)vm_map_phys(SELF, (void *)CM_PER_BASE_ADR, 512); if ((void *)lan8710a_state.regs_cp_per == MAP_FAILED) { panic("lan8710a_state.regs_cp_per: vm_map_phys failed"); } lan8710a_state.regs_cpdma_stram = (vir_bytes)vm_map_phys(SELF, (void *)CPDMA_STRAM_BASE_ADR, 512); if ((void *)lan8710a_state.regs_cpdma_stram == MAP_FAILED) { panic("lan8710a_state.regs_cpdma_stram: vm_map_phys failed"); } lan8710a_state.regs_cpsw_cpdma = (vir_bytes)vm_map_phys(SELF, (void *)CPSW_CPDMA_BASE_ADR, 512); if ((void *)lan8710a_state.regs_cpsw_cpdma == MAP_FAILED) { panic("lan8710a_state.regs_cpsw_cpdma: vm_map_phys failed"); } lan8710a_state.regs_cpsw_ale = (vir_bytes)vm_map_phys(SELF, (void *)CPSW_ALE_BASE_ADR, 256); if ((void *)lan8710a_state.regs_cpsw_ale == MAP_FAILED) { panic("lan8710a_state.regs_cpsw_ale: vm_map_phys failed"); } lan8710a_state.regs_cpsw_sl = (vir_bytes)vm_map_phys(SELF, (void *)CPSW_SL_BASE_ADR, 512); if ((void *)lan8710a_state.regs_cpsw_sl == MAP_FAILED) { panic("lan8710a_state.regs_cpsw_sl: vm_map_phys failed"); } lan8710a_state.regs_cpsw_ss = (vir_bytes)vm_map_phys(SELF, (void *)CPSW_SS_BASE_ADR, 512); if ((void *)lan8710a_state.regs_cpsw_ss == MAP_FAILED) { panic("lan8710a_state.regs_cpsw_ss: vm_map_phys failed"); } lan8710a_state.regs_cpsw_wr = (vir_bytes)vm_map_phys(SELF, (void *)CPSW_WR_BASE_ADR, 512); if ((void *)lan8710a_state.regs_cpsw_wr == MAP_FAILED) { panic("lan8710a_state.regs_cpsw_wr: vm_map_phys failed"); } lan8710a_state.regs_ctrl_mod = (vir_bytes)vm_map_phys(SELF, (void *)CTRL_MOD_BASE_ADR, 2560); if ((void *)lan8710a_state.regs_ctrl_mod == MAP_FAILED) { panic("lan8710a_state.regs_ctrl_mod: vm_map_phys failed"); } lan8710a_state.regs_intc = (vir_bytes)vm_map_phys(SELF, (void *)INTC_BASE_ADR, 512); if ((void *)lan8710a_state.regs_intc == MAP_FAILED) { panic("lan8710a_state.regs_intc: vm_map_phys failed"); } lan8710a_state.regs_mdio = (vir_bytes)vm_map_phys(SELF, (void *)MDIO_BASE_ADDR, 512); if ((void *)lan8710a_state.regs_mdio == MAP_FAILED) { panic("lan8710a_state.regs_mdio: vm_map_phys failed"); } mr.mr_base = BEGINNING_DESC_MEM; mr.mr_limit = BEGINNING_DESC_MEM + DESC_MEMORY_LIMIT; if (sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr) != 0) { panic("Unable to request permission to map memory"); } lan8710a_state.rx_desc_phy = BEGINNING_RX_DESC_MEM; lan8710a_state.tx_desc_phy = BEGINNING_TX_DESC_MEM; lan8710a_state.rx_desc = (lan8710a_desc_t *)vm_map_phys(SELF, (void *)lan8710a_state.rx_desc_phy, 1024); if ((void *)lan8710a_state.rx_desc == MAP_FAILED) { panic("lan8710a_state.rx_desc: vm_map_phys failed"); } lan8710a_state.tx_desc = (lan8710a_desc_t *)vm_map_phys(SELF, (void *)lan8710a_state.tx_desc_phy, 1024); if ((void *)lan8710a_state.tx_desc == MAP_FAILED) { panic("lan8710a_state.tx_desc: vm_map_phys failed"); } mr.mr_base = CPSW_STATS_BASE_ADR; mr.mr_limit = CPSW_STATS_BASE_ADR + CPSW_STATS_MEM_LIMIT; if (sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr) != 0) { panic("Unable to request permission to map memory"); } lan8710a_state.regs_cpsw_stats = (vir_bytes)vm_map_phys(SELF, (void *)CPSW_STATS_BASE_ADR, 256); if ((void *)lan8710a_state.regs_cpsw_stats == MAP_FAILED) { panic("lan8710a_state.regs_cpsw_stats: vm_map_phys failed"); } }
void *vg_init(unsigned short mode) { vbe_mode_info_t info; struct reg86u reg86; int r; struct mem_range mr; reg86.u.b.intno = BIOS_VIDEO_INT; /* BIOS video services */ reg86.u.w.ax = SET_VBE_MODE; /* Set Video Mode function */ reg86.u.w.bx = SET_LINEAR_MODE | mode; /* Mode */ if (sys_int86(®86) != OK) { // Sets video mode printf("\tvg_init(): sys_int86() failed \n"); return NULL; } switch (reg86.u.w.ax) { case VBE_FUNC_CALL_FAILED: printf("\tvg_init(): sys_int86() function call failed.\n"); return NULL; break; case VBE_FUNC_NOT_SUPPORTED: printf("\tvg_init(): sys_int86() function not supported.\n"); return NULL; break; case VBE_FUNC_INVALID_CUR_MODE: printf( "\tvg_init(): sys_int86() function invalid in current video mode.\n"); return NULL; break; } if (lm_init() == NULL) { printf("\tvg_init(): lm_init() failed \n"); return NULL; } if (vbe_get_mode_info(mode, &info) != OK) { // Gets info printf("\tvg_init(): vbe_get_mode_info() failed \n"); return NULL; } h_res = info.XResolution; v_res = info.YResolution; //Sets global variables bits_per_pixel = info.BitsPerPixel; //Allow memory mapping mr.mr_base = (phys_bytes)(info.PhysBasePtr); mr.mr_limit = mr.mr_base + info.XResolution * info.YResolution * info.BitsPerPixel / 8; if (OK != (r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr))) panic("video_txt: sys_privctl (ADD_MEM) failed: %d\n", r); // Map memory video_mem = vm_map_phys(SELF, (void *) mr.mr_base, info.XResolution * info.YResolution * info.BitsPerPixel / 8); double_buffer = malloc(h_res * v_res * sizeof(char)); /*if(video_mem == MAP_FAILED) panic("video_txt couldn't map video memory");*/ return video_mem; }
/*===========================================================================* * sef_cb_init_fresh * *===========================================================================*/ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) { /* Initialize the reincarnation server. */ struct sigaction sa; struct boot_image *ip; int s,i,j; int nr_image_srvs, nr_image_priv_srvs, nr_uncaught_init_srvs; struct rproc *rp; struct rprocpub *rpub; struct boot_image image[NR_BOOT_PROCS]; struct mproc mproc[NR_PROCS]; struct exec header; struct boot_image_priv *boot_image_priv; struct boot_image_sys *boot_image_sys; struct boot_image_dev *boot_image_dev; /* See if we run in verbose mode. */ env_parse("rs_verbose", "d", 0, &rs_verbose, 0, 1); /* Initialize the global init descriptor. */ rinit.rproctab_gid = cpf_grant_direct(ANY, (vir_bytes) rprocpub, sizeof(rprocpub), CPF_READ); if(!GRANT_VALID(rinit.rproctab_gid)) { panic("RS", "unable to create rprocpub table grant", rinit.rproctab_gid); } /* Initialize the global update descriptor. */ rupdate.flags = 0; /* Get a copy of the boot image table. */ if ((s = sys_getimage(image)) != OK) { panic("RS", "unable to get copy of boot image table", s); } /* Determine the number of system services in the boot image table and * compute the size required for the boot image buffer. */ nr_image_srvs = 0; boot_image_buffer_size = 0; for(i=0;i<NR_BOOT_PROCS;i++) { ip = &image[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(ip->endpoint))) { continue; } nr_image_srvs++; /* Lookup the corresponding entry in the boot image sys table. */ boot_image_info_lookup(ip->endpoint, image, NULL, NULL, &boot_image_sys, NULL); /* If we must keep a copy of this system service, read the header * and increase the size of the boot image buffer. */ if(boot_image_sys->flags & SF_USE_COPY) { if((s = sys_getaoutheader(&header, i)) != OK) { panic("RS", "unable to get copy of a.out header", s); } boot_image_buffer_size += header.a_hdrlen + header.a_text + header.a_data; } } /* Determine the number of entries in the boot image priv table and make sure * it matches the number of system services in the boot image table. */ nr_image_priv_srvs = 0; for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } nr_image_priv_srvs++; } if(nr_image_srvs != nr_image_priv_srvs) { panic("RS", "boot image table and boot image priv table mismatch", NO_NUM); } /* Allocate boot image buffer. */ if(boot_image_buffer_size > 0) { boot_image_buffer = rs_startup_sbrk(boot_image_buffer_size); if(boot_image_buffer == (char *) -1) { panic("RS", "unable to allocate boot image buffer", NO_NUM); } } /* Reset the system process table. */ for (rp=BEG_RPROC_ADDR; rp<END_RPROC_ADDR; rp++) { rp->r_flags = 0; rp->r_pub = &rprocpub[rp - rproc]; rp->r_pub->in_use = FALSE; } /* Initialize the system process table in 4 steps, each of them following * the appearance of system services in the boot image priv table. * - Step 1: get a copy of the executable image of every system service that * requires it while it is not yet running. * In addition, set priviliges, sys properties, and dev properties (if any) * for every system service. */ for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } /* Lookup the corresponding entries in other tables. */ boot_image_info_lookup(boot_image_priv->endpoint, image, &ip, NULL, &boot_image_sys, &boot_image_dev); rp = &rproc[boot_image_priv - boot_image_priv_table]; rpub = rp->r_pub; /* * Get a copy of the executable image if required. */ rp->r_exec_len = 0; rp->r_exec = NULL; if(boot_image_sys->flags & SF_USE_COPY) { exec_image_copy(ip - image, ip, rp); } /* * Set privileges. */ /* Get label. */ strcpy(rpub->label, boot_image_priv->label); if(boot_image_priv->endpoint != RS_PROC_NR) { /* Force a static priv id for system services in the boot image. */ rp->r_priv.s_id = static_priv_id( _ENDPOINT_P(boot_image_priv->endpoint)); /* Initialize privilege bitmaps. */ rp->r_priv.s_flags = boot_image_priv->flags; /* priv flags */ rp->r_priv.s_trap_mask = boot_image_priv->trap_mask; /* traps */ memcpy(&rp->r_priv.s_ipc_to, &boot_image_priv->ipc_to, sizeof(rp->r_priv.s_ipc_to)); /* targets */ /* Initialize kernel call mask bitmap from unordered set. */ fill_call_mask(boot_image_priv->k_calls, NR_SYS_CALLS, rp->r_priv.s_k_call_mask, KERNEL_CALL, TRUE); /* Set the privilege structure. */ if ((s = sys_privctl(ip->endpoint, SYS_PRIV_SET_SYS, &(rp->r_priv))) != OK) { panic("RS", "unable to set privilege structure", s); } } /* Synch the privilege structure with the kernel. */ if ((s = sys_getpriv(&(rp->r_priv), ip->endpoint)) != OK) { panic("RS", "unable to synch privilege structure", s); } /* * Set sys properties. */ rpub->sys_flags = boot_image_sys->flags; /* sys flags */ /* * Set dev properties. */ rpub->dev_nr = boot_image_dev->dev_nr; /* major device number */ rpub->dev_style = boot_image_dev->dev_style; /* device style */ rpub->period = boot_image_dev->period; /* heartbeat period */ /* Get process name. */ strcpy(rpub->proc_name, ip->proc_name); /* Get command settings. */ rp->r_cmd[0]= '\0'; rp->r_argv[0] = rp->r_cmd; rp->r_argv[1] = NULL; rp->r_argc = 1; rp->r_script[0]= '\0'; /* Initialize vm call mask bitmap from unordered set. */ fill_call_mask(boot_image_priv->vm_calls, NR_VM_CALLS, rpub->vm_call_mask, VM_RQ_BASE, TRUE); /* Get some settings from the boot image table. */ rp->r_nice = ip->priority; rpub->endpoint = ip->endpoint; /* Set some defaults. */ rp->r_uid = 0; /* root */ rp->r_check_tm = 0; /* not checked yet */ getuptime(&rp->r_alive_tm); /* currently alive */ rp->r_stop_tm = 0; /* not exiting yet */ rp->r_restarts = 0; /* no restarts so far */ rp->r_set_resources = 0; /* don't set resources */ /* Mark as in use. */ rp->r_flags = RS_IN_USE; rproc_ptr[_ENDPOINT_P(rpub->endpoint)]= rp; rpub->in_use = TRUE; } /* - Step 2: allow every system service in the boot image to run. */ nr_uncaught_init_srvs = 0; for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } /* Ignore RS. */ if(boot_image_priv->endpoint == RS_PROC_NR) { continue; } /* Lookup the corresponding slot in the system process table. */ rp = &rproc[boot_image_priv - boot_image_priv_table]; rpub = rp->r_pub; /* Allow the service to run. */ if ((s = sys_privctl(rpub->endpoint, SYS_PRIV_ALLOW, NULL)) != OK) { panic("RS", "unable to initialize privileges", s); } /* Initialize service. We assume every service will always get * back to us here at boot time. */ if(boot_image_priv->flags & SYS_PROC) { if ((s = init_service(rp, SEF_INIT_FRESH)) != OK) { panic("RS", "unable to initialize service", s); } if(rpub->sys_flags & SF_SYNCH_BOOT) { /* Catch init ready message now to synchronize. */ catch_boot_init_ready(rpub->endpoint); } else { /* Catch init ready message later. */ nr_uncaught_init_srvs++; } } } /* - Step 3: let every system service complete initialization by * catching all the init ready messages left. */ while(nr_uncaught_init_srvs) { catch_boot_init_ready(ANY); nr_uncaught_init_srvs--; } /* - Step 4: all the system services in the boot image are now running. * Complete the initialization of the system process table in collaboration * with other system processes. */ if ((s = getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc)) != OK) { panic("RS", "unable to get copy of PM process table", s); } for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } /* Lookup the corresponding slot in the system process table. */ rp = &rproc[boot_image_priv - boot_image_priv_table]; rpub = rp->r_pub; /* Get pid from PM process table. */ rp->r_pid = NO_PID; for (j = 0; j < NR_PROCS; j++) { if (mproc[j].mp_endpoint == rpub->endpoint) { rp->r_pid = mproc[j].mp_pid; break; } } if(j == NR_PROCS) { panic("RS", "unable to get pid", NO_NUM); } } /* * Now complete RS initialization process in collaboration with other * system services. */ /* Let the rest of the system know about our dynamically allocated buffer. */ if(boot_image_buffer_size > 0) { boot_image_buffer = rs_startup_sbrk_synch(boot_image_buffer_size); if(boot_image_buffer == (char *) -1) { panic("RS", "unable to synch boot image buffer", NO_NUM); } } /* Set alarm to periodically check service status. */ if (OK != (s=sys_setalarm(RS_DELTA_T, 0))) panic("RS", "couldn't set alarm", s); /* Install signal handlers. Ask PM to transform signal into message. */ sa.sa_handler = SIG_MESS; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(SIGCHLD,&sa,NULL)<0) panic("RS","sigaction failed", errno); if (sigaction(SIGTERM,&sa,NULL)<0) panic("RS","sigaction failed", errno); /* Initialize the exec pipe. */ if (pipe(exec_pipe) == -1) panic("RS", "pipe failed", errno); if (fcntl(exec_pipe[0], F_SETFD, fcntl(exec_pipe[0], F_GETFD) | FD_CLOEXEC) == -1) { panic("RS", "fcntl set FD_CLOEXEC on pipe input failed", errno); } if (fcntl(exec_pipe[1], F_SETFD, fcntl(exec_pipe[1], F_GETFD) | FD_CLOEXEC) == -1) { panic("RS", "fcntl set FD_CLOEXEC on pipe output failed", errno); } if (fcntl(exec_pipe[0], F_SETFL, fcntl(exec_pipe[0], F_GETFL) | O_NONBLOCK) == -1) { panic("RS", "fcntl set O_NONBLOCK on pipe input failed", errno); } /* Map out our own text and data. This is normally done in crtso.o * but RS is an exception - we don't get to talk to VM so early on. * That's why we override munmap() and munmap_text() in utility.c. * * _minix_unmapzero() is the same code in crtso.o that normally does * it on startup. It's best that it's there as crtso.o knows exactly * what the ranges are of the filler data. */ unmap_ok = 1; _minix_unmapzero(); return(OK); }
void *vg_init(unsigned short mode) { struct reg86u r; vbe_mode_info_t *info = malloc(sizeof(vbe_mode_info_t)); if (vbe_get_mode_info(mode, info) != 0) { return NULL; } h_res=info->XResolution; v_res=info->YResolution; bits_per_pixel=info->BitsPerPixel; printf("%d\n", h_res); int erro; struct mem_range mr; /* Allow memory mapping */ unsigned int vram_size = h_res * v_res * (bits_per_pixel/8); mr.mr_base = (phys_bytes)(info->PhysBasePtr); mr.mr_limit = mr.mr_base + vram_size; if( OK != (erro = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr))) panic("video_gr: sys_privctl (ADD_MEM) failed: %d\n", erro); /* Map memory */ video_mem = vm_map_phys(SELF, (void *)mr.mr_base, vram_size); if(video_mem == MAP_FAILED) panic("video_gr couldn't map video memory"); r.u.w.ax = SET_MODE; // VBE call, function 02 -- set VBE mode r.u.w.bx = BIT(LINEAR_MODEL_BIT)|mode; // set bit 14: linear framebuffer r.u.b.intno = BIOS_SERVICE; if( sys_int86(&r) != OK ) { printf("set_vbe_mode: sys_int86() failed \n"); return NULL; } switch(r.u.b.ah){ case 0x01: printf("Function call failed \n"); return NULL; break; case 0x02: printf("Function is not supported in current HW configuration \n"); return NULL; break; case 0x03: printf("Function is invalid in current video mode \n"); return NULL; break; default: break; } vram_phisical_address = info->PhysBasePtr; return video_mem; }
/*===========================================================================* * main * *===========================================================================*/ int main(int argc, char **argv) { endpoint_t ep_self, ep_child; size_t size = BUF_SIZE; int i, r, pid; int status; /* SEF local startup. */ env_setargs(argc, argv); sef_local_startup(); /* Prepare work. */ buf = (char*) CLICK_CEIL(buf_buf); fid_get = open(FIFO_GRANTOR, O_RDONLY); fid_send = open(FIFO_REQUESTOR, O_WRONLY); if(fid_get < 0 || fid_send < 0) { printf("REQUESTOR: can't open fifo files.\n"); return 1; } /* Send the endpoint to the granter, in order to let him to * create the grant. */ ep_self = getprocnr(); write(fid_send, &ep_self, sizeof(ep_self)); dprint("REQUESTOR: sending my endpoint: %d\n", ep_self); /* Get the granter's endpoint and gid. */ read(fid_get, &ep_granter, sizeof(ep_granter)); read(fid_get, &gid, sizeof(gid)); dprint("REQUESTOR: getting granter's endpoint %d and gid %d\n", ep_granter, gid); /* Test MAP. */ FIFO_WAIT(fid_get); r = sys_safemap(ep_granter, gid, 0, (long)buf, size, 1); if(r != OK) { printf("REQUESTOR: error in sys_safemap: %d\n", r); return 1; } CHECK_TEST("REQUESTOR", buf[0], BUF_START_GRANTOR, "MAP"); buf[0] = BUF_START_REQUESTOR; r = sys_safeunmap((long)buf); if(r != OK) { printf("REQUESTOR: error in sys_safeunmap: %d\n", r); return 1; } FIFO_NOTIFY(fid_send); /* Test UNMAP. */ FIFO_WAIT(fid_get); CHECK_TEST("REQUESTOR", buf[0], BUF_START_REQUESTOR, "UNMAP"); r = sys_safemap(ep_granter, gid, 0, (long)buf, size, 1); if(r != 0) { printf("REQUESTOR: error in sys_safemap: %d\n", r); return 1; } FIFO_NOTIFY(fid_send); /* Test REVOKE. */ FIFO_WAIT(fid_get); CHECK_TEST("REQUESTOR", buf[0], BUF_START_GRANTOR, "REVOKE"); buf[0] = BUF_START_REQUESTOR; FIFO_NOTIFY(fid_send); /* Test SMAP_COW. */ FIFO_WAIT(fid_get); r = sys_safemap(ep_granter, gid, 0, (long)buf, size, 1); if(r != OK) { printf("REQUESTOR: error in sys_safemap: %d\n", r); return 1; } buf[0] = BUF_START_REQUESTOR; pid = fork(); if(pid < 0) { printf("REQUESTOR: error in fork\n"); return 1; } if(pid == 0) { exit(buf[0] != BUF_START_REQUESTOR); } FIFO_NOTIFY(fid_send); FIFO_WAIT(fid_get); ep_child = getnprocnr(pid); if ((r = sys_privctl(ep_child, SYS_PRIV_SET_USER, NULL)) != OK) { printf("REQUESTOR: unable to set privileges: %d\n", r); return 1; } if ((r = sys_privctl(ep_child, SYS_PRIV_ALLOW, NULL)) != OK) { printf("REQUESTOR: child process can't run: %d\n", r); return 1; } wait(&status); FIFO_NOTIFY(fid_send); CHECK_TEST("REQUESTOR", buf[0], BUF_START_GRANTOR, "SMAP_COW"); CHECK_TEST("REQUESTOR", 1, WIFEXITED(status) && (WEXITSTATUS(status) == 0), "SMAP_COW child"); /* Test COW_SMAP. */ FIFO_WAIT(fid_get); buf[0] = BUF_START_REQUESTOR; r = sys_safemap(ep_granter, gid, 0, (long)buf, size, 1); if(r != OK) { printf("REQUESTOR: error in sys_safemap: %d\n", r); return 1; } FIFO_NOTIFY(fid_send); FIFO_WAIT(fid_get); CHECK_TEST("REQUESTOR", buf[0], BUF_START_GRANTOR+1, "COW_SMAP"); /* Test COW_SMAP2 (with COW safecopy). */ FIFO_WAIT(fid_get); buf[0] = BUF_START_REQUESTOR; r = sys_safecopyto(ep_granter, gid, 0, (long)buf, size); if(r != OK) { printf("REQUESTOR: error in sys_safecopyto: %d\n", r); return 1; } r = sys_safemap(ep_granter, gid, 0, (long)buf, size, 1); if(r != OK) { printf("REQUESTOR: error in sys_safemap: %d\n", r); return 1; } FIFO_NOTIFY(fid_send); CHECK_TEST("REQUESTOR", buf[0], BUF_START_REQUESTOR, "COW_SMAP2"); return 0; }
/* * Initialize the MMC controller given a certain * instance. this driver only handles a single * mmchs controller at a given time. */ int mmchs_init(uint32_t instance) { uint32_t value; value = 0; struct minix_mem_range mr; spin_t spin; mr.mr_base = MMCHS1_REG_BASE; mr.mr_limit = MMCHS1_REG_BASE + 0x400; if (sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr) != 0) { panic("Unable to request permission to map memory"); } /* Set the base address to use */ base_address = (uint32_t) vm_map_phys(SELF, (void *) MMCHS1_REG_BASE, 0x400); if (base_address == (uint32_t) MAP_FAILED) panic("Unable to map MMC memory"); #ifdef DM37XX base_address = (unsigned long) base_address - 0x100; #endif /* Soft reset of the controller. This section is documented in the TRM */ /* Write 1 to sysconfig[0] to trigger a reset */ set32(base_address + MMCHS_SD_SYSCONFIG, MMCHS_SD_SYSCONFIG_SOFTRESET, MMCHS_SD_SYSCONFIG_SOFTRESET); /* Read sysstatus to know when it's done */ spin_init(&spin, SANE_TIMEOUT); while (!(read32(base_address + MMCHS_SD_SYSSTATUS) & MMCHS_SD_SYSSTATUS_RESETDONE)) { if (spin_check(&spin) == FALSE) { mmc_log_warn(&log, "mmc init timeout\n"); return 1; } } /* Set SD default capabilities */ set32(base_address + MMCHS_SD_CAPA, MMCHS_SD_CAPA_VS_MASK, MMCHS_SD_CAPA_VS18 | MMCHS_SD_CAPA_VS30); /* TRM mentions MMCHS_SD_CUR_CAPA but does not describe how to limit * the current */ uint32_t mask = MMCHS_SD_SYSCONFIG_AUTOIDLE | MMCHS_SD_SYSCONFIG_ENAWAKEUP | MMCHS_SD_SYSCONFIG_STANDBYMODE | MMCHS_SD_SYSCONFIG_CLOCKACTIVITY | MMCHS_SD_SYSCONFIG_SIDLEMODE; /* Automatic clock gating strategy */ value = MMCHS_SD_SYSCONFIG_AUTOIDLE_EN; /* Enable wake-up capability */ value |= MMCHS_SD_SYSCONFIG_ENAWAKEUP_EN; /* Smart-idle */ value |= MMCHS_SD_SYSCONFIG_SIDLEMODE_IDLE; /* Both the interface and functional can be switched off */ value |= MMCHS_SD_SYSCONFIG_CLOCKACTIVITY_OFF; /* Go into wake-up mode when possible */ value |= MMCHS_SD_SYSCONFIG_STANDBYMODE_WAKEUP_INTERNAL; /* * wake-up configuration */ set32(base_address + MMCHS_SD_SYSCONFIG, mask, value); /* Wake-up on sd interrupt for SDIO */ set32(base_address + MMCHS_SD_HCTL, MMCHS_SD_HCTL_IWE, MMCHS_SD_HCTL_IWE_EN); /* * MMC host and bus configuration */ /* Configure data and command transfer (1 bit mode) */ set32(base_address + MMCHS_SD_CON, MMCHS_SD_CON_DW8, MMCHS_SD_CON_DW8_1BIT); set32(base_address + MMCHS_SD_HCTL, MMCHS_SD_HCTL_DTW, MMCHS_SD_HCTL_DTW_1BIT); /* Configure card voltage to 3.0 volt */ set32(base_address + MMCHS_SD_HCTL, MMCHS_SD_HCTL_SDVS, MMCHS_SD_HCTL_SDVS_VS30); /* Power on the host controller and wait for the * MMCHS_SD_HCTL_SDBP_POWER_ON to be set */ set32(base_address + MMCHS_SD_HCTL, MMCHS_SD_HCTL_SDBP, MMCHS_SD_HCTL_SDBP_ON); // /* TODO: Add padconf/pinmux stuff here as documented in the TRM */ spin_init(&spin, SANE_TIMEOUT); while ((read32(base_address + MMCHS_SD_HCTL) & MMCHS_SD_HCTL_SDBP) != MMCHS_SD_HCTL_SDBP_ON) { if (spin_check(&spin) == FALSE) { mmc_log_warn(&log, "mmc init timeout SDBP not set\n"); return 1; } } /* Enable internal clock and clock to the card */ set32(base_address + MMCHS_SD_SYSCTL, MMCHS_SD_SYSCTL_ICE, MMCHS_SD_SYSCTL_ICE_EN); // @TODO Fix external clock enable , this one is very slow // but we first need faster context switching // set32(base_address + MMCHS_SD_SYSCTL, MMCHS_SD_SYSCTL_CLKD, // (0x20 << 6)); set32(base_address + MMCHS_SD_SYSCTL, MMCHS_SD_SYSCTL_CLKD, (0x5 << 6)); set32(base_address + MMCHS_SD_SYSCTL, MMCHS_SD_SYSCTL_CEN, MMCHS_SD_SYSCTL_CEN_EN); spin_init(&spin, SANE_TIMEOUT); while ((read32(base_address + MMCHS_SD_SYSCTL) & MMCHS_SD_SYSCTL_ICS) != MMCHS_SD_SYSCTL_ICS_STABLE) { if (spin_check(&spin) == FALSE) { mmc_log_warn(&log, "clock not stable\n"); return 1; } } /* * See spruh73e page 3576 Card Detection, Identification, and Selection */ /* Enable command interrupt */ set32(base_address + MMCHS_SD_IE, MMCHS_SD_IE_CC_ENABLE, MMCHS_SD_IE_CC_ENABLE_ENABLE); /* Enable transfer complete interrupt */ set32(base_address + MMCHS_SD_IE, MMCHS_SD_IE_TC_ENABLE, MMCHS_SD_IE_TC_ENABLE_ENABLE); /* enable error interrupts */ /* NOTE: We are currently skipping the BADA interrupt it does get * raised for unknown reasons */ set32(base_address + MMCHS_SD_IE, MMCHS_SD_IE_ERROR_MASK, 0x0fffffffu); /* clear the error interrupts */ set32(base_address + MMCHS_SD_STAT, MMCHS_SD_STAT_ERROR_MASK, 0xffffffffu); /* send a init signal to the host controller. This does not actually * send a command to a card manner */ set32(base_address + MMCHS_SD_CON, MMCHS_SD_CON_INIT, MMCHS_SD_CON_INIT_INIT); /* command 0 , type other commands not response etc) */ write32(base_address + MMCHS_SD_CMD, 0x00); spin_init(&spin, SANE_TIMEOUT); while ((read32(base_address + MMCHS_SD_STAT) & MMCHS_SD_STAT_CC) != MMCHS_SD_STAT_CC_RAISED) { if (read32(base_address + MMCHS_SD_STAT) & 0x8000) { mmc_log_warn(&log, "%s, error stat %x\n", __FUNCTION__, read32(base_address + MMCHS_SD_STAT)); return 1; } if (spin_check(&spin) == FALSE) { mmc_log_warn(&log, "Interrupt not raised during init\n"); return 1; } } /* clear the cc interrupt status */ set32(base_address + MMCHS_SD_STAT, MMCHS_SD_IE_CC_ENABLE, MMCHS_SD_IE_CC_ENABLE_ENABLE); /* * Set Set SD_CON[1] INIT bit to 0x0 to end the initialization sequence */ set32(base_address + MMCHS_SD_CON, MMCHS_SD_CON_INIT, MMCHS_SD_CON_INIT_NOINIT); /* Set timeout */ set32(base_address + MMCHS_SD_SYSCTL, MMCHS_SD_SYSCTL_DTO, MMCHS_SD_SYSCTL_DTO_2POW27); /* Clean the MMCHS_SD_STAT register */ write32(base_address + MMCHS_SD_STAT, 0xffffffffu); #ifdef USE_INTR hook_id = 1; if (sys_irqsetpolicy(OMAP3_MMC1_IRQ, 0, &hook_id) != OK) { printf("mmc: couldn't set IRQ policy %d\n", OMAP3_MMC1_IRQ); return 1; } /* enable signaling from MMC controller towards interrupt controller */ write32(base_address + MMCHS_SD_ISE, 0xffffffffu); #endif return 0; }