mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2025-01-03 19:26:30 +00:00
8a5e9328ca
Add newlines to OS Upgrade questions. Move PCNet interrupt #defines. Improve E1000 PCI device loading. Add comments in E1000 driver to sketch out dev process.
169 lines
12 KiB
HTML
Executable file
169 lines
12 KiB
HTML
Executable file
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
|
|
<meta name="generator" content="ZealOS V0.06">
|
|
<style type="text/css">
|
|
body {background-color:#000000;}
|
|
.cF0{color:#ffffff;background-color:#000000;}
|
|
.cF1{color:#3465a4;background-color:#000000;}
|
|
.cF2{color:#4e9a06;background-color:#000000;}
|
|
.cF3{color:#06989a;background-color:#000000;}
|
|
.cF4{color:#a24444;background-color:#000000;}
|
|
.cF5{color:#75507b;background-color:#000000;}
|
|
.cF6{color:#ce982f;background-color:#000000;}
|
|
.cF7{color:#bcc0b9;background-color:#000000;}
|
|
.cF8{color:#555753;background-color:#000000;}
|
|
.cF9{color:#729fcf;background-color:#000000;}
|
|
.cFA{color:#82bc49;background-color:#000000;}
|
|
.cFB{color:#34e2e2;background-color:#000000;}
|
|
.cFC{color:#ac3535;background-color:#000000;}
|
|
.cFD{color:#ad7fa8;background-color:#000000;}
|
|
.cFE{color:#fce94f;background-color:#000000;}
|
|
.cFF{color:#000000;background-color:#000000;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre style="font-family:monospace;font-size:12pt">
|
|
<a name="l1"></a><span class=cF2>/*</span><span class=cF0> </span><span class=cF2>Intel(R) E1000 Driver</span><span class=cF0>
|
|
<a name="l2"></a> </span><span class=cF2>Author: TomAwezome</span><span class=cF0>
|
|
<a name="l3"></a>
|
|
<a name="l4"></a> </span><span class=cF2>Driver is based on:</span><span class=cF0>
|
|
<a name="l5"></a> </span><span class=cF2>-</span><span class=cF0> </span><span class=cF2>Linux E1000 driver</span><span class=cF0>
|
|
<a name="l6"></a> </span><span class=cF2>-</span><span class=cF0> </span><span class=cF2>01000101's example i825xx driver</span><span class=cF0>
|
|
<a name="l7"></a> </span><span class=cF2>-</span><span class=cF0> </span><span class=cF2>OSDev Intel(R) 8254x documentation</span><span class=cF0>
|
|
<a name="l8"></a> </span><span class=cF2>-</span><span class=cF0> </span><span class=cF2>Intel(R) PCI/PCI-X Family of Gigabit Ethernet Controllers Software Developer's Manual</span><span class=cF0>
|
|
<a name="l9"></a> </span><span class=cF2>-</span><span class=cF0> </span><span class=cF2>any other useful sources.</span><span class=cF0>
|
|
<a name="l10"></a>
|
|
<a name="l11"></a> </span><span class=cF2>Guidelines:</span><span class=cF0>
|
|
<a name="l12"></a> </span><span class=cF2>-</span><span class=cF0> </span><span class=cF2>Magic numbers are bad. #defines are good.</span><span class=cF0>
|
|
<a name="l13"></a> </span><span class=cF2>-</span><span class=cF0> </span><span class=cF2>Understandability over LOC.</span><span class=cF0>
|
|
<a name="l14"></a> </span><span class=cF2>-</span><span class=cF0> </span><span class=cF2>Clear documentation.</span><span class=cF0>
|
|
<a name="l15"></a></span><span class=cF2>*/</span><span class=cF0>
|
|
<a name="l16"></a>
|
|
<a name="l17"></a></span><span class=cF1>class</span><span class=cF0> CE1000
|
|
<a name="l18"></a>{
|
|
<a name="l19"></a> </span><span class=cF9>CPCIDev</span><span class=cF0> *pci;
|
|
<a name="l20"></a>
|
|
<a name="l21"></a> </span><span class=cF1>U8</span><span class=cF0> mac_address[</span><span class=cFE>6</span><span class=cF0>];
|
|
<a name="l22"></a> </span><span class=cF9>U64</span><span class=cF0> mmio_address;
|
|
<a name="l23"></a>
|
|
<a name="l24"></a>} e1000; </span><span class=cF2>// e1000 is the global variable we store all of this into.</span><span class=cF0>
|
|
<a name="l25"></a>
|
|
<a name="l26"></a></span><span class=cF9>CPCIDev</span><span class=cF0> *E1000PCIDevFind()
|
|
<a name="l27"></a>{</span><span class=cF2>// Find and return E1000 card as a CPCIDev pointer.</span><span class=cF0>
|
|
<a name="l28"></a>
|
|
<a name="l29"></a> </span><span class=cF9>CPCIDev</span><span class=cF0> *pci = </span><span class=cF5>PCIDevFind</span><span class=cF0>(</span><span class=cF3>PCIC_NETWORK</span><span class=cF0>,, PCIV_E1000);
|
|
<a name="l30"></a>
|
|
<a name="l31"></a> </span><span class=cF1>if</span><span class=cF0> (!pci)
|
|
<a name="l32"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
|
|
<a name="l33"></a>
|
|
<a name="l34"></a> </span><span class=cF5>ClassRep</span><span class=cF0>(pci);
|
|
<a name="l35"></a>
|
|
<a name="l36"></a> </span><span class=cF1>switch</span><span class=cF0> (pci->device_id)
|
|
<a name="l37"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l38"></a> </span><span class=cF1>case</span><span class=cF0> PCID_82545EM:
|
|
<a name="l39"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l40"></a>
|
|
<a name="l41"></a> </span><span class=cF1>default</span><span class=cF0>:
|
|
<a name="l42"></a> pci = </span><span class=cF3>NULL</span><span class=cF0>;
|
|
<a name="l43"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l44"></a>
|
|
<a name="l45"></a> </span><span class=cF1>return</span><span class=cF0> pci;
|
|
<a name="l46"></a>}
|
|
<a name="l47"></a>
|
|
<a name="l48"></a></span><span class=cF1>U0</span><span class=cF0> EthernetFrameFinish(</span><span class=cF9>I64</span><span class=cF0> de_index)
|
|
<a name="l49"></a>{</span><span class=cF2>//Alias for driver Finish TX function.</span><span class=cF0>
|
|
<a name="l50"></a> </span><span class=cF2>//E1000TransmitPacketFinish(de_index);</span><span class=cF0>
|
|
<a name="l51"></a> </span><span class=cF1>no_warn</span><span class=cF0> de_index;
|
|
<a name="l52"></a> NetErr(</span><span class=cF6>"TODO E1000"</span><span class=cF0>);
|
|
<a name="l53"></a>}
|
|
<a name="l54"></a>
|
|
<a name="l55"></a></span><span class=cF2>/*</span><span class=cF0>
|
|
<a name="l56"></a></span><span class=cF2>U0 PCIInterruptsReroute(I64 base)</span><span class=cF0>
|
|
<a name="l57"></a></span><span class=cF2>{ // todo: comments explaining process, maybe better var names</span><span class=cF0>
|
|
<a name="l58"></a> </span><span class=cF2>I64</span><span class=cF0> </span><span class=cF2> i;</span><span class=cF0>
|
|
<a name="l59"></a> </span><span class=cF2>U8</span><span class=cF0> </span><span class=cF2>*da = dev.uncached_alias + IOAPIC_REG;</span><span class=cF0>
|
|
<a name="l60"></a> </span><span class=cF2>U32 *_d = dev.uncached_alias + IOAPIC_DATA;</span><span class=cF0>
|
|
<a name="l61"></a>
|
|
<a name="l62"></a> </span><span class=cF2>for (i = 0; i < 4; i++)</span><span class=cF0>
|
|
<a name="l63"></a> </span><span class=cF2>{</span><span class=cF0>
|
|
<a name="l64"></a> </span><span class=cF2>*da = IOREDTAB + i * 2 + 1;</span><span class=cF0>
|
|
<a name="l65"></a> </span><span class=cF2>*_d = dev.mp_apic_ids[INT_DEST_CPU] << 24;</span><span class=cF0>
|
|
<a name="l66"></a> </span><span class=cF2>*da = IOREDTAB + i * 2;</span><span class=cF0>
|
|
<a name="l67"></a> </span><span class=cF2>*_d = 0x4000 + base + i;</span><span class=cF0>
|
|
<a name="l68"></a> </span><span class=cF2>}</span><span class=cF0>
|
|
<a name="l69"></a></span><span class=cF2>}</span><span class=cF0>
|
|
<a name="l70"></a>
|
|
<a name="l71"></a>
|
|
<a name="l72"></a></span><span class=cF2>U0 E1000InterruptsSetup()</span><span class=cF0>
|
|
<a name="l73"></a></span><span class=cF2>{</span><span class=cF0>
|
|
<a name="l74"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>PCIInterruptsReroute(I_E1000);</span><span class=cF0>
|
|
<a name="l75"></a> </span><span class=cF2>NetErr("TODO E1000");</span><span class=cF0>
|
|
<a name="l76"></a></span><span class=cF2>}</span><span class=cF0>
|
|
<a name="l77"></a></span><span class=cF2>*/</span><span class=cF0>
|
|
<a name="l78"></a>
|
|
<a name="l79"></a></span><span class=cF1>U0</span><span class=cF0> E1000Init()
|
|
<a name="l80"></a>{
|
|
<a name="l81"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&e1000, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CE1000</span><span class=cF7>)</span><span class=cF0>); </span><span class=cF2>// e1000 global var will hold member data the driver uses often.</span><span class=cF0>
|
|
<a name="l82"></a> </span><span class=cF6>"\nE1000 driver WIP\n\n"</span><span class=cF0>;
|
|
<a name="l83"></a>
|
|
<a name="l84"></a> e1000.pci = E1000PCIDevFind;
|
|
<a name="l85"></a> </span><span class=cF1>if</span><span class=cF0> (!e1000.pci)
|
|
<a name="l86"></a> </span><span class=cF1>return</span><span class=cF0>; </span><span class=cF2>// if we don't find the card, quit.</span><span class=cF0>
|
|
<a name="l87"></a>
|
|
<a name="l88"></a>
|
|
<a name="l89"></a> e1000.mmio_address = </span><span class=cFB>dev</span><span class=cF0>.uncached_alias + e1000.pci->base[</span><span class=cFE>0</span><span class=cF0>] & ~</span><span class=cFE>0xF</span><span class=cF0>;
|
|
<a name="l90"></a> </span><span class=cF2>// Assuming card supports MMIO... lower 4 bits are hardwired zero (?)</span><span class=cF0>
|
|
<a name="l91"></a>
|
|
<a name="l92"></a> </span><span class=cF6>"\nMMIO address: 0x%0X\n"</span><span class=cF0>, e1000.mmio_address;
|
|
<a name="l93"></a>
|
|
<a name="l94"></a> </span><span class=cF2>// init rx/tx addrs?</span><span class=cF0>
|
|
<a name="l95"></a>
|
|
<a name="l96"></a> </span><span class=cF2>// eeprom? MAC ?</span><span class=cF0>
|
|
<a name="l97"></a>
|
|
<a name="l98"></a> </span><span class=cF2>// setup link? (01000101's driver)</span><span class=cF0>
|
|
<a name="l99"></a>
|
|
<a name="l100"></a> </span><span class=cF2>// zero out multicast hash? (linux)</span><span class=cF0>
|
|
<a name="l101"></a> </span><span class=cF2>// zero out multicast table array (01000101's driver)</span><span class=cF0>
|
|
<a name="l102"></a>
|
|
<a name="l103"></a> </span><span class=cF2>// setup link? (linux)</span><span class=cF0>
|
|
<a name="l104"></a>
|
|
<a name="l105"></a> </span><span class=cF2>// clear all statistics regs after link establish attempt (linux)</span><span class=cF0>
|
|
<a name="l106"></a>
|
|
<a name="l107"></a> </span><span class=cF2>// enable interupts (01000101's driver)</span><span class=cF0>
|
|
<a name="l108"></a>
|
|
<a name="l109"></a> </span><span class=cF2>// start rx tx?</span><span class=cF0>
|
|
<a name="l110"></a>
|
|
<a name="l111"></a> NetErr(</span><span class=cF6>"TODO E1000"</span><span class=cF0>);
|
|
<a name="l112"></a>}
|
|
<a name="l113"></a>
|
|
<a name="l114"></a></span><span class=cF9>I64</span><span class=cF0> EthernetFrameAllocate(</span><span class=cF1>U8</span><span class=cF0> **packet_buffer_out,
|
|
<a name="l115"></a> </span><span class=cF1>U8</span><span class=cF0> *source_address,
|
|
<a name="l116"></a> </span><span class=cF1>U8</span><span class=cF0> *destination_address,
|
|
<a name="l117"></a> </span><span class=cF9>U16</span><span class=cF0> ethertype,
|
|
<a name="l118"></a> </span><span class=cF9>I64</span><span class=cF0> packet_length)
|
|
<a name="l119"></a>{
|
|
<a name="l120"></a> </span><span class=cF1>no_warn</span><span class=cF0> packet_buffer_out, source_address, destination_address, ethertype, packet_length;
|
|
<a name="l121"></a> NetErr(</span><span class=cF6>"TODO E1000"</span><span class=cF0>);
|
|
<a name="l122"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
|
|
<a name="l123"></a>}
|
|
<a name="l124"></a>
|
|
<a name="l125"></a></span><span class=cF1>U8</span><span class=cF0> *EthernetMACGet()
|
|
<a name="l126"></a>{
|
|
<a name="l127"></a> NetErr(</span><span class=cF6>"TODO E1000"</span><span class=cF0>);
|
|
<a name="l128"></a> </span><span class=cF1>return</span><span class=cF0> e1000.mac_address;
|
|
<a name="l129"></a>}
|
|
<a name="l130"></a>
|
|
<a name="l131"></a></span><span class=cF1>U0</span><span class=cF0> NetStop()
|
|
<a name="l132"></a>{
|
|
<a name="l133"></a>
|
|
<a name="l134"></a>}
|
|
<a name="l135"></a>
|
|
<a name="l136"></a></span><span class=cF1>U0</span><span class=cF0> NetStart()
|
|
<a name="l137"></a>{
|
|
<a name="l138"></a>
|
|
<a name="l139"></a>}
|
|
<a name="l140"></a>
|
|
<a name="l141"></a>E1000Init;</span></pre></body>
|
|
</html>
|