Skip to content

Commit cd8b408

Browse files
committed
Format code using clang-format.
Signed-off-by: KieranMusser <59939188+KieranMusser@users.noreply.github.com>
1 parent a948a91 commit cd8b408

File tree

6 files changed

+71
-76
lines changed

6 files changed

+71
-76
lines changed

src/kernel/devices/pci.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
struct list_head pcis = LIST_INIT(pcis);
1010

1111
struct registered_device {
12-
void (*callback)(struct pci* this, struct pci_regs *regs);
12+
void (*callback)(struct pci *this, struct pci_regs *regs);
1313
u16 vid;
1414
u16 did;
1515
};
1616

1717
struct registered_device *handlers = nullptr;
1818
usize handlers_len = 0, handlers_cap = 0;
1919

20-
void pci_register(u16 vid, u16 did, void (*callback)(struct pci *this, struct pci_regs *regs)) {
20+
void pci_register(u16 vid, u16 did,
21+
void (*callback)(struct pci *this, struct pci_regs *regs)) {
2122
if (!handlers) {
2223
assert(!handlers_len);
2324
handlers_cap = 16;
@@ -33,15 +34,13 @@ void pci_register(u16 vid, u16 did, void (*callback)(struct pci *this, struct pc
3334
handlers = new_handlers;
3435
}
3536

36-
handlers[handlers_len++] = (struct registered_device) {
37-
.vid = vid,
38-
.did = did,
39-
.callback = callback
40-
};
37+
handlers[handlers_len++] =
38+
(struct registered_device){.vid = vid, .did = did, .callback = callback};
4139
}
4240

43-
void (*pci_get_handler(u16 vid, u16 did))(struct pci *this, struct pci_regs *regs) {
44-
for (usize i = 0; i<handlers_len; ++i) {
41+
void (*pci_get_handler(u16 vid, u16 did))(struct pci *this,
42+
struct pci_regs *regs) {
43+
for (usize i = 0; i < handlers_len; ++i) {
4544
if (handlers[i].vid == vid && handlers[i].did == did)
4645
return handlers[i].callback;
4746
}

src/kernel/drivers/pci_device.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
* SPDX-License-Identifier: GPL-3.0-or-later
55
*/
66

7-
#include <print.h>
7+
#include <container.h>
8+
#include <devicetree.h>
9+
#include <endian.h>
810
#include <mm/paging.h>
911
#include <mm/virtual_alloc.h>
1012
#include <physical.h>
11-
#include <devicetree.h>
13+
#include <print.h>
1214
#include <volatile.h>
13-
#include <container.h>
14-
#include <endian.h>
1515

1616
#include <devices/pci.h>
1717

@@ -35,15 +35,14 @@ union pci_device_addr {
3535
u32 bits;
3636
};
3737

38-
void register_device(struct pci *this, u16 vid, u16 did, void (*callback)(struct pci* this, void *regs));
39-
struct vma* mmio_alloc(struct pci *this, usize len, bool want_low_addr);
38+
void register_device(struct pci *this, u16 vid, u16 did,
39+
void (*callback)(struct pci *this, void *regs));
40+
struct vma *mmio_alloc(struct pci *this, usize len, bool want_low_addr);
4041

41-
static struct pci_ops pci_device_ops = {
42-
.mmio_alloc = mmio_alloc
43-
};
44-
static_assert( offsetof(struct pci_regs, memar) == 0x14);
42+
static struct pci_ops pci_device_ops = {.mmio_alloc = mmio_alloc};
43+
static_assert(offsetof(struct pci_regs, memar) == 0x14);
4544

46-
struct vma* mmio_alloc(struct pci *this, usize num_pages, bool want_low_addr) {
45+
struct vma *mmio_alloc(struct pci *this, usize num_pages, bool want_low_addr) {
4746
struct pci_device *dev = container_of(this, struct pci_device, pci);
4847
struct vma_allocator *allocator;
4948

@@ -58,8 +57,8 @@ struct vma* mmio_alloc(struct pci *this, usize num_pages, bool want_low_addr) {
5857

5958
void pci_enumerate(struct pci *this, void *reg_base) {
6059

61-
for (u32 bus=0; bus<256; ++bus) {
62-
for (u32 dev=0; dev<32; ++dev) {
60+
for (u32 bus = 0; bus < 256; ++bus) {
61+
for (u32 dev = 0; dev < 32; ++dev) {
6362
union pci_device_addr addr;
6463
addr.offset = 0;
6564
addr.func = 0;
@@ -74,9 +73,10 @@ void pci_enumerate(struct pci *this, void *reg_base) {
7473
if (did == 0xffff && vid == 0xffff)
7574
continue;
7675

77-
void (*callback)(struct pci*, struct pci_regs *) = pci_get_handler(vid, did);
76+
void (*callback)(struct pci *, struct pci_regs *) =
77+
pci_get_handler(vid, did);
7878

79-
if (callback) {
79+
if (callback) {
8080
callback(this, device);
8181
} else {
8282
print("Unbekannt pci Gerät: {u16:x} Anbieter: {u16:x}", did, vid);
@@ -112,7 +112,6 @@ static struct device *pci_enumerate_dt(struct devicetree_node *node) {
112112
&parent_size_cells))
113113
goto fail;
114114

115-
116115
devicetree_print(node->parent);
117116

118117
usize triplet_size = (address_cells + parent_address_cells + size_cells) * 4;
@@ -132,8 +131,10 @@ static struct device *pci_enumerate_dt(struct devicetree_node *node) {
132131
u64 addr, size;
133132

134133
memcpy(&bus_addr.bits, &base->value[i], 4);
135-
memcpy(&addr, &base->value[i+address_cells*4], parent_address_cells * 4);
136-
memcpy(&size, &base->value[i+(address_cells + parent_address_cells)*4], size_cells * 4);
134+
memcpy(&addr, &base->value[i + address_cells * 4],
135+
parent_address_cells * 4);
136+
memcpy(&size, &base->value[i + (address_cells + parent_address_cells) * 4],
137+
size_cells * 4);
137138

138139
addr = big_to_native(addr);
139140
size = big_to_native(size);
@@ -166,8 +167,8 @@ static struct device *pci_enumerate_dt(struct devicetree_node *node) {
166167
},
167168
.reg_base = iomem_map(reg_addr, reg_size),
168169
.mmio_low_allocator = vma_allocator_new(mmio_32bit_low, mmio_32bit_high),
169-
.mmio_high_allocator = vma_allocator_new(mmio_64bit_low, mmio_64bit_high)
170-
};
170+
.mmio_high_allocator =
171+
vma_allocator_new(mmio_64bit_low, mmio_64bit_high)};
171172

172173
if (!device->device.name || !device->reg_base)
173174
goto fail;

src/kernel/drivers/rtl8139.c

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <print.h>
1010

1111
#include <device.h>
12-
#include <devices/pci.h>
1312
#include <devices/netdev.h>
13+
#include <devices/pci.h>
1414
#include <net/eth.h>
1515

1616
struct rtl8139_regs {
@@ -34,20 +34,14 @@ struct rtl8139 {
3434
bool send_packet(struct netdev *this, u8 packet[], usize length);
3535
struct mac get_mac(struct netdev *this);
3636

37-
struct netdev_ops rtl8139_ops = {
38-
.send_packet = send_packet,
39-
.get_mac = get_mac
40-
};
37+
struct netdev_ops rtl8139_ops = {.send_packet = send_packet,
38+
.get_mac = get_mac};
4139

4240
constexpr usize TX_BUFF_SIZE = 0x1700;
4341
constexpr u16 rtl8139_vid = 0x10ec;
4442
constexpr u16 rtl8139_did = 0x8139;
4543

46-
enum rtl8139_registers {
47-
REG_COM = 0x37,
48-
REG_TCR = 0x40,
49-
REG_CONFIG1 = 0x52
50-
};
44+
enum rtl8139_registers { REG_COM = 0x37, REG_TCR = 0x40, REG_CONFIG1 = 0x52 };
5145

5246
enum rtl8139_flags {
5347
TSD_TOK = (1 << 15),
@@ -60,10 +54,10 @@ enum rtl8139_flags {
6054

6155
u8 rtl8139_tbuff[4][TX_BUFF_SIZE] __attribute__((aligned(256)));
6256

63-
static_assert( offsetof(struct rtl8139_regs, tsad) == 0x20);
64-
static_assert( offsetof(struct rtl8139_regs, tsd) == 0x10);
65-
static_assert( offsetof(struct rtl8139_regs, com) == 0x37);
66-
static_assert( offsetof(struct rtl8139_regs, config1) == 0x52);
57+
static_assert(offsetof(struct rtl8139_regs, tsad) == 0x20);
58+
static_assert(offsetof(struct rtl8139_regs, tsd) == 0x10);
59+
static_assert(offsetof(struct rtl8139_regs, com) == 0x37);
60+
static_assert(offsetof(struct rtl8139_regs, config1) == 0x52);
6761

6862
bool mm_paging_walk(uaddr va, paddr *pte, bool alloc);
6963

@@ -81,15 +75,15 @@ u32 walkaddr(uaddr addr) {
8175

8276
pte = (pte >> 10) << 12;
8377
assert(pte < U32_MAX);
84-
return (u32) pte | off;
78+
return (u32)pte | off;
8579
}
8680

8781
struct mac get_mac(struct netdev *this) {
8882
struct rtl8139 *rtl_this = (struct rtl8139 *)(this->device);
8983
volatile struct rtl8139_regs *rtl_regs = rtl_this->regs;
9084
struct mac mac;
9185

92-
for (usize i = 0; i<6; ++i) {
86+
for (usize i = 0; i < 6; ++i) {
9387
mac.addr[i] = rtl_regs->mac[i];
9488
}
9589
return mac;
@@ -98,10 +92,10 @@ struct mac get_mac(struct netdev *this) {
9892
bool send_packet(struct netdev *this, u8 packet[], usize length) {
9993
struct rtl8139 *rtl_this = container_of(this, struct rtl8139, netdev);
10094
volatile struct rtl8139_regs *rtl_regs = rtl_this->regs;
101-
u32 phys_buffer = walkaddr((uaddr) (&rtl8139_tbuff[0]));
95+
u32 phys_buffer = walkaddr((uaddr)(&rtl8139_tbuff[0]));
10296
u64 i;
10397

104-
for (i=0; i<length; ++i) {
98+
for (i = 0; i < length; ++i) {
10599
rtl8139_tbuff[rtl_this->current_buffer][i] = packet[i];
106100
}
107101

@@ -110,26 +104,23 @@ bool send_packet(struct netdev *this, u8 packet[], usize length) {
110104
}
111105

112106
rtl_regs->tsad[rtl_this->current_buffer] = phys_buffer;
113-
rtl_regs->tsd[rtl_this->current_buffer] = (u32) length;
107+
rtl_regs->tsd[rtl_this->current_buffer] = (u32)length;
114108

115109
++rtl_this->current_buffer;
116110
return true;
117111
}
118112

119-
120113
void rtl8139_test(struct rtl8139 *rtl_device) {
121114
volatile struct rtl8139_regs *rtl_regs = rtl_device->regs;
122115
struct mac mac;
123-
memcpy(mac.addr, (const u8*) "\xff\xff\xff\xff\xff\xff", 6);
116+
memcpy(mac.addr, (const u8 *)"\xff\xff\xff\xff\xff\xff", 6);
124117

125-
eth_send_packet(&rtl_device->netdev, mac,
126-
(u8*) "yellow submarine", 16);
118+
eth_send_packet(&rtl_device->netdev, mac, (u8 *)"yellow submarine", 16);
127119

128120
assert(rtl_regs->tsad[0] != 0);
129121
assert((rtl_regs->tsd[0] & TSD_TOK) != 0);
130122
}
131123

132-
133124
static struct device *add_device(paddr reg_addr, usize reg_size) {
134125
struct rtl8139 *device = nullptr;
135126

@@ -164,10 +155,9 @@ static struct device *add_device(paddr reg_addr, usize reg_size) {
164155
}
165156
free(device);
166157
return nullptr;
167-
168158
}
169159

170-
void rtl8139_init(struct pci* pci, struct pci_regs *pci_device) {
160+
void rtl8139_init(struct pci *pci, struct pci_regs *pci_device) {
171161
print("initializing rtl8139");
172162

173163
volatile struct rtl8139_regs *rtl_regs;
@@ -179,10 +169,11 @@ void rtl8139_init(struct pci* pci, struct pci_regs *pci_device) {
179169

180170
/* Should always be true, see mmio_alloc */
181171
assert(low < U32_MAX);
182-
reg_addr = (u32) low;
172+
reg_addr = (u32)low;
183173

184-
struct device *device = add_device(paddr_of_bits(reg_addr), sizeof(struct rtl8139_regs));
185-
struct rtl8139 *rtl_device = (struct rtl8139 *) device;
174+
struct device *device =
175+
add_device(paddr_of_bits(reg_addr), sizeof(struct rtl8139_regs));
176+
struct rtl8139 *rtl_device = (struct rtl8139 *)device;
186177
rtl_regs = rtl_device->regs;
187178

188179
/* TODO: Maybe move PCI init to pci.c? */
@@ -193,7 +184,8 @@ void rtl8139_init(struct pci* pci, struct pci_regs *pci_device) {
193184
rtl_regs->config1 = 0;
194185

195186
rtl_regs->com = COM_RST;
196-
while (rtl_regs->com & COM_RST) ;
187+
while (rtl_regs->com & COM_RST)
188+
;
197189
rtl_regs->com = COM_RE | COM_TE;
198190

199191
rtl_regs->tsad[0] = 0x12;

src/kernel/include/devices/pci.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
#ifndef UKO_OS_KERNEL__PCI_H
88
#define UKO_OS_KERNEL__PCI_H 1
99

10-
#include <types.h>
1110
#include <device.h>
12-
11+
#include <types.h>
1312

1413
struct pci_regs {
1514
u16 vid;
@@ -26,13 +25,15 @@ struct pci {
2625
};
2726

2827
struct pci_ops {
29-
struct vma* (*mmio_alloc)(struct pci *this, usize len, bool want_low_addr);
28+
struct vma *(*mmio_alloc)(struct pci *this, usize len, bool want_low_addr);
3029
};
3130

3231
extern struct list_head pcis;
3332

34-
void (*pci_get_handler(u16 vid, u16 did))(struct pci *this, struct pci_regs *regs);
35-
void pci_register(u16 vid, u16 did, void (*callback)(struct pci *this, struct pci_regs *regs));
33+
void (*pci_get_handler(u16 vid, u16 did))(struct pci *this,
34+
struct pci_regs *regs);
35+
void pci_register(u16 vid, u16 did,
36+
void (*callback)(struct pci *this, struct pci_regs *regs));
3637

3738
enum pci_bus_addr_space_code {
3839
SPACE_CODE_CONFIG = 0,
@@ -45,7 +46,7 @@ union pci_bus_addr {
4546
struct {
4647
u32 pad : 24;
4748
enum pci_bus_addr_space_code space_code : 2;
48-
u32 pad2: 6;
49+
u32 pad2 : 6;
4950
};
5051
u32 bits;
5152
};

src/kernel/include/net/eth.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
#define UKO_OS_KERNEL__NET_ETH__H 1
1111

1212
struct mac {
13-
u8 addr[6];
13+
u8 addr[6];
1414
};
1515

16-
bool eth_send_packet(struct netdev *device, const struct mac dst, u8 *buffer, usize len);
16+
bool eth_send_packet(struct netdev *device, const struct mac dst, u8 *buffer,
17+
usize len);
1718

1819
#endif

src/kernel/net/eth.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
*
44
* SPDX-License-Identifier: GPL-3.0-or-later
55
*/
6-
#include <types.h>
76
#include <device.h>
87
#include <devices/netdev.h>
98
#include <mm/virtual_alloc.h>
109
#include <net/eth.h>
10+
#include <types.h>
1111

1212
struct ethernet_packet {
13-
u8 dst[6];
14-
u8 src[6];
15-
u8 ethertype[2];
16-
u8 data[];
13+
u8 dst[6];
14+
u8 src[6];
15+
u8 ethertype[2];
16+
u8 data[];
1717
};
1818

19-
bool eth_send_packet(struct netdev *device, const struct mac dst, u8 *buffer, usize len) {
19+
bool eth_send_packet(struct netdev *device, const struct mac dst, u8 *buffer,
20+
usize len) {
2021
struct ethernet_packet *packet;
2122
struct mac src;
2223
usize packet_len;
@@ -34,12 +35,12 @@ bool eth_send_packet(struct netdev *device, const struct mac dst, u8 *buffer, us
3435

3536
packet->ethertype[0] = 0x86;
3637
packet->ethertype[1] = 0xDD;
37-
38+
3839
memcpy(packet->data, buffer, len);
3940

40-
for (usize i=len; i<46; ++i) {
41+
for (usize i = len; i < 46; ++i) {
4142
packet->data[i] = 0;
4243
}
4344

44-
return device->ops->send_packet(device, (u8*) packet, packet_len);
45+
return device->ops->send_packet(device, (u8 *)packet, packet_len);
4546
}

0 commit comments

Comments
 (0)