⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 driver.h

📁 一个简单的操作系统minix的核心代码
💻 H
📖 第 1 页 / 共 2 页
字号:
09220	        tmp_phys += DMA_BUF_SIZE;
09221	  }
09222	}
	
09224	/*===========================================================================*
09225	 *                              do_rdwt                                      *
09226	 *===========================================================================*/
09227	PUBLIC int do_rdwt(dp, m_ptr)
09228	struct driver *dp;              /* device dependent entry points */
09229	message *m_ptr;                 /* pointer to read or write message */
09230	{
09231	/* Carry out a single read or write request. */
09232	  struct iorequest_s ioreq;
09233	  int r;
09234	
09235	  if (m_ptr->COUNT <= 0) return(EINVAL);
09236	
09237	  if ((*dp->dr_prepare)(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
09238	
09239	  ioreq.io_request = m_ptr->m_type;
09240	  ioreq.io_buf = m_ptr->ADDRESS;
09241	  ioreq.io_position = m_ptr->POSITION;
09242	  ioreq.io_nbytes = m_ptr->COUNT;
09243	
09244	  r = (*dp->dr_schedule)(m_ptr->PROC_NR, &ioreq);
09245	
09246	  if (r == OK) (void) (*dp->dr_finish)();
09247	
09248	  r = ioreq.io_nbytes;
09249	  return(r < 0 ? r : m_ptr->COUNT - r);
09250	}
	
09252	/*==========================================================================*
09253	 *                              do_vrdwt                                    *
09254	 *==========================================================================*/
09255	PUBLIC int do_vrdwt(dp, m_ptr)
09256	struct driver *dp;      /* device dependent entry points */
09257	message *m_ptr;         /* pointer to read or write message */
09258	{
09259	/* Fetch a vector of i/o requests.  Handle requests one at a time.  Return
09260	 * status in the vector.
09261	 */
09262	
09263	  struct iorequest_s *iop;
09264	  static struct iorequest_s iovec[NR_IOREQS];
09265	  phys_bytes iovec_phys;
09266	  unsigned nr_requests;
09267	  int request;
09268	  int r;
09269	  phys_bytes user_iovec_phys;
09270	
09271	  nr_requests = m_ptr->COUNT;
09272	
09273	  if (nr_requests > sizeof iovec / sizeof iovec[0])
09274	        panic("FS passed too big an I/O vector", nr_requests);
09275	
09276	  iovec_phys = vir2phys(iovec);
09277	  user_iovec_phys = numap(m_ptr->PROC_NR, (vir_bytes) m_ptr->ADDRESS,
09278	                         (vir_bytes) (nr_requests * sizeof iovec[0]));
09279	
09280	  if (user_iovec_phys == 0)
09281	        panic("FS passed a bad I/O vector", (int) m_ptr->ADDRESS);
09282	
09283	  phys_copy(user_iovec_phys, iovec_phys,
09284	                            (phys_bytes) nr_requests * sizeof iovec[0]);
09285	
09286	  if ((*dp->dr_prepare)(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
09287	
09288	  for (request = 0, iop = iovec; request < nr_requests; request++, iop++) {
09289	        if ((r = (*dp->dr_schedule)(m_ptr->PROC_NR, iop)) != OK) break;
09290	  }
09291	
09292	  if (r == OK) (void) (*dp->dr_finish)();
09293	
09294	  phys_copy(iovec_phys, user_iovec_phys,
09295	                            (phys_bytes) nr_requests * sizeof iovec[0]);
09296	  return(OK);
09297	}
	
09299	/*===========================================================================*
09300	 *                              no_name                                      *
09301	 *===========================================================================*/
09302	PUBLIC char *no_name()
09303	{
09304	/* If no specific name for the device. */
09305	
09306	  return(tasktab[proc_number(proc_ptr) + NR_TASKS].name);
09307	}
	
09309	/*============================================================================*
09310	 *                              do_nop                                        *
09311	 *============================================================================*/
09312	PUBLIC int do_nop(dp, m_ptr)
09313	struct driver *dp;
09314	message *m_ptr;
09315	{
09316	/* Nothing there, or nothing to do. */
09317	
09318	  switch (m_ptr->m_type) {
09319	  case DEV_OPEN:        return(ENODEV);
09320	  case DEV_CLOSE:       return(OK);
09321	  case DEV_IOCTL:       return(ENOTTY);
09322	  default:              return(EIO);
09323	  }
09324	}
	
09326	/*===========================================================================*
09327	 *                              nop_finish                                   *
09328	 *===========================================================================*/
09329	PUBLIC int nop_finish()
09330	{
09331	/* Nothing to finish, all the work has been done by dp->dr_schedule. */
09332	  return(OK);
09333	}
	
09335	/*===========================================================================*
09336	 *                              nop_cleanup                                  *
09337	 *===========================================================================*/
09338	PUBLIC void nop_cleanup()
09339	{
09340	/* Nothing to clean up. */
09341	}
	
09343	/*===========================================================================*
09344	 *                              clock_mess                                   *
09345	 *===========================================================================*/
09346	PUBLIC void clock_mess(ticks, func)
09347	int ticks;                      /* how many clock ticks to wait */
09348	watchdog_t func;                /* function to call upon time out */
09349	{
09350	/* Send the clock task a message. */
09351	
09352	  message mess;
09353	
09354	  mess.m_type = SET_ALARM;
09355	  mess.CLOCK_PROC_NR = proc_number(proc_ptr);
09356	  mess.DELTA_TICKS = (long) ticks;
09357	  mess.FUNC_TO_CALL = (sighandler_t) func;
09358	  sendrec(CLOCK, &mess);
09359	}
	
09361	/*============================================================================*
09362	 *                              do_diocntl                                    *
09363	 *============================================================================*/
09364	PUBLIC int do_diocntl(dp, m_ptr)
09365	struct driver *dp;
09366	message *m_ptr;                 /* pointer to ioctl request */
09367	{
09368	/* Carry out a partition setting/getting request. */
09369	  struct device *dv;
09370	  phys_bytes user_phys, entry_phys;
09371	  struct partition entry;
09372	
09373	  if (m_ptr->REQUEST != DIOCSETP && m_ptr->REQUEST != DIOCGETP) return(ENOTTY);
09374	
09375	  /* Decode the message parameters. */
09376	  if ((dv = (*dp->dr_prepare)(m_ptr->DEVICE)) == NIL_DEV) return(ENXIO);
09377	
09378	  user_phys = numap(m_ptr->PROC_NR, (vir_bytes) m_ptr->ADDRESS, sizeof(entry));
09379	  if (user_phys == 0) return(EFAULT);
09380	
09381	  entry_phys = vir2phys(&entry);
09382	
09383	  if (m_ptr->REQUEST == DIOCSETP) {
09384	        /* Copy just this one partition table entry. */
09385	        phys_copy(user_phys, entry_phys, (phys_bytes) sizeof(entry));
09386	        dv->dv_base = entry.base;
09387	        dv->dv_size = entry.size;
09388	  } else {
09389	        /* Return a partition table entry and the geometry of the drive. */
09390	        entry.base = dv->dv_base;
09391	        entry.size = dv->dv_size;
09392	        (*dp->dr_geometry)(&entry);
09393	        phys_copy(entry_phys, user_phys, (phys_bytes) sizeof(entry));
09394	  }
09395	  return(OK);
09396	}













⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -