Diff for /wikisrc/tutorials/bus_space_tutorial.mdwn between versions 1.5 and 1.6

version 1.5, 2013/06/23 14:41:01 version 1.6, 2013/06/23 15:02:25
Line 82  this knowledge yourself. Line 82  this knowledge yourself.
     - port-specific or architecture-specific parts (such as the      - port-specific or architecture-specific parts (such as the
     low-level system initialisation procedures or machine-dependent      low-level system initialisation procedures or machine-dependent
     drivers)      drivers)
 -   src/sys/arch/\$PORTNAME/conf/  -   src/sys/arch/$PORTNAME/conf/
     - kernel configuration files for a given port      - kernel configuration files for a given port
   
 ### Kernel autoconfiguration framework - autoconf(9)  ### Kernel autoconfiguration framework - autoconf(9)
Line 147  this knowledge yourself. Line 147  this knowledge yourself.
     bus like mapping, reading, writing, copying, etc.      bus like mapping, reading, writing, copying, etc.
 -   The bus\_space(9) is implemented at the machine-dependent level  -   The bus\_space(9) is implemented at the machine-dependent level
     (typically it’s a part of architecture-specific code), but all      (typically it’s a part of architecture-specific code), but all
     implementations present the same interface[^1]      implementations present the same interface
   > At least they should, some functions are missing on less popular ports
   
 ### Machine independent drivers  ### Machine independent drivers
   
Line 174  this knowledge yourself. Line 175  this knowledge yourself.
 -   Described in [Part V of the NetBSD  -   Described in [Part V of the NetBSD
     Guide](http://www.netbsd.org/docs/guide/en/part-compile.html)      Guide](http://www.netbsd.org/docs/guide/en/part-compile.html)
 -   Check out the NetBSD sources  -   Check out the NetBSD sources
 -   \$ build.sh -m cobalt tools  -   $ build.sh -m cobalt tools
     will build compiler, assembler, linker, etc. for cobalt port      will build compiler, assembler, linker, etc. for cobalt port
 -   \$ build.sh -m cobalt kernel=GENERIC  -   $ build.sh -m cobalt kernel=GENERIC
     will build the GENERIC kernel for cobalt      will build the GENERIC kernel for cobalt
 -   Call build.sh with a -u parameter to update (won’t rebuilding  -   Call build.sh with a -u parameter to update (won’t rebuilding
     everything)      everything)
Line 208  this knowledge yourself. Line 209  this knowledge yourself.
 -   Overview  -   Overview
     -   Implemented as a PCI device      -   Implemented as a PCI device
     -   Arithmetic unit capable of addition of two numbers      -   Arithmetic unit capable of addition of two numbers
     -   Four[^2] registers in the PCI memory space      -   Four registers in the PCI memory space
   > Only three of these registers are of any importance for us at this moment
 -   PCI configuration space  -   PCI configuration space
     -   Identified by the PCI vendor ID 0xfabc and product ID 0x0001      -   Identified by the PCI vendor ID 0xfabc and product ID 0x0001
     -   Base Address Register 0x10 used to configure the engine address      -   Base Address Register 0x10 used to configure the engine address
Line 271  this knowledge yourself. Line 273  this knowledge yourself.
     the NetBSD kernel      the NetBSD kernel
     -   Add the vendor and device ID to the database of PCI IDs      -   Add the vendor and device ID to the database of PCI IDs
     -   Create a set of the driver source files in      -   Create a set of the driver source files in
         src/sys/dev/\$BUSNAME/          src/sys/dev/$BUSNAME/
     -   Add the new driver to src/sys/dev/\$BUSNAME/\$BUSNAME.files file      -   Add the new driver to src/sys/dev/$BUSNAME/$BUSNAME.files file
     -   Add the new driver to DEVNAMES[^3] file      -   Add the new driver to DEVNAMES file
   > Required if you are NetBSD developer, optional otherwise.
   
 ### Modifying the PCI device database  ### Modifying the PCI device database
   
Line 328  this knowledge yourself. Line 331  this knowledge yourself.
     -   faa.c      -   faa.c
         - main driver code          - main driver code
     -   faareg.h      -   faareg.h
         - register definitions[^4]          - register definitions
   > Might not exist if the driver is only a simple passthrough from a specific bus to another MI driver.
     -   faavar.h      -   faavar.h
         - driver structures and functions used in other parts of the          - driver structures and functions used in other parts of the
         kernel[^5]          kernel
   > Omitted if not needed.
 -   Modify driver definitions  -   Modify driver definitions
     -   src/sys/dev/pci/files.pci      -   src/sys/dev/pci/files.pci
     -   src/sys/dev/DEVNAMES      -   src/sys/dev/DEVNAMES
 -   Configure the kernel to use the newly added driver -  -   Configure the kernel to use the newly added driver -
     src/sys/arch/\$PORTNAME/conf/GENERIC      src/sys/arch/$PORTNAME/conf/GENERIC
   
 ### Adding the new PCI driver - main driver  ### Adding the new PCI driver - main driver
   
Line 400  this knowledge yourself. Line 405  this knowledge yourself.
 <!-- -->  <!-- -->
   
     #include <sys/cdefs.h>      #include <sys/cdefs.h>
     __KERNEL_RCSID(0, "$NetBSD: bus_space_tutorial.mdwn,v 1.4 2013/06/23 14:34:32 mspo Exp $");      __KERNEL_RCSID(0, "$NetBSD: bus_space_tutorial.mdwn,v 1.5 2013/06/23 14:41:01 mspo Exp $");
     #include <sys/param.h>      #include <sys/param.h>
     #include <sys/device.h>      #include <sys/device.h>
     #include <dev/pci/pcivar.h>      #include <dev/pci/pcivar.h>
Line 571  this knowledge yourself. Line 576  this knowledge yourself.
     – an amount of space on the bus      – an amount of space on the bus
   
 -   Contents of these types are MD, so avoid modifying from within the  -   Contents of these types are MD, so avoid modifying from within the
     driver[^6]      driver
   > although you’ll often have to use bus\_size\_t
   
 ### Why do we need to “map” the resources?  ### Why do we need to “map” the resources?
   
Line 738  this knowledge yourself. Line 744  this knowledge yourself.
   
 ### Variants of bus\_space\_read and bus\_space\_write  ### Variants of bus\_space\_read and bus\_space\_write
   
     Data       Read function         Write function  <table>
   -------- --------------------- ----------------------  <tr><th>Data</th><th>Read function</th><th>Write function</th></tr>
    8-bit    bus\_space\_read\_1   bus\_space\_write\_1  <tr><td>8-bit</td><td>bus\_space\_read\_1</td><td>bus\_space\_write\_1</td></tr>
    16-bit   bus\_space\_read\_2   bus\_space\_write\_2  <tr><td>16-bit</td><td>bus\_space\_read\_2</td><td>bus\_space\_write\_2</td></tr>
    32-bit   bus\_space\_read\_4   bus\_space\_write\_4  <tr><td>32-bit</td><td>bus\_space\_read\_4</td><td>bus\_space\_write\_4</td></tr>
    64-bit   bus\_space\_read\_8   bus\_space\_write\_8  <tr><td>64-bit</td><td>bus\_space\_read\_8</td><td>bus\_space\_write\_8</td></tr>
   </table>
   
 -   There are many more variants of read and write functions and they  -   There are many more variants of read and write functions and they
     are useful in certain situations, see the      are useful in certain situations, see the
Line 1112  this knowledge yourself. Line 1119  this knowledge yourself.
 ### Defining device major number  ### Defining device major number
   
 -   Device major numbers for hardware drivers are usually defined in a  -   Device major numbers for hardware drivers are usually defined in a
     per-port manner[^7]      per-port manner
 -   src/sys/arch/\$PORTNAME/conf/majors.\$PORTNAME  > It’s also possible to define a major in a machine-independent way in src/sys/conf/majors
   -   src/sys/arch/$PORTNAME/conf/majors.$PORTNAME
 -   src/sys/arch/cobalt/conf/majors.cobalt  -   src/sys/arch/cobalt/conf/majors.cobalt
 -   The following defines a new character device file called /dev/faa\*  -   The following defines a new character device file called /dev/faa\*
     with major number 101, but only if the faa driver is included in the      with major number 101, but only if the faa driver is included in the
Line 1259  this knowledge yourself. Line 1267  this knowledge yourself.
 -   <https://github.com/rkujawa/busspace-tutorial>  -   <https://github.com/rkujawa/busspace-tutorial>
 -   <https://github.com/rkujawa/gxemul-tutorial>  -   <https://github.com/rkujawa/gxemul-tutorial>
   
 ### The End…  
   
 [^1]: At least they should, some functions are missing on less popular ports  
   
 [^2]: Only three of these registers are of any importance for us at this moment  
   
 [^3]: Required if you are NetBSD developer, optional otherwise.  
   
 [^4]: Might not exist if the driver is only a simple passthrough from a specific bus to another MI driver.  
   
 [^5]: Omitted if not needed.  
   
 [^6]: although you’ll often have to use bus\_size\_t  
   
 [^7]: It’s also possible to define a major in a machine-independent way in src/sys/conf/majors  

Removed from v.1.5  
changed lines
  Added in v.1.6


CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb