Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4cee997)
raw | patch | inline | side by side (parent: 4cee997)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Tue, 1 Jul 2014 17:23:31 +0000 (01:23 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Wed, 3 Nov 2021 02:45:34 +0000 (10:45 +0800) |
| drivers/ide.c | patch | blob | history | |
| drivers/keyboard.c | patch | blob | history | |
| drivers/vga.c | patch | blob | history | |
| include/pci.h | patch | blob | history | |
| kernel/clock.c | patch | blob | history | |
| kernel/pci.c | patch | blob | history | |
| kernel/setup.c | patch | blob | history | |
| lib/string.c | patch | blob | history | |
| lib/vsprintf.c | patch | blob | history |
diff --git a/drivers/ide.c b/drivers/ide.c
--- a/drivers/ide.c
+++ b/drivers/ide.c
typedef struct _ide_drv
{
pci_device_t *pci;
- unsigned long cmd_cnt;
+ unsigned long pio_cnt;
+ unsigned long dma_cnt;
unsigned long irq_cnt;
unsigned int iobase;
void ide_printd()
{
- printd(MPL_IDE, "ide cmd cnt %d irq cnt %d", drv.cmd_cnt, drv.irq_cnt);
+ printd(MPL_IDE, "ide pio_cnt %d dma_cnt %d irq_cnt %d", drv.pio_cnt, drv.dma_cnt, drv.irq_cnt);
}
void ide_cmd_out(Dev dev, u32 nsect, u64 sect_nr, u32 cmd)
{
- drv.cmd_cnt++;
+ drv.pio_cnt++;
drv.read_mode = cmd;
+ ide_printd();
+
outb(0x00, REG_CTL(dev));
outb(0x40, REG_DEVSEL(dev));
outb((u8)((sect_nr>>16)&0xFF), REG_LBAH(dev));
outb(cmd, REG_CMD(dev));
-
- ide_printd();
}
DECLARE_MUTEX(mutex);
-void init_pci_controller(unsigned int vendor, unsigned int device)
+void init_pci_controller(unsigned int classcode)
{
- pci_device_t *pci = pci_find_device(vendor, device);
- if(pci != 0)
+ pci_device_t *pci = pci_find_device_by_classcode(classcode);
+ if(pci != 0 && pci->intr_line < 16)
{
- printk("Found PCI Vendor %04x Device %04x Class %04x IntrLine %d\n", vendor, device, pci->classcode, pci->intr_line);
- printd(17, "Found PCI Vendor %04x Device %04x Class %04x IntrLine %d", vendor, device, pci->classcode, pci->intr_line);
+ printk("Found PCI Vendor %04x Device %04x Class %04x IntrLine %d\n", pci->vendor, pci->device, pci->classcode, pci->intr_line);
+ printd(17, "Found PCI Vendor %04x Device %04x Class %04x IntrLine %d", pci->vendor, pci->device, pci->classcode, pci->intr_line);
ide_pci_init(pci);
drv.pci = pci;
}
insl(REG_DATA(0), buf, (512>>2));
sig = *((u16_t *) (buf+510));
}
+
if(drv.read_mode == HD_CMD_READ_DMA)
{
sig = *((u16_t *) (data+510));
}
+
ide_printd();
printk("hard disk sig %04x read mode %x cnt %d\n", sig, drv.read_mode, drv.irq_cnt);
void ide_dma_pci_lba48()
{
+ drv.dma_cnt ++;
drv.read_mode = HD_CMD_READ_DMA;
#if 1
memset((void *)&prd, 0, sizeof(prd));
break;
}
}
-#endif
outb(0x00, HD_CHL0_CMD_BASE+HD_DEVSEL);
DELAY400NS;
-#if 0
while ( 1 )
{
status = inb(HD_CHL0_CMD_BASE+HD_STATUS);
}
#endif
- printd(16, "---------------------------------------");
-
outb(0x00, HD_CHL0_CTL_BASE); // Device Control
outb(0x00, HD_CHL0_CMD_BASE+HD_FEATURES);
void ide_init()
{
memset((void *)&drv, 0, sizeof(drv));
- init_pci_controller(PCI_VENDORID_INTEL, 0x2829);
- init_pci_controller(PCI_VENDORID_INTEL, 0x7010);
+ init_pci_controller(0x0106);
+ init_pci_controller(0x0101);
#if 1
ide_read_identify();
ide_printd();
diff --git a/drivers/keyboard.c b/drivers/keyboard.c
--- a/drivers/keyboard.c
+++ b/drivers/keyboard.c
void ide_dma_pci_lba48();
unsigned long kbd_cnt = 0;
+
void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id)
{
unsigned char scan_code;
diff --git a/drivers/vga.c b/drivers/vga.c
--- a/drivers/vga.c
+++ b/drivers/vga.c
__vga_switch(offset);
}
+
void vga_dbg_puts(unsigned int line, const char *buf, unsigned char color)
{
int i;
char *p = (char *) buf;
vga_char_t * const pv = (vga_char_t * const) (VIDEO_ADDR + (VIDEO_DBG_LINE + line) * BYTES_PER_LINE);
+ for(i=0; i<CHARS_PER_LINE; ++i)
+ pv[i] = vga_char(0, color);
+
for(i=0; *p; ++i, ++p)
{
pv[i] = vga_char(*p, color);
diff --git a/include/pci.h b/include/pci.h
--- a/include/pci.h
+++ b/include/pci.h
unsigned int command;
unsigned int status;
unsigned int revision;
+ unsigned int progif;
unsigned int classcode;
unsigned int hdr_type;
//unsigned int bar0, bar1, bar2, bar3, bar4, bar5;
#define PCI_VENDORID_REALTEK 0x10EC
pci_device_t *pci_find_device(unsigned int vendor, unsigned int device);
+pci_device_t *pci_find_device_by_classcode(unsigned int classcode);
static inline u32 pci_cmd(pci_device_t *pci, unsigned int reg) {
return PCI_CMD(pci->bus, pci->dev, pci->devfn, reg);
diff --git a/kernel/clock.c b/kernel/clock.c
--- a/kernel/clock.c
+++ b/kernel/clock.c
static unsigned int jiffies = 0;
-void clk_handler(unsigned int irq, pt_regs_t * regs, void *dev_id)
+void clk_handler(unsigned int irq, pt_regs_t * regs, void *dev_id)
{
jiffies++;
printk("^");
- printd(0, "clock:%d", jiffies);
+ printd(MPL_CLOCK, "clock:%d", jiffies);
}
diff --git a/kernel/pci.c b/kernel/pci.c
--- a/kernel/pci.c
+++ b/kernel/pci.c
LIST_HEAD(pci_devs);
+const char *pci_get_info(unsigned int classcode, unsigned int progif);
+
int pci_read_config_byte(int cmd)
{
outl(PCI_CONFIG_CMD(cmd), PCI_ADDR);
cmd = PCI_CMD(bus, dev, devfn, PCI_REVISION);
pci->revision = pci_read_config_byte(cmd);
+ cmd = PCI_CMD(bus, dev, devfn, PCI_PROGIF);
+ pci->progif = pci_read_config_byte(cmd);
+
cmd = PCI_CMD(bus, dev, devfn, PCI_CLASSCODE);
pci->classcode = pci_read_config_word(cmd);
return 0;
}
+pci_device_t *pci_find_device_by_classcode(unsigned int classcode)
+{
+ int i;
+ list_head_t *p;
+ pci_device_t *pci = 0;
+
+ list_for_each(p, &pci_devs)
+ {
+ pci = list_entry(p, pci_device_t, list);
+
+ if(pci->classcode == classcode)
+ return pci;
+ }
+
+ return 0;
+}
+
void dump_pci_dev()
{
list_head_t *p;
list_for_each(p, &pci_devs)
{
pci_device_t *pci = list_entry(p, pci_device_t, list);
- printk("Vendor %x Device %x Class %x Revision %x IntrLine %d Pin %d ", pci->vendor, pci->device, pci->classcode, pci->revision, pci->intr_line, pci->intr_pin);
-
+ printk("Vendor %04x Device %04x Class %04x Intr %02d ", pci->vendor, pci->device, pci->classcode, pci->intr_line);
+ printk("%s\n", pci_get_info(pci->classcode, pci->progif));
+ continue;
switch(pci->hdr_type)
{
case PCI_HDRTYPE_NORMAL:
}
}
-
return 1;
err:
printk("Can not find PCI bus on your computer\n");
dump_pci_dev();
}
+typedef struct pci_info {
+ unsigned long code;
+ unsigned int flag;
+ const char *info;
+} pci_info_t;
+
+pci_info_t pci_info[] = {
+ { 0x000000, 0, "Any device except for VGA-Compatible devices" },
+ { 0x000100, 0, "VGA-Compatible Device" },
+ { 0x010000, 0, "SCSI Bus Controller" },
+ { 0x0101, 1, "IDE Controller" },
+ { 0x010200, 0, "Floppy Disk Controller" },
+ { 0x010300, 0, "IPI Bus Controller" },
+ { 0x010400, 0, "RAID Controller" },
+ { 0x010520, 0, "ATA Controller (Single DMA)" },
+ { 0x010530, 0, "ATA Controller (Chained DMA)" },
+ { 0x010600, 0, "Serial ATA (Vendor Specific Interface)" },
+ { 0x010601, 0, "Serial ATA (AHCI 1.0)" },
+ { 0x010700, 0, "Serial Attached SCSI (SAS)" },
+ { 0x018000, 0, "Other Mass Storage Controller" },
+ { 0x020000, 0, "Ethernet Controller" },
+ { 0x020100, 0, "Token Ring Controller" },
+ { 0x020200, 0, "FDDI Controller" },
+ { 0x020300, 0, "ATM Controller" },
+ { 0x020400, 0, "ISDN Controller" },
+ { 0x020500, 0, "WorldFip Controller" },
+ { 0x0206, 1, "PICMG 2.14 Multi Computing" },
+ { 0x028000, 0, "Other Network Controller" },
+ { 0x030000, 0, "VGA-Compatible Controller" },
+ { 0x030001, 0, "8512-Compatible Controller" },
+ { 0x030100, 0, "XGA Controller" },
+ { 0x030200, 0, "3D Controller (Not VGA-Compatible)" },
+ { 0x038000, 0, "Other Display Controller" },
+ { 0x040000, 0, "Video Device" },
+ { 0x040100, 0, "Audio Device" },
+ { 0x040200, 0, "Computer Telephony Device" },
+ { 0x048000, 0, "Other Multimedia Device" },
+ { 0x050000, 0, "RAM Controller" },
+ { 0x050100, 0, "Flash Controller" },
+ { 0x058000, 0, "Other Memory Controller" },
+ { 0x060000, 0, "Host Bridge" },
+ { 0x060100, 0, "ISA Bridge" },
+ { 0x060200, 0, "EISA Bridge" },
+ { 0x060300, 0, "MCA Bridge" },
+ { 0x060400, 0, "PCI-to-PCI Bridge" },
+ { 0x060401, 0, "PCI-to-PCI Bridge (Subtractive Decode)" },
+ { 0x060500, 0, "PCMCIA Bridge" },
+ { 0x060600, 0, "NuBus Bridge" },
+ { 0x060700, 0, "CardBus Bridge" },
+ { 0x0608, 1, "RACEway Bridge" },
+ { 0x060940, 0, "PCI-to-PCI Bridge (Semi-Transparent, Primary)" },
+ { 0x060980, 0, "PCI-to-PCI Bridge (Semi-Transparent, Secondary)" },
+ { 0x060A00, 0, "InfiniBrand-to-PCI Host Bridge" },
+ { 0x068000, 0, "Other Bridge Device" },
+ { 0x070000, 0, "Generic XT-Compatible Serial Controller" },
+ { 0x070001, 0, "16450-Compatible Serial Controller" },
+ { 0x070002, 0, "16550-Compatible Serial Controller" },
+ { 0x070003, 0, "16650-Compatible Serial Controller" },
+ { 0x070004, 0, "16750-Compatible Serial Controller" },
+ { 0x070005, 0, "16850-Compatible Serial Controller" },
+ { 0x070006, 0, "16950-Compatible Serial Controller" },
+ { 0x070100, 0, "Parallel Port" },
+ { 0x070101, 0, "Bi-Directional Parallel Port" },
+ { 0x070102, 0, "ECP 1.X Compliant Parallel Port" },
+ { 0x070103, 0, "IEEE 1284 Controller" },
+ { 0x0701FE, 0, "IEEE 1284 Target Device" },
+ { 0x070200, 0, "Multiport Serial Controller" },
+ { 0x070300, 0, "Generic Modem" },
+ { 0x070301, 0, "Hayes Compatible Modem (16450-Compatible Interface)" },
+ { 0x070302, 0, "Hayes Compatible Modem (16550-Compatible Interface)" },
+ { 0x070303, 0, "Hayes Compatible Modem (16650-Compatible Interface)" },
+ { 0x070304, 0, "Hayes Compatible Modem (16750-Compatible Interface)" },
+ { 0x070400, 0, "IEEE 488.1/2 (GPIB) Controller" },
+ { 0x070500, 0, "Smart Card" },
+ { 0x078000, 0, "Other Communications Device" },
+ { 0x080000, 0, "Generic 8259 PIC" },
+ { 0x080001, 0, "ISA PIC" },
+ { 0x080002, 0, "EISA PIC" },
+ { 0x080010, 0, "I/O APIC Interrupt Controller" },
+ { 0x080020, 0, "I/O(x) APIC Interrupt Controller" },
+ { 0x080100, 0, "Generic 8237 DMA Controller" },
+ { 0x080101, 0, "ISA DMA Controller" },
+ { 0x080102, 0, "EISA DMA Controller" },
+ { 0x080200, 0, "Generic 8254 System Timer" },
+ { 0x080201, 0, "ISA System Timer" },
+ { 0x080202, 0, "EISA System Timer" },
+ { 0x080300, 0, "Generic RTC Controller" },
+ { 0x080301, 0, "ISA RTC Controller" },
+ { 0x080400, 0, "Generic PCI Hot-Plug Controller" },
+ { 0x088000, 0, "Other System Peripheral" },
+ { 0x090000, 0, "Keyboard Controller" },
+ { 0x090100, 0, "Digitizer" },
+ { 0x090200, 0, "Mouse Controller" },
+ { 0x090300, 0, "Scanner Controller" },
+ { 0x090400, 0, "Gameport Controller (Generic)" },
+ { 0x090410, 0, "Gameport Contrlller (Legacy)" },
+ { 0x098000, 0, "Other Input Controller" },
+ { 0x0A0000, 0, "Generic Docking Station" },
+ { 0x0A8000, 0, "Other Docking Station" },
+ { 0x0B0000, 0, "386 Processor" },
+ { 0x0B0100, 0, "486 Processor" },
+ { 0x0B0200, 0, "Pentium Processor" },
+ { 0x0B1000, 0, "Alpha Processor" },
+ { 0x0B2000, 0, "PowerPC Processor" },
+ { 0x0B3000, 0, "MIPS Processor" },
+ { 0x0B4000, 0, "Co-Processor" },
+ { 0x0C0000, 0, "IEEE 1394 Controller (FireWire)" },
+ { 0x0C0010, 0, "IEEE 1394 Controller (1394 OpenHCI Spec)" },
+ { 0x0C0100, 0, "ACCESS.bus" },
+ { 0x0C0200, 0, "SSA" },
+ { 0x0C0300, 0, "USB (Universal Host Controller Spec)" },
+ { 0x0C0310, 0, "USB (Open Host Controller Spec" },
+ { 0x0C0320, 0, "USB2 Host Controller (Intel Enhanced Host Controller Interface)" },
+ { 0x0C0380, 0, "USB" },
+ { 0x0C03FE, 0, "USB (Not Host Controller)" },
+ { 0x0C0400, 0, "Fibre Channel" },
+ { 0x0C0500, 0, "SMBus" },
+ { 0x0C0600, 0, "InfiniBand" },
+ { 0x0C0700, 0, "IPMI SMIC Interface" },
+ { 0x0C0701, 0, "IPMI Kybd Controller Style Interface" },
+ { 0x0C0702, 0, "IPMI Block Transfer Interface" },
+ { 0x0C0800, 0, "SERCOS Interface Standard (IEC 61491)" },
+ { 0x0C0900, 0, "CANbus" },
+ { 0x0D0000, 0, "iRDA Compatible Controller" },
+ { 0x0D0100, 0, "Consumer IR Controller" },
+ { 0x0D1000, 0, "RF Controller" },
+ { 0x0D1100, 0, "Bluetooth Controller" },
+ { 0x0D1200, 0, "Broadband Controller" },
+ { 0x0D2000, 0, "Ethernet Controller (802.11a)" },
+ { 0x0D2100, 0, "Ethernet Controller (802.11b)" },
+ { 0x0D8000, 0, "Other Wireless Controller" },
+ { 0x0E00, 1, "I20 Architecture" },
+ { 0x0E0000, 0, "Message FIFO" },
+ { 0x0F0100, 0, "TV Controller" },
+ { 0x0F0200, 0, "Audio Controller" },
+ { 0x0F0300, 0, "Voice Controller" },
+ { 0x0F0400, 0, "Data Controller" },
+ { 0x100000, 0, "Network and Computing Encrpytion/Decryption" },
+ { 0x101000, 0, "Entertainment Encryption/Decryption" },
+ { 0x108000, 0, "Other Encryption/Decryption" },
+ { 0x110000, 0, "DPIO Modules" },
+ { 0x110100, 0, "Performance Counters" },
+ { 0x111000, 0, "Communications Syncrhonization Plus Time and Frequency Test/Measurment" },
+ { 0x112000, 0, "Management Card" },
+ { 0x118000, 0, "Other Data Acquisition/Signal Processing Controller" },
+ { 0x000000, 0, 0 }
+};
+
+const char *pci_get_info(unsigned int classcode, unsigned int progif)
+{
+ pci_info_t *p = pci_info;
+ while(p->code != 0 || p->flag != 0 || p->info != 0)
+ {
+ unsigned long code = classcode;
+
+ if(p->flag == 0)
+ {
+ code <<= 8;
+ code |= progif & 0xFF;
+ }
+
+ if(p->code == code)
+ return p->info;
+
+ p++;
+ }
+
+ return 0;
+}
diff --git a/kernel/setup.c b/kernel/setup.c
--- a/kernel/setup.c
+++ b/kernel/setup.c
set_tss();
setup_sysc();
- setup_pci();
cnsl_init();
setup_irqs();
+ setup_pci();
+
void ide_init();
ide_init();
detect_cpu();
printk("%s\n", version);
+ printd(0, "-----------------------------------------------------------");
return;
while(1); // TODO MODIFY CODE BELOW
diff --git a/lib/string.c b/lib/string.c
--- a/lib/string.c
+++ b/lib/string.c
while(*str++) i++;
return i;
}
-int strcmp(const char *a, const char *b)
+
+int strcmp(const char *a, const char *b)
{
int delta;
while (*a || *b)
return 0;
}
-int strncmp(const char *a, const char *b, size_t count)
+int strncmp(const char *a, const char *b, size_t count)
{
unsigned char c1, c2;
int delta;
return 0;
}
-char *strcat(char *dest, const char *src)
+char *strcat(char *dest, const char *src)
{
char *tmp = dest;
while(*dest) dest++;
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
int write_buf(char *buf, const char *str, char fillch, int charcnt, int align)
{
+ if(str == 0)
+ return 0;
+
int len = strlen(str);
int delta_char_cnt = charcnt - len;