Răsfoiți Sursa

3.913u-pci: wrote function to get device configuration

rain 5 ani în urmă
părinte
comite
560dc9fe5e
7 a modificat fișierele cu 101 adăugiri și 15 ștergeri
  1. 1 0
      LINES
  2. 2 2
      Makefile
  3. 3 0
      README.md
  4. 37 0
      include/kernel/pci.h
  5. 3 12
      init/main.c
  6. 1 1
      kernel/Makefile
  7. 54 0
      kernel/pci.c

+ 1 - 0
LINES

@@ -17,4 +17,5 @@
 2021-7-08 2.327: 2327 lines, 26 files, rain
 2021-7-11 3.455: 3455 lines, 32 files, rain
 2021-7-18 3.831: 3831 lines, 33 files, rain
+2021-7-18 3.913: 3913 lines, 35 files, rain
 

+ 2 - 2
Makefile

@@ -1,8 +1,8 @@
 OBJS = boot/bootsect 
 RLIB_SRCS = kernel/rlib/bitman.c kernel/rlib/bitmap.c
 RLIB_OBJS = kernel/rlib/bitman.o kernel/rlib/bitmap.o 
-KOBJS = init/head.o init/main.o kernel/int.o kernel/trap.o kernel/graphic.o kernel/vsprintf.o kernel/irq.o kernel/panic.o kernel/mm.o font.o $(RLIB_OBJS)
-KSRCS = init/head.S init/main.c kernel/int.c kernel/trap.S kernel/graphic.c kernel/vsprintf.c kernel/irq.c kernel/panic.c kernel/mm.c $(RLIB_SRCS)
+KOBJS = init/head.o init/main.o kernel/int.o kernel/trap.o kernel/graphic.o kernel/vsprintf.o kernel/irq.o kernel/panic.o kernel/mm.o kernel/pci.o font.o $(RLIB_OBJS)
+KSRCS = init/head.S init/main.c kernel/int.c kernel/trap.S kernel/graphic.c kernel/vsprintf.c kernel/irq.c kernel/panic.c kernel/mm.c kernel/pci.c $(RLIB_SRCS)
 
 all: Makefile
 	make -C tools/

+ 3 - 0
README.md

@@ -78,3 +78,6 @@ source software, you can get its source code from <https://gitee.com/pengruiyang
 &nbsp;&nbsp;&nbsp;&nbsp;we can use `alloc_page` and `free_page` to allocate/free memory. 
 &nbsp;&nbsp;&nbsp;&nbsp;and don't forget to call `mm_init` first. 
 
+3.913u-pci:  
+&nbsp;&nbsp;&nbsp;&nbsp;I only wrote one function that called `pci_read_config`, and I think PCI is only for this (read device's config). 
+

+ 37 - 0
include/kernel/pci.h

@@ -0,0 +1,37 @@
+/* Copyright (C) 2021 Rain */
+
+/* This file is part of XNIX. */
+
+/* 
+  XNIX 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, either version 3 of the License, or 
+  (at your option) and later version. 
+*/
+
+/*
+  XNIX 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 XNIX. If not, see <https://www.gnu.org/licenses/>.  
+*/
+
+
+
+
+#ifndef _PCI_H
+#define _PCI_H
+
+#include <kernel/types.h>
+#include <kernel/errno.h>
+
+
+__uint32_t pci_read_config(__uint8_t, __uint8_t, __uint8_t, __uint8_t);
+
+#endif
+

+ 3 - 12
init/main.c

@@ -32,6 +32,7 @@
 #include <kernel/schk.h>
 
 #include <kernel/mm.h>
+#include <kernel/pci.h>
 
 #include <lib/string.h>
 
@@ -58,19 +59,9 @@ int init(void) {
 	int_init();
 	mm_init();
 
-	int *i = alloc_page();
-	int *p = alloc_page();
+	__uint32_t config = pci_read_config(0x0, 0x00, 0x00, 0x00);
 
-	printk(0x00ffffff, 0x00000000, "alloc_page: %q\n", i);
-	printk(0x00ffffff, 0x00000000, "alloc_page: %q\n", p);
-
-	free_page(i);
-	i = alloc_page();
-
-	printk(0x00ffffff, 0x00000000, "free i and alloc_page: %q\n", i);
-
-	free_page(i);
-	free_page(p);
+	printk(0x00ffffff, 0x00000000, "read pci config: %x\n", config);
 
 	return 0;
 }

+ 1 - 1
kernel/Makefile

@@ -1,6 +1,6 @@
 CFLAGS = -mcmodel=large -fno-builtin -m64 -I ../include/ -Wall -Werror -g
 
-all: int.o trap.o graphic.o vsprintf.o irq.o panic.o mm.o 
+all: int.o trap.o graphic.o vsprintf.o irq.o panic.o mm.o pci.o 
 
 
 %.o: %.S

+ 54 - 0
kernel/pci.c

@@ -0,0 +1,54 @@
+/* Copyright (C) 2021 Rain */
+
+/* This file is part of XNIX. */
+
+/* 
+  XNIX 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, either version 3 of the License, or 
+  (at your option) and later version. 
+*/
+
+/*
+  XNIX 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 XNIX. If not, see <https://www.gnu.org/licenses/>.  
+*/
+
+
+
+
+#include <kernel/init.h>
+#include <kernel/errno.h>
+#include <kernel/types.h>
+
+#include <kernel/graphic.h>
+#include <kernel/int.h>
+
+#include <arch/x86/int.h>
+#include <arch/io.h>
+#include <arch/sys.h>
+
+
+
+__uint32_t pci_read_config(__uint8_t bus, __uint8_t slot, __uint8_t func, __uint8_t offset) {
+	__uint32_t addr;
+
+#define lbus  ((__uint32_t) bus)
+#define lslot ((__uint32_t) slot)
+#define lfunc ((__uint32_t) func)
+
+	addr = (lbus << 16) | (lslot << 11) | (lfunc << 8) | (offset & 0xfc) | 0x80000000ul;
+
+	outl(addr, 0xcf8);
+
+	return inl(0xcfc);
+}
+
+